Advertisement
berinkaq

Untitled

Feb 23rd, 2021
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1.  
  2. # #C = #G, #T = #A
  3. def check1(file):
  4.     f = open(file, 'r')
  5.     text = f.read()
  6.     text = text.replace('\r', '')
  7.     text = text.replace('\n', '')
  8.     c = 0
  9.     g = 0
  10.     t = 0
  11.     a = 0
  12.     for ch in text:
  13.         if ch == 'C':
  14.             c += 1
  15.         if ch == 'G':
  16.             g += 1
  17.         if ch == 'T':
  18.             t += 1
  19.         if ch == 'A':
  20.             a += 1
  21.     c_g = (max(c, g) - min(c, g)) / max(c, g) * 100
  22.     print('#C = ', c, '\n#G = ', g, '\ndifference C&G = ', c_g, '%', sep = '')
  23.     a_t = (max(a, t) - min(a, t)) / max(a, t) * 100
  24.     print('#A = ', a, '\n#T = ', t, '\ndifference A&T = ', a_t, '%', sep = '')
  25.     print()
  26.  
  27.  
  28. # слов CG мало в определенных геномах
  29. def check2(file):
  30.     f = open(file, 'r')
  31.     text = f.read()
  32.     text = text.replace('\r', '')
  33.     text = text.replace('\n', '')
  34.     cg = 0
  35.     for i in range(len(text) - 1):
  36.         if text[i] == 'C' and text[i + 1] == 'G':
  37.             cg += 1
  38.     print("#CG = ", cg, sep = '')
  39.     print()
  40.  
  41.  
  42. # слов TA мало во всех геномах
  43. def check3(file):
  44.     f = open(file, 'r')
  45.     text = f.read()
  46.     text = text.replace('\r', '')
  47.     text = text.replace('\n', '')
  48.     ta = 0
  49.     for i in range(len(text) - 1):
  50.         if text[i] == 'T' and text[i + 1] == 'A':
  51.             ta += 1
  52.     print("#TA = ", ta, sep = '')
  53.     print()
  54.  
  55. # в некоторых геномах #C > #G в одной части и #G > #C в другой части (GC skew)
  56. # проверяем первую половину и вторую половину
  57. def check4(file):
  58.     f = open(file, 'r')
  59.     text = f.read()
  60.     text = text.replace('\r', '')
  61.     text = text.replace('\n', '')
  62.     l = len(text) // 2
  63.     c = 0
  64.     g = 0
  65.     for i in range(l):
  66.         if text[i] == 'C':
  67.             c += 1
  68.         if text[i] == 'G':
  69.             g += 1
  70.     print("first half:\n", '#C = ', c, '\n#G = ', g, sep = '')
  71.     c = 0
  72.     g = 0
  73.     for i in range(l, len(text)):
  74.         if text[i] == 'C':
  75.             c += 1
  76.         if text[i] == 'G':
  77.             g += 1
  78.     print("second half:\n", '#C = ', c, '\n#G = ', g, sep = '')    
  79.     print()
  80.  
  81.  
  82.  
  83. files = ['NC_001802.1.fna', 'NC_002642.fna', 'NC_045512.2.fna']
  84. viruses = ['HIV', 'YABA', 'COVID']
  85.  
  86. for i in range(len(files)):
  87.     print(viruses[i], ': ')
  88.     check1(files[i])
  89.     check2(files[i])
  90.     check3(files[i])
  91.     check4(files[i])
  92.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement