Entering edit mode
2.9 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
check this tutorial: https://biopython.org/wiki/Split_large_file