Skip to content
Snippets Groups Projects
Select Git revision
  • d3fee7ecf41f26a06002aa141b0d3b91d252bb52
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

swap_util.hh

Blame
  • postprocessing.py 2.54 KiB
    # -*- coding: utf-8 -*-
    """
    Created on Tue Dec 20 14:06:20 2022
    
    @author: baerma
    """
    
    import pandas as pd
    import math
    pd.options.mode.chained_assignment = None
    
    class PostProcessRIBlast():
        
        def __init__(self):
            output = self.generate_gtf()
            #print(output)
         
        
        def calculate_energy(self, value):
            energy_constant = 1.380649*10**(-23)*298
            kcalmol_joul = 6.9477*10**-21
            return (math.exp(-float(value)*kcalmol_joul/energy_constant))
        
        
        def create_list_from_output(self):
            self.file = "RIBlast output example.txt"
            self.firstline = 3
            self.interaction_list = []
            with open(self.file, 'r') as file:
                self.raw_interactions = file.readlines()[self.firstline:]   
            self.number_entries = len(self.raw_interactions)
            
            for i in range(0, self.number_entries-1):
                current_interaction = self.raw_interactions[i].strip(' \n').replace('(', '').replace(')','').replace('-',',').replace(':',',').split(',')
                self.interaction_list.append(current_interaction) 
    
            return self.interaction_list
                
    
        def create_pandas_df(self):
            self.interaction_list = self.create_list_from_output()
            self.df = pd.DataFrame(self.interaction_list)
            self.df['Number_of_interactions'] = int(0)
            self.df['Interaction_Energy'] = float(0)
            self.transcript = 3
            self.energy = 5
            
            for index in self.df.index:
                self.df['Number_of_interactions'][index]=self.df[self.transcript].value_counts()[self.df[self.transcript][index]]
                self.df['Interaction_Energy'][index]=self.calculate_energy(self.df[self.energy][index])
    
            self.df['Normalised_interaction_energy']=self.df['Interaction_Energy']/self.df['Number_of_interactions']
            
            return self.df
    
        
        def generate_gtf(self):
            self.interaction_df = self.create_pandas_df()
            self.output = str()
    
            for index in self.interaction_df.index:
                self.output = self.output + str(self.interaction_df[3][index]+'\t' + 'RIBlast' + '\t' + 'Priming_site' + '\t' + self.interaction_df[13][index] + '\t' + self.interaction_df[12][index] + '\t' + '.' + '\t' + '+' + '\t' + '.' + '\t' + f'Interaction_Energy "{self.interaction_df["Normalised_interaction_energy"][index]}"' + '\n')
            
            with open('output_transcripts_df.GTF', 'w') as f:
                f.write(self.output)
                return(self.output)
            
    
    print(PostProcessRIBlast().output)