How do I make my code go through all through my list in my file.
1
0
Entering edit mode
16 months ago
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.

sequence • 349 views
ADD COMMENT
2
Entering edit mode
16 months ago

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()
ADD COMMENT

Login before adding your answer.

Traffic: 1160 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6