Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv, exit
- import csv
- import re
- if len(argv) < 3:
- print("mising command-line argument")
- exit(1)
- #INSTRUCTIONS
- #1. Read the sequence file into a string (you've got this).
- #2. Open the csv file and get each sub string ("AGATC", "TCTG", etc) from the first row into a list (you've essentially done this too).
- #3. For each item in the list of sub strings, look through the sequence you read in step 1 and see what the longest sequential run is. Store this number in a list so you have the longest runs of all sub strings.
- #4. Iterate through the rest of the CSV file, comparing the numbers in each row to the list of numbers you created in step 3. When all numbers match, the name from this row is the one to print.
- with open(argv[1],"r") as file, open(argv[2],"r") as csvfile:
- count = 0
- contents = file.read() #1. Read the sequence file into a string (you've got this).
- csvcontents = csv.reader(csvfile)
- #2. Open the csv file and get each sub string
- #("AGATC", "TCTG", etc) from the first row
- #into a list (you've essentially done this too).
- header = next(csvcontents)
- print("how long is header?")
- print(len(header))
- sublist = []
- for item in header:
- sublist.append(item)
- complist = sublist[1:]
- #3. For each item in the list of sub strings,
- #look through the sequence you read
- #in step 1 and see what the longest
- #sequential run is. Store this number
- #in a list so you have the longest runs of all sub strings.
- #for item in sublist[1:]:
- #while contents[beg:end]:
- for item in complist: # look at each item in the list
- beg = 0 # beginning index
- end = len(item) # ending index
- seqrun = 0 # number of times the sequence runs/repeats
- while contents[beg:end]: # while the substring of contents from beginning to end have values
- if contents[beg:end] == item: # if the span of contents is equal to the item in the list
- seqrun = 1 # it occurs at least once
- while contents[beg + end:end + end] == item: # as long as the contents span from beginning to end matches the contents span when incremented by end
- seqrun += 1
- beg += end
- end += end
- if seqrun > 1:
- print(item + " repeats " + seqrun + " times")
- beg += 1
- end += 1
- else:
- beg += 1
- end += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement