Hi: I want to extract one section of a chromosome into a FASTA file, I have two versions, but neither of them work correctly. At the end I want to have a normal FASTA file like this:
>chromosome_1_results
ACGGGAAAAA.......
version 1
from Bio import SeqIO
inFile = open('c:\\data\\ch1.fasta','r')
fw=open("c:\\data\\ch1results.fasta",'w')
s=0
for record in SeqIO.parse(inFile,'fasta'):
fw.write (str(record.seq)[1:((23522552+23660224)/2)+1])
fw.close()
In this version it generates the file, but when I want to open it using for example a word processor it cannot be read. I have tried with ch1.fasta and opens normally. Also I have problems in how to put a header like in the FASTA files to my results.
version 2 from Bio import SeqIO
inFile = open('c:\\data\\ch1.fasta','r')
fw=open("c:\\data\\ch1results.fasta",'w')
s=0
for record in SeqIO.parse(inFile,'fasta'):
SeqIO.write (str(record.seq)[1:((23522552+23660224)/2)+1],fw,"fasta")
fw.close()
in the second case I got an error that says "str object has no attribute id"
Thanks
thank you very much for your time in answering this question @Michael Schubert, now it works really nice