hinagawa

2_HW_BioInf

Nov 10th, 2020 (edited)
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. import random
  2.  
  3. def makeDNA(countAT, countCG):
  4.     countA = int(countAT / 2)
  5.     countT = int(countAT / 2)
  6.     countC = int(countCG / 2)
  7.     countG = int(countCG / 2)
  8.     strA = ''.join(random.choice("A") for _ in range(countA))
  9.     strT = ''.join(random.choice("T") for _ in range(countT))
  10.     strC = ''.join(random.choice("C") for _ in range(countC))
  11.     strG = ''.join(random.choice("G") for _ in range(countG))
  12.     listDNA = list(strA + strT + strC + strG)
  13.     random.shuffle(listDNA)
  14.     DNA = ''.join(listDNA)
  15.     return DNA
  16.  
  17.  
  18. def findORF(strDNA):
  19.     listORF = list(strDNA[0 + i:3 + i] for i in range(0, len(strDNA), 3))
  20.  
  21.     for i in range(len(listORF)):
  22.         newORF = []
  23.         if listORF[i] == "ATG":
  24.             newORF.append(listORF[i])
  25.             for j in range(i + 1, len(listORF)):
  26.                 if listORF[j] != 'TAA' and listORF[j] != 'TAG' and listORF[j] != 'TGA' and listORF[j] != 'ATG':
  27.                     newORF.append(listORF[j])
  28.                 else:
  29.                     if listORF[j] != 'ATG':
  30.                         newORF.append(listORF[j])
  31.                         return newORF
  32.  
  33.  
  34. def secondFrame(strDNA):
  35.     strDNA2 = strDNA[1:]
  36.     return findORF(strDNA2)
  37.  
  38.  
  39. def thirdFrame(strDNA):
  40.     strDNA2 = strDNA[2:]
  41.     return findORF(strDNA2)
  42.  
  43.  
  44. def check(newORF):
  45.     if newORF is None:
  46.         return 0
  47.     else:
  48.         strORF = ''
  49.         for i in range(0, len(newORF)):
  50.             strORF = strORF + newORF[i]
  51.  
  52.         if len(strORF) % 3 == 0 and len(strORF) >= 90:
  53.             return 1
  54.         else:
  55.             return 0
  56.  
  57.  
  58. def reverseDNA(strDNA):
  59.     rDNA = ""
  60.     for i in strDNA:
  61.         if i == "A":
  62.             rDNA = rDNA + "G"
  63.         elif i == "T":
  64.             rDNA = rDNA + "C"
  65.         if i == "G":
  66.             rDNA = rDNA + "A"
  67.         elif i == "C":
  68.             rDNA = rDNA + "T"
  69.     revDNA = rDNA[::-1]
  70.     return revDNA
  71.  
  72.  
  73. def print3(frame):
  74.     newStr = ''
  75.     for i in frame:
  76.         newStr += i + ' '
  77.     return newStr
  78.  
  79.  
  80. if __name__ == '__main__':
  81.     dnaSize = 1000
  82.     for i in range(20, 81):
  83.         k = 0
  84.         for j in range(1, 10000):
  85.             percentGC = i
  86.             percentAT = 100 - percentGC
  87.             countGC = int((dnaSize * percentGC) / 100)
  88.             countAT = int((dnaSize * percentAT) / 100)
  89.             strDNA = makeDNA(countAT, countGC)
  90.             dfirstFrame = findORF(strDNA)
  91.             dsecondFrame = secondFrame(strDNA)
  92.             dthirdFrame = thirdFrame(strDNA)
  93.             rDNA = reverseDNA(strDNA)
  94.             rfirstFrame = findORF(rDNA)
  95.             rsecondFrame = secondFrame(rDNA)
  96.             rthirdFrame = thirdFrame(rDNA)
  97.             if check(dfirstFrame) | check(dsecondFrame) | check(dthirdFrame) | check(rfirstFrame) | check(rfirstFrame) | check(rsecondFrame) | check(rthirdFrame):
  98.                 k += 1
  99.  
  100.         print(percentGC,";", k / 10000)
  101.  
Add Comment
Please, Sign In to add comment