How do I make my code go through all through my list in my file.
hello = open("humanSeq.txt", "r")
l = []
for line in hello:
fields = line.split()
l.append(fields[0])
import Bio
from Bio import Entrez
Entrez.email = "trejomarco@test.edu"
handle = Bio.Entrez.efetch(db="nucleotide", id="NC_001643.1",rettype="gb",retmode="text")
gb_file_contents = handle.read()
handle.close()
from Bio import SeqIO
with open("NC_001643.1", "w") as out_handle:
out_handle.write(gb_file_contents)
with open("NC_001643.1", "r") as in_handle:
record = SeqIO.read(in_handle, format="gb")
print(record.seq[0:])
In my text file, I have a list of ids and I want to know how do I make my code input in all of my ids and record them all into a fasta file.
• 1,069 views
•
link
1 answer
The following code would be an option:
from Bio import Entrez
from Bio import SeqIO
Entrez.email = "trejomarco@test.edu"
fh = open("humanSeq.txt")
oh = open("humanSeq.fasta", "w")
for line in fh:
seq_id = line.strip()
try:
handle = Entrez.efetch(db="nucleotide", id=seq_id, rettype="fasta", retmode="text")
fasta_str = handle.read()
handle.close()
oh.write(fasta_str)
except:
continue
oh.close()
fh.close()
• 0 views
•
link
Log in to answer this question.