comlement fastq file using Biopython
2
0
Entering edit mode
5.9 years ago

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)

sequence gene genome • 2.2k views
ADD COMMENT
0
Entering edit mode

I was wondering whether there is a command-line-only-way to produce the reverse complement of a fastq file. And there is:

$ cat file.fastq|paste - - - -|awk -v OFS="\n" '{"echo "$2"|tr ATCG TAGC|rev"|getline seq; "echo ""\""$4"\"|rev"|getline qual; print $1, seq, $3, qual}'

BTW: Why do you want to produce a reverse complement of a fastq file?

fin swimmer

ADD REPLY
0
Entering edit mode
5.9 years ago

My test fastq file:

@SEQ_ID
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
!''*((((***+))%%%++)(%%%%).1***-+*''))**55CCF>>>>>>CCCCCCC65
@SEQ_ID1
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
+
!''*((((***+))%%%++)(%%%%).1***-+*''))**55CCF>>>>>>CCCCCCC65
@SEQ_ID2
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
+
!''*((((***+))%%%++)(%%%%).1***-+*''))**55CCF>>>>>>CCCCCCC65
ADD COMMENT
0
Entering edit mode
5.9 years ago

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

ADD COMMENT

Login before adding your answer.

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