botechga

DNA Oligo Analyzer Calc

Jul 17th, 2020
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.34 KB | None | 0 0
  1. import pandas as pd
  2. import math
  3. import os
  4. import numpy.random as rd
  5.  
  6. class DNA():
  7.     '''This is a class for DNA sequences and their properties. All that you needed is pandas and an excel or csv sheet
  8.    formatted such that the first column is the sequence name and the second column is the sequence.
  9.  
  10.    Ex:
  11.    Sequence 1, ATGCGCGATCGATCGATGGACTTAGCAAATCGCT
  12.    Sequence 2, ACTACTACTCGCATGCATACGGACGACTGACTG
  13.    ...
  14.  
  15.    Calculations are taken from http://biotools.nubic.northwestern.edu/OligoCalc.html#helpbasic'''
  16.  
  17.     def __init__(self,name,sequence):
  18.         #   Basic sequence information
  19.         self.name = name
  20.         self.sequence = sequence
  21.         self.baselength = len(sequence)
  22.  
  23.         #   Count the number of the respective nucleotides
  24.         self.num_As = sequence.count('A')
  25.         self.num_Ts = sequence.count('T')
  26.         self.num_Gs = sequence.count('G')
  27.         self.num_Cs = sequence.count('C')
  28.  
  29.         #   Basic Salt information units = M
  30.         self.sodium = 0.050
  31.         self.magnesium = 0
  32.  
  33.     def GC_content(self):
  34.         '''Simple percentage of G and C out of total sequence'''
  35.         gc = ((self.num_Cs + self.num_Gs) / self.baselength)*100
  36.         return int(gc)
  37.  
  38.  
  39.     def AnHydro_MolWeight(self):
  40.         '''Calculation: (Anhydrous Molecular Weight = (An x 313.21) + (Tn x 304.2) + (Cn x 289.18) + (Gn x 329.21) - 61.96)
  41.        Taken from http://biotools.nubic.northwestern.edu/OligoCalc.html#helpbasic'''
  42.         mol = (self.num_As * 313.21) + (self.num_Ts * 304.2) + (self.num_Cs * 289.18) + (self.num_Gs * 329.21) - 61.96
  43.         return int(mol)
  44.  
  45.     def Melting_Temp(self):
  46.         '''Calculation: (Tm= 100.5 + (41 * (yG+zC)/(wA+xT+yG+zC)) - (820/(wA+xT+yG+zC)) + 16.6*log10([Na+]))
  47.        Taken from http://biotools.nubic.northwestern.edu/OligoCalc.html#helpbasic'''
  48.         tm = Tm= 100.5 + (41 * (self.num_Gs+self.num_Cs)/(self.num_As+self.num_Ts+self.num_Gs+self.num_Cs)) - (820/(self.num_As+self.num_Ts+self.num_Gs+self.num_Cs)) + 16.6*math.log10(self.sodium)
  49.         return int(tm)
  50.  
  51.     def Estimate_Ext_Coeff(self):
  52.         '''Calculation: (E260 = ( (nA × 15.4) + (nC × 7.4) + (nG × 11.5) + (nT × 8.7) ) × 0.9 × 1000)
  53.        Taken from https://www.atdbio.com/content/1/Ultraviolet-absorbance-of-oligonucleotides#Calculation-of-extinction-coefficient'''
  54.         e = ((self.num_As * 15.4) + (self.num_Cs * 7.4) + (self.num_Gs * 11.5) + (self.num_Ts * 8.7)) * 0.9 * 1000
  55.         return int(e)
  56.  
  57. class Optical():
  58.     '''Next is a class made for calculating concentration from absorbance'''
  59.  
  60.     def __init__(self,absorbance, extinction):
  61.         self.Abs = absorbance
  62.         self.path = 1   #   path is either 1 or 0.3 cm from mm
  63.         self.ext_coeff = extinction
  64.         self.dilution =  100
  65.  
  66.     def Concentration(self):
  67.         conc = ((((self.Abs)/(self.path*self.ext_coeff))*self.dilution)/1E-6)
  68.         return conc
  69.  
  70. #   read the data into a DataFrame
  71. file =  'dna_seq.csv' #input('Please enter sequence file name:')
  72. df = pd.read_csv(str(file))
  73.  
  74. Info_Table = pd.DataFrame()
  75.  
  76. #   Loop through the given sequences
  77. for i in range(0,len(df["Seq"])):
  78.  
  79.     #   add some random absorbance data
  80.     df.loc[i,'Absorbance'] = rd.random()
  81.  
  82.     #    call the DNA class
  83.     dna = DNA(df.loc[i,"Name"],df.loc[i,"Seq"])
  84.     #   Once called the salts can be changed to adjust the melting temp
  85.     dna.sodium = 0.050
  86.  
  87.     #   Here trying to calculate the concentration
  88.     optics = Optical(df.loc[i,'Absorbance'],dna.Estimate_Ext_Coeff())
  89.  
  90.     #    print the whatever dna properties...
  91.     Info_Table.loc[i,'Sequence Name'] = dna.name
  92.     Info_Table.loc[i,'Sequence'] = dna.sequence
  93.     Info_Table.loc[i, "Molecular Weight (g/mol)"] = dna.AnHydro_MolWeight()
  94.     Info_Table.loc[i,"Melting Temp (C)"] = dna.Melting_Temp()
  95.     Info_Table.loc[i,"GC Content (%)"] = dna.GC_content()
  96.     Info_Table.loc[i,"Length"] = dna.baselength
  97.     Info_Table.loc[i,'Estimate Exctinction (M-1 cm-1)'] = dna.Estimate_Ext_Coeff()
  98.     Info_Table.loc[i,'Concentration (mM)'] = round(optics.Concentration(),3)
  99.     Info_Table.loc[i,'Absorbance'] = round(optics.Abs,3)
  100.  
  101. #   pick an export file
  102. export = 'data.csv'
  103.  
  104. #   Export to file, make sure the method and the filetype match
  105. Info_Table.to_csv(export)
  106.  
  107. #   Print the file name and the PATH
  108. print('--Results saved as:(' + export + ') --In path:' + os.getcwd())
Advertisement
Add Comment
Please, Sign In to add comment