import sys filename = input("Please enter filename: ") #open the file f=open(filename, "r") #read the file by line lines = f.readlines() #make a list of proteins that followed the header proteins = [] for line in lines: #cheak if is a hearder line if line[0] == '>': #append the header to the protein list header = line proteins.append([header]) else: proteins[-1].append(line); #print(proteins) #count numbers of proteins in the list def count_protein_number(list): count = -1 for item in list[1:]: for character in item: if item!='\n': count+=1 return count #loop through the list of headers following by proteins for protein in proteins: count = count_protein_number(protein) print(protein[0]) print(count,"",protein[1][0:10])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question