comlement fastq file using Biopython
HI. I try to make complement fastq file using this code:
from Bio import SeqIO
seq_=[]
with open("pass/to/input/file.fastq") as handle:
for i in SeqIO.parse(handle,"fastq"):
a =i.seq.complement()
seq_.append(a)
SeqIO.write(seq_, "pass/to/output/file.fastq", "fastq")
Trying this I get error:
Traceback (most recent call last):
File "/home/andrey/PycharmProjects/python_bio/2.py", line 7, in <module>
SeqIO.write(seq_, "/home/andrey/genes/2.fastq", "fastq")
File "/home/andrey/PycharmProjects/python_bio/venv/lib/python3.5/site-packages/Bio/SeqIO/__init__.py", line 497, in write
count = writer_class(fp).write_file(sequences)
File "/home/andrey/PycharmProjects/python_bio/venv/lib/python3.5/site-packages/Bio/SeqIO/Interfaces.py", line 215, in write_file
count = self.write_records(records)
File "/home/andrey/PycharmProjects/python_bio/venv/lib/python3.5/site-packages/Bio/SeqIO/Interfaces.py", line 200, in write_records
self.write_record(record)
File "/home/andrey/PycharmProjects/python_bio/venv/lib/python3.5/site-packages/Bio/SeqIO/QualityIO.py", line 1428, in write_record
if record.seq is None:
AttributeError: 'Seq' object has no attribute 'seq'
In my opinion i did not add id to fastq file
hope for your help)
• 2,725 views
•
link
2 answers
My test fastq file:
@SEQ_ID
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
!''*((((***+))%%%++)(%%%%).1***-+*''))**55CCF>>>>>>CCCCCCC65
@SEQ_ID1
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
+
!''*((((***+))%%%++)(%%%%).1***-+*''))**55CCF>>>>>>CCCCCCC65
@SEQ_ID2
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
+
!''*((((***+))%%%++)(%%%%).1***-+*''))**55CCF>>>>>>CCCCCCC65
• 1 views
•
link
Hello,
the (main) problem is this line:
a =i.seq.complement()
Try this instead:
from Bio import SeqIO
seq = open("file.fastq", "w")
with open("compl.fastq") as handle:
for i in SeqIO.parse(handle, "fastq"):
reverse = i.reverse_complement()
i.seq = reverse.seq
i.letter_annotations = reverse.letter_annotations
SeqIO.write(i, seq, "fastq")
fin swimmer
• 1 views
•
link
Log in to answer this question.
I was wondering whether there is a command-line-only-way to produce the reverse complement of a fastq file. And there is:
BTW: Why do you want to produce a reverse complement of a fastq file?
fin swimmer