daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Aug 21st, 2018 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. subsequences = {}
  3.  
  4. def read_file():
  5.     sequence = ""
  6.     file = open("file/sequence.fasta","r")
  7.     file.readline()
  8.     for line in file.readlines():
  9.         sequence += line[:-1]
  10.     return sequence
  11.  
  12. def set_subsequence(sequence):
  13.     if sequence in subsequences:
  14.         subsequences[sequence] += 1
  15.     else:
  16.         subsequences[sequence] = 1
  17.  
  18. def count_subsequences(sequence,size):
  19.    
  20.     limit = len(sequence) - size + 1
  21.     for i in range(0,limit,37):
  22.         subsequence = sequence[i:i+size]
  23.         set_subsequence(subsequence)
  24.  
  25. if __name__ == '__main__':
  26.     sequence = read_file()
  27.     count_subsequences(sequence,37)
  28.     print(len(subsequences))
  29.     for sub, count in subsequences.items():
  30.         print("{} => {}".format(sub,count))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top