This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Seqrecord object to only a single line sequence (without ID)

I have used Biopython to import a sequence based on Genbank ID (that part works smoothly). However, as an output, I want to split the only sequence by a certain width and to create an output list. For instance, if the sequence has 1000 not and nt is 100 I want to end up with 10 new sequences.

It seems that the Seqrecord format is not suitable for basic text manipulation. How, could one extract a sequence as a text?

import Bio 
print("Insert NCBI code")
while True:
    DNA, nt = input("Enter NCBI code, length of oligonucleotides: ").split()
    print("Inser NCBI code: ", DNA)
    print("length: ", nt)
    from Bio import SeqIO
    from Bio import Entrez
    Entrez.email = "123456789@gmail.com"  
    handle = Entrez.efetch(db="nucleotide", id=DNA, rettype="gb", retmode="text")
    sample = SeqIO.read(handle, "genbank")
    out = open("DNA.fasta",'w')
    a = SeqIO.write(sample, out, "fasta")

    #from textwrap import wrap
    #print(wrap(sample, nt))

    import textwrap
    textwrap.fill(a, width=nt)

    break
seqio biopython python

0 answers

No answers yet.

Log in to answer this question.