-
Notifications
You must be signed in to change notification settings - Fork 12
HW3 solution
Ming Chen edited this page Sep 19, 2016
·
2 revisions
-
trees = ["Fraxinus pennsylvanica", "Castanea mollissima", "Quercus rubra"]
-
Quercus rubra
-
For example:
for tree in trees: print(tree)
-
1 5 9 13 17 21 25 29
-
Line 5, add colon at end and change file to file contents
file_name = "input_seqs.txt" restriction_enzyme = "CTGCAG" file_contents = open(file_name) for seq in file_contents: index = seq.find(restriction_enzyme) print(index)
-
answer:
# open the input file file = open("input_seqs.txt") # open the output file output = open("trimmed.txt", "w") # <--- add write mode # go through the input file one line at a time for dna in file: # calculate the position of the last character last_character_position = len(dna) # <--- fix var name to dna # get the substring from the 15th character to the end trimmed_dna = dna[14:last_character_position] # print out the trimmed sequence output.write(trimmed_dna) # print out the length to the screen print("processed sequence with length " + str(len(trimmed_dna))) # <--- add str method to print num
EC. Example:
adapter = "ATCTCGTATGCCGTCTTCTGCTTG"
infile = open("input_seqs.txt")
outfile = open("indices.txt","w")
for seq in infile:
index = seq.find(adapter)
outfile.write(str(index)+"\n")