There are countless ways to accomplish such bash operation, but I always prefer to write simple rules in snakemake
.
# mvfq.py
rule:
input: expand('{samples}_{reads}.fq.gz', samples=['ALT_1', 'ALT_2'], reads=['R1', 'R2'])
rule move_fqs:
output: mvto = '{sample}_{read}.fq.gz'
run:
mvfrom = '_'.join([wildcards.sample.replace('_',''), wildcards.read.replace('R',''), 'clean.fq.gz'])
shell('mv {mvfrom} {output.mvto}')
I can dryrun it
snakemake -s mvfq.py --dryrun
or run a specific target to make sure everything is working
snakemake -s mvfq.py ALT_1_R1.fq.gz
or run it all on my laptop
snakemake -s mvfq.py
or run it using 4 cores
snakemake -s mvfq.py -j4
or in a cluster via qsub with 100 independent jobs
snakemake -s mvfq.py -j100 -c "qsub"
or using remote files at S3 (or dropbox, google drive, etc) in a cluster
snakemake -s mvfq.py -j100 -c "qsub" --default-remote-provider S3 --default-remote-prefix s3/location/
or I can restart from the last failure check points, and many more.
All without changing the underlying code.
And to make things even more complicated, the
rename
tool linked by igor in another answer is not the same as therename
tool in this answer, which is available at https://metacpan.org/release/File-Rename, and in therename
package on Debian and related systems.Indeed, good point, which I overlooked. There are renames and renames around, this one is a Perl script, that other one is a binary executable, and in Debian and relatives is called
rename.ul
.That is a lot of answers for a "how to rename files" question...
I guess this can be further shortened (code) and extended (function) by:
To further complicate things, I don't think every
rename
has the-n
flag. Mine (fromutil-linux-ng
) does not.