Reputation: 45
I need to iterate through input file pairs, R1 and R2, which will be processed together and each appended with a ".trim" file extension.
I have a limited knowledge of python and glob, which have worked well for similar tasks using paired inputs but a single output. I am completely stumped as to why this doesn't work, though I'm sure it's an easy fix.
#!/usr/bin/python
import glob
import os
files = glob.glob("ATAC*R1*.fastq.gz")
for ifile in files:
os.system("cutadapt -a CTGTCTCTTATACACATCT -A CTGTCTCTTATACACATCT -a AGATGTGTATAAGAGA -o %s.trim -p %s.trim %s %s" % (ifile, ifile.replace("R1","R2"), ifile, ifile.replace("R1","R2"))
Error:
line 7
^
SyntaxError: invalid syntax
This should work as follows:
ATAC2-1_R1_.fastq.gz and ATAC2-1_R1_.fastq.gz -> ATAC2-1_R1_.fastq.gz.trim and ATAC2-1_R1_.fastq.gz.trim.
There are several R1 and R2 pairs that I would like to iterate through.Thanks for the help!
Upvotes: 0
Views: 252
Reputation: 1501
The only issue is that you're missing an ending parenthesis:
os.system("cutadapt -a CTGTCTCTTATACACATCT -A CTGTCTCTTATACACATCT -a AGATGTGTATAAGAGA -o %s.trim -p %s.trim %s %s" % (ifile, ifile.replace("R1","R2"), ifile, ifile.replace("R1","R2")))
You just need to add the ending parenthesis and you should stop experiencing that syntax error.
Upvotes: 1
Reputation: 338
Instead of trying to do this with %s placeholders, I would try .format(), like so:
"cutadapt -a CTGTCTCTTATACACATCT -A CTGTCTCTTATACACATCT -a AGATGTGTATAAGAGA -o {0}.trim -p {1}.trim {2} {3}".format(ifile, ifile.replace("R1","R2"), ifile, ifile.replace("R1","R2"))
Upvotes: 0