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("header prints: ")
- print(header)
- print("header[1] prints: ")
- print(header[1])
- print("header[0] prints: ")
- print(header[0])
- stringcompare = [] # an empty list to store the values of header
- #charcount = 0
- print("appending the stringcompare[] list with every element in header")
- for i in header:
- stringcompare.append(i) # appending works!
- print("every element of stringcompare[] list prints: ")
- for s in stringcompare:
- print(s)
- #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.
- sublist = []
- for item in stringcompare:
- charcount = len(item)
- index = 0
- #print("item " + item + " is " + str(charcount) + " long")
- longest = 0
- if charcount > longest:
- longest = charcount
- index = 0
- while contents[index:charcount]:
- span = contents[index:charcount]
- repcount = 1
- while contents[index + charcount: charcount + charcount] == span:
- repcount += 1
- #Store this number
- #in a list so you
- #have the longest runs of all sub strings. ... why where?
- index += charcount
- charcount += charcount
- sublist.append(repcount) # is this what is meant?
- print("stringcompare prints: ")
- print(stringcompare)
- #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.
- for i in header:
- n = 0
- print("header[" + n + "] prints:")
- print(i)
- n += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement