Seqrecord object to only a single line sequence (without ID)
0
0
Entering edit mode
3.0 years ago
voltosj • 0

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 • 711 views
ADD COMMENT
1
Entering edit mode
ADD REPLY

Login before adding your answer.

Traffic: 2092 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