1

So I am trying to run a program iRep and usually it runs as-

iRep -f Bins/10000A-01-01_bin.* -s sam/10000A-01-01.sam.sorted.sam --sort -o 10000A-01-01_iRep_output

in sam folder -

10000A-01-01.sam.sorted.sam
10000A-01-02.sam.sorted.sam
10000A-01-03.sam.sorted.sam

in Bins folder -

10000A-01-01_bin.1.fa
10000A-01-01_bin.2.fa
10000A-01-01_bin.3.fa

10000A-01-02_bin.1.fa
10000A-01-02_bin.2.fa
10000A-01-02_bin.3.fa

10000A-01-03_bin.1.fa
10000A-01-03_bin.3.fa
10000A-01-03_bin.5.fa
10000A-01-03_bin.7.fa

I want to have one loop where I can do all in one command, instead of running each command for each sample individually, like

iRep -f Bins/10000A-01-01_bin.* -s sam/10000A-01-01.sam.sorted.sam --sort -o 10000A-01-01_iRep_output
iRep -f Bins/10000A-01-02_bin.* -s sam/10000A-01-02.sam.sorted.sam --sort -o 10000A-01-02_iRep_output
iRep -f Bins/10000A-01-03_bin.* -s sam/10000A-01-03.sam.sorted.sam --sort -o 10000A-01-03_iRep_output

Any idea how I could do this?

2 Answers 2

2
#!/bin/sh

# Loop over the SAM files
for sam in sam/*.sam.sorted.sam; do
    # Extract the sample name by taking the basename of the SAM file
    # and removing the known filename suffix.
    sample=$(basename "$sam" .sam.sorted.sam)

    # Call iRep (as described in the question)
    iRep -f Bins/"$sample"_bin.* -s "$sam" --sort -o "$sample"_iRep_output
done

Given the files in the question, this would end up running

iRep -f Bins/10000A-01-01_bin.1.fa Bins/10000A-01-01_bin.2.fa Bins/10000A-01-01_bin.3.fa -s sam/10000A-01-01.sam.sorted.sam --sort -o 10000A-01-01_iRep_output
iRep -f Bins/10000A-01-02_bin.1.fa Bins/10000A-01-02_bin.2.fa Bins/10000A-01-02_bin.3.fa -s sam/10000A-01-02.sam.sorted.sam --sort -o 10000A-01-02_iRep_output
iRep -f Bins/10000A-01-03_bin.1.fa Bins/10000A-01-03_bin.3.fa Bins/10000A-01-03_bin.5.fa -s sam/10000A-01-03.sam.sorted.sam --sort -o 10000A-01-03_iRep_output
1
  • can we make the above scripts in parallel? @Kusalananda Commented Sep 24, 2019 at 9:42
1

Using GNU Parallel it looks like this:

parallel --plus iRep -f Bins/{/...}_bin.* -s {} --sort -o {/...}_iRep_output ::: sam/*.sam.sorted.sam

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.