samia11

Untitled

Jan 17th, 2021
952
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import csv
  3.  
  4. def main():
  5.  
  6.     # Ensure correct usage
  7.     if len(sys.argv) != 3:
  8.         sys.exit("Usage: python dna.py data.csv sequence.txt")
  9.  
  10.     # open the csv file
  11.     data = []
  12.     with open(sys.argv[1]) as file:
  13.         reader = csv.DictReader(file)
  14.         for name in reader:
  15.             data.append(name)
  16.         header = reader.fieldnames
  17.         header = header[1:]
  18.     print(header)
  19.  
  20.     # open the txt file
  21.     with open(sys.argv[2]) as f:
  22.         sequence = f.read()
  23.     #print(sequence)
  24.  
  25. # computing STR counts
  26.     counts = {'str' : 'count'}
  27.     for strr in header:
  28.         counter = 0;
  29.         for i in range(len(sequence) - len(strr)):
  30.             for j in range(len(sequence)):
  31.                 if sequence[i:j] == strr:
  32.                     counter = counter + 1
  33.                     #print(i, j)
  34.         counts[strr] = str(counter)
  35.     print(counts)
  36.  
  37. if __name__ == "__main__":
  38.     main()
RAW Paste Data