Advertisement
berinkaq

Untitled

Mar 10th, 2021
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. def count_n(file):
  2.     """
  3.     amount of N
  4.     """
  5.     f = open(file, 'r')
  6.     text = f.read()
  7.     text = text.replace('\r', '')
  8.     text = text.replace('\n', '')
  9.     f.close()
  10.     l = len(text)
  11.     n = text.count('N')
  12.     print('total length =', l)
  13.     print('#N =', n)
  14.     print("it's", round(n / l * 100, 3), '%')
  15.  
  16.  
  17. def count_repeatitions(file):
  18.     """
  19.     повторы длины >= 1000
  20.     """
  21.     f = open(file, 'r')
  22.     text = f.read()
  23.     text = text.replace('\r', '')
  24.     text = text.replace('\n', '')
  25.     f.close()
  26.     ans = 0
  27.     l_curr = 0
  28.     for ch in text:
  29.         if ch != 'N':
  30.             if l_curr >= 1000:
  31.                 ans += 1
  32.             l_curr = 0
  33.         else:
  34.             l_curr += 1
  35.     if l_curr >= 1000:
  36.         ans += 1
  37.     print('amount of repetitions with len >= 1000 is', ans)
  38.  
  39.  
  40. file = 'sequence.fasta'
  41. count_n(file)
  42. count_repeatitions(file)
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement