wdecoster / chopper

MIT License
135 stars 11 forks source link

error: Found argument 'file.fastq' which wasn't expected, or isn't valid in this context #10

Closed dgslos closed 4 months ago

dgslos commented 1 year ago

Wanted behavior: Run chopper directly on input files


I noticed that I can run chopper in a pipe like this:

cat file.fastq | chopper --minlength 1350 --maxlength 1600 --quality 10 > test.fastq

But it seems I cannot run it directly on the file like this:

chopper --minlength 1350 --maxlength 1600 --quality 10  file.fastq> test.fastq

Resulting in:

error: Found argument 'file.fastq' which wasn't expected, or isn't valid in this context

Maybe you could consider adding this functionality to make the use of this tool more straightforward?

wdecoster commented 1 year ago

Hi,

Yes, that would be possible, I will put your request on the list :-)

Wouter

Mailinnia commented 1 year ago

Any progress on this? :)

I can't implement chopper in my pipeline. I've tried piping with subprocess.Popen, but get the same error.

wdecoster commented 1 year ago

I can't implement chopper in my pipeline. I've tried piping with subprocess.Popen, but get the same error.

That should work, in principle. Which (python?) code leads to that error?

Mailinnia commented 1 year ago

My bad. I found a mistake in my code.

It seems to work doing this:

input1 = 'barcode37.fastq'
cmd_cat = ['cat', input1]
fastq = subprocess.Popen(cmd_cat, stdout=subprocess.PIPE)

cmd_chopper = ['chopper', '-l', '1','-q', '3','--headcrop', '30', '--tailcrop', '30', '--threads', '12']

reads_trim = open('test.fastq', 'w')
chopper = subprocess.Popen(cmd_chopper, stdin=fastq.stdout, stdout=reads_trim)
wdecoster commented 1 year ago

It seems like you are reinventing a workflow system like snakemake. Maybe that solves the needs that you try to take care of in your python code.

I can also recommend the python shlex module, which you could use to avoid splitting the arguments in a list:

import shlex
cmd_chopper = shlex.split('chopper -l 1 -q 3 --headcrop 30 --tailcrop 30 --threads 12')
JMencius commented 4 months ago

Maybe you could consider adding this functionality to make the use of this tool more straightforward?

@wdecoster Any update of this issue? I also found this enhancement to be very useful. But the latest chopper 0.7.0 still do not have the feature. If you agree, I would be happy to implement this feature and make a PR.

wdecoster commented 4 months ago

Oh, that would be great! :)

wdecoster commented 4 months ago

Implemented thanks to @JMencius! I will make a new release soon.