sr320 / course-fish546-2018

7 stars 2 forks source link

bash - subtracting a portion of a file name #86

Closed kimh11 closed 5 years ago

kimh11 commented 5 years ago

I'm trying to convert all .sam files to .bam files. To this this, I figured I'll create a list of commands using:

for f in *.sam;
do echo "samtools view -bS $f > $f.bam" >> samtobam;
done

It works and I get a list that looks like this:

samtools view -bS aln-10595.sam > aln-10595.sam.bam
samtools view -bS aln-10596.sam > aln-10596.sam.bam
...

I would rather have files called aln-10595.bam and not all-10595.sam.bam. Is there an easy way to this this as part of the for loop?

Thank you!

sr320 commented 5 years ago

find and xargs would work will for this..

an example

%%bash
find /Volumes/Serine/wd/18-04-27/zr2096_*R1* \
| xargs basename -s _s1_R1_val_1.fq.gz | xargs -I{} /Applications/bioinfo/Bismark_v0.19.0/bismark \
--path_to_bowtie /Applications/bioinfo/bowtie2-2.3.4.1-macos-x86_64 \
--genome /Volumes/Serine/wd/18-03-15/genome \
--score_min L,0,-1.2 \
-p 4 \
--non_directional \
-1 /Volumes/Serine/wd/18-04-27/{}_s1_R1_val_1.fq.gz \
-2 /Volumes/Serine/wd/18-04-27/{}_s1_R2_val_2.fq.gz \
2> bismark.err