I would like this carried out in a single list comprehension:
for rec in SeqIO.parse(infile2, "fastq"):
if rec.id+"_RC" in RCList:
rec.reverse_complement(id=rec.id,description="")
else:
rec
This works:
good_reads = ( rec.reverse_complement(id=rec.id,description="") for rec in SeqIO.parse(infile2, "fastq") if rec.id+"_RC" in RCList )
If I put in else into this line there are general invalid syntax errors:
(1) reads = ( rec.reverse_complement(id=rec.id,description="") for rec in SeqIO.parse(infile2, "fastq") if rec.id+"_RC" in RCList rec if not rec.id+"_RC" in RCList)
or the same goes with:
(2) reads = ( rec.reverse_complement(id=rec.id,description="") for rec in SeqIO.parse(infile2, "fastq") if rec.id+"_RC" in RCList else (rec))
Finally, I am using SeqIO to write this to a file
SeqIO.write(good_reads,infile2+".RC.fastq", "fastq")
What is wrong with the above in (1) and (2) ?