combine commands using loop Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!What's the best way to break from nested (for) loops?Breaking out of a nested loopIn .NET, which loop runs faster, 'for' or 'foreach'?A 'for' loop to iterate over an enum in JavaCan I use break to exit multiple nested for loops?Loop through an array in JavaScriptGet loop count inside a Python FOR loopPythonic way to combine FOR loop and IF statementWhy does python use 'else' after for and while loops?Java 8 Iterable.forEach() vs foreach loop

Is it fair for a professor to grade us on the possession of past papers?

porting install scripts : can rpm replace apt?

Can inflation occur in a positive-sum game currency system such as the Stack Exchange reputation system?

Seeking colloquialism for “just because”

How do I keep my slimes from escaping their pens?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Is it true that "carbohydrates are of no use for the basal metabolic need"?

List *all* the tuples!

Why are Kinder Surprise Eggs illegal in the USA?

What is the logic behind the Maharil's explanation of why we don't say שעשה ניסים on Pesach?

Should I discuss the type of campaign with my players?

Identifying polygons that intersect with another layer using QGIS?

How to bypass password on Windows XP account?

What does F' and F" mean?

What exactly is a "Meth" in Altered Carbon?

English words in a non-english sci-fi novel

Using audio cues to encourage good posture

How does the particle を relate to the verb 行く in the structure「A を + B に行く」?

What does an IRS interview request entail when called in to verify expenses for a sole proprietor small business?

Using et al. for a last / senior author rather than for a first author

Why did the rest of the Eastern Bloc not invade Yugoslavia?

How discoverable are IPv6 addresses and AAAA names by potential attackers?

Error "illegal generic type for instanceof" when using local classes

Generate an RGB colour grid



combine commands using loop



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!What's the best way to break from nested (for) loops?Breaking out of a nested loopIn .NET, which loop runs faster, 'for' or 'foreach'?A 'for' loop to iterate over an enum in JavaCan I use break to exit multiple nested for loops?Loop through an array in JavaScriptGet loop count inside a Python FOR loopPythonic way to combine FOR loop and IF statementWhy does python use 'else' after for and while loops?Java 8 Iterable.forEach() vs foreach loop



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I want to perform alignment using Hisat2 for single-ended thousands of samples and each sample distributed among different libraries.



I have modified this script (https://www.biostars.org/p/223404/#224169):



#!/bin/bash
for f in `ls data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/*.fastq.bz2_trimmed.fq.gz | sed 's/.fastq.bz2_trimmed.fq.gz//g' | sort -u`
do
echo HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U $f.fastq.bz2_trimmed.fq.gz -S $f.bam
done


It gives me echo as:



HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.bam
HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.bam
HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.bam
HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.bam


As this is the same sample (Alst-1_6989) is distributed among different lanes (SRR3460433,SRR3460434,SRR3460435,SRR3460436) which should be joined by comma not as a separate command as follows and I want the name of the sample (Alst-1_6989) in the output file (Alst-1_6989.bam), currently its name of the distributed library. Its just one example I have thousands of sample with a variable number of distributed library, so we need to keep this thing in mind.



HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/Alst-1_6989.bam


I think some neseted for loop can work or something like this, Any help will be highly appreciated.










share|improve this question




























    0















    I want to perform alignment using Hisat2 for single-ended thousands of samples and each sample distributed among different libraries.



    I have modified this script (https://www.biostars.org/p/223404/#224169):



    #!/bin/bash
    for f in `ls data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/*.fastq.bz2_trimmed.fq.gz | sed 's/.fastq.bz2_trimmed.fq.gz//g' | sort -u`
    do
    echo HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U $f.fastq.bz2_trimmed.fq.gz -S $f.bam
    done


    It gives me echo as:



    HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.bam
    HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.bam
    HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.bam
    HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.bam


    As this is the same sample (Alst-1_6989) is distributed among different lanes (SRR3460433,SRR3460434,SRR3460435,SRR3460436) which should be joined by comma not as a separate command as follows and I want the name of the sample (Alst-1_6989) in the output file (Alst-1_6989.bam), currently its name of the distributed library. Its just one example I have thousands of sample with a variable number of distributed library, so we need to keep this thing in mind.



    HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/Alst-1_6989.bam


    I think some neseted for loop can work or something like this, Any help will be highly appreciated.










    share|improve this question
























      0












      0








      0








      I want to perform alignment using Hisat2 for single-ended thousands of samples and each sample distributed among different libraries.



      I have modified this script (https://www.biostars.org/p/223404/#224169):



      #!/bin/bash
      for f in `ls data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/*.fastq.bz2_trimmed.fq.gz | sed 's/.fastq.bz2_trimmed.fq.gz//g' | sort -u`
      do
      echo HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U $f.fastq.bz2_trimmed.fq.gz -S $f.bam
      done


      It gives me echo as:



      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.bam
      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.bam
      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.bam
      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.bam


      As this is the same sample (Alst-1_6989) is distributed among different lanes (SRR3460433,SRR3460434,SRR3460435,SRR3460436) which should be joined by comma not as a separate command as follows and I want the name of the sample (Alst-1_6989) in the output file (Alst-1_6989.bam), currently its name of the distributed library. Its just one example I have thousands of sample with a variable number of distributed library, so we need to keep this thing in mind.



      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/Alst-1_6989.bam


      I think some neseted for loop can work or something like this, Any help will be highly appreciated.










      share|improve this question














      I want to perform alignment using Hisat2 for single-ended thousands of samples and each sample distributed among different libraries.



      I have modified this script (https://www.biostars.org/p/223404/#224169):



      #!/bin/bash
      for f in `ls data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/*.fastq.bz2_trimmed.fq.gz | sed 's/.fastq.bz2_trimmed.fq.gz//g' | sort -u`
      do
      echo HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U $f.fastq.bz2_trimmed.fq.gz -S $f.bam
      done


      It gives me echo as:



      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.bam
      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.bam
      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.bam
      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.bam


      As this is the same sample (Alst-1_6989) is distributed among different lanes (SRR3460433,SRR3460434,SRR3460435,SRR3460436) which should be joined by comma not as a separate command as follows and I want the name of the sample (Alst-1_6989) in the output file (Alst-1_6989.bam), currently its name of the distributed library. Its just one example I have thousands of sample with a variable number of distributed library, so we need to keep this thing in mind.



      HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460435.fastq.bz2_trimmed.fq.gz,data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460436.fastq.bz2_trimmed.fq.gz -S data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/Alst-1_6989.bam


      I think some neseted for loop can work or something like this, Any help will be highly appreciated.







      for-loop nested-loops






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 17:51









      Waqas KhokharWaqas Khokhar

      697




      697






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Don't parse ls.



          Full path filenames shouldn't be dups, so I dropped the sort.

          I'm going to assume a reasonable number of files per sample.

          For that -



          base="$PWD"
          cmdtrunk="HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U "
          shopt -s nullglob # return empty if not matched
          for sample in data/1547_2015/Accessions/* # assumes no spaces, etc
          do [[ -d "$base/$sample" ]] || continue # ignore files in this dir
          lst=( $( find "$base/$sample/transcriptome/fastq/trim/" -name *.fastq.bz2_trimmed.fq.gz -print0 |
          while read -r -d '' f; do printf "%sn" "$f"; done ) )
          if (( $#lst[@] ))
          then stack="$( printf "%s," "$lst[@]" )"
          printf " %sn" "$cmdtrunk $stack%, -S $base/$sample/$sample##*/.bam"
          fi
          done


          I don't have anything like this structure, so haven't tested this as much as I'd like. Still, but all it does is print the commands, which you can save and inspect before executing.



          Let me know what's broken and we'll fix it.






          share|improve this answer

























          • Many thanks, the above command combine the libraries like this: cmdtrunk /media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,/media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz, But it misses the starting command: HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U Is it possible to sort it out? and make this command executable

            – Waqas Khokhar
            Mar 10 at 21:00







          • 1





            Two major things - 1) I didn't put a $ on my var (mea culpa) and 2) you have embedded spaces in your structure. I edited for that. As a rule, I avoid spaces in my filenames like the plague it is, but I totally understand that people don't always get to choose. Tell me what blows up this time. :)

            – Paul Hodges
            Mar 11 at 13:41











          • (stackoverflow.com/users/8656552/paul-hodges), is it possible to remove comma from the end of last joined fastq file. Means I want files joined like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz) not like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz,)

            – Waqas Khokhar
            Mar 27 at 19:45











          • edited, try that. :)

            – Paul Hodges
            Apr 1 at 14:03











          • Hm. Previous edit didn't take. Did it again.

            – Paul Hodges
            Apr 2 at 14:21











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55068476%2fcombine-commands-using-loop%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Don't parse ls.



          Full path filenames shouldn't be dups, so I dropped the sort.

          I'm going to assume a reasonable number of files per sample.

          For that -



          base="$PWD"
          cmdtrunk="HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U "
          shopt -s nullglob # return empty if not matched
          for sample in data/1547_2015/Accessions/* # assumes no spaces, etc
          do [[ -d "$base/$sample" ]] || continue # ignore files in this dir
          lst=( $( find "$base/$sample/transcriptome/fastq/trim/" -name *.fastq.bz2_trimmed.fq.gz -print0 |
          while read -r -d '' f; do printf "%sn" "$f"; done ) )
          if (( $#lst[@] ))
          then stack="$( printf "%s," "$lst[@]" )"
          printf " %sn" "$cmdtrunk $stack%, -S $base/$sample/$sample##*/.bam"
          fi
          done


          I don't have anything like this structure, so haven't tested this as much as I'd like. Still, but all it does is print the commands, which you can save and inspect before executing.



          Let me know what's broken and we'll fix it.






          share|improve this answer

























          • Many thanks, the above command combine the libraries like this: cmdtrunk /media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,/media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz, But it misses the starting command: HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U Is it possible to sort it out? and make this command executable

            – Waqas Khokhar
            Mar 10 at 21:00







          • 1





            Two major things - 1) I didn't put a $ on my var (mea culpa) and 2) you have embedded spaces in your structure. I edited for that. As a rule, I avoid spaces in my filenames like the plague it is, but I totally understand that people don't always get to choose. Tell me what blows up this time. :)

            – Paul Hodges
            Mar 11 at 13:41











          • (stackoverflow.com/users/8656552/paul-hodges), is it possible to remove comma from the end of last joined fastq file. Means I want files joined like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz) not like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz,)

            – Waqas Khokhar
            Mar 27 at 19:45











          • edited, try that. :)

            – Paul Hodges
            Apr 1 at 14:03











          • Hm. Previous edit didn't take. Did it again.

            – Paul Hodges
            Apr 2 at 14:21















          1














          Don't parse ls.



          Full path filenames shouldn't be dups, so I dropped the sort.

          I'm going to assume a reasonable number of files per sample.

          For that -



          base="$PWD"
          cmdtrunk="HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U "
          shopt -s nullglob # return empty if not matched
          for sample in data/1547_2015/Accessions/* # assumes no spaces, etc
          do [[ -d "$base/$sample" ]] || continue # ignore files in this dir
          lst=( $( find "$base/$sample/transcriptome/fastq/trim/" -name *.fastq.bz2_trimmed.fq.gz -print0 |
          while read -r -d '' f; do printf "%sn" "$f"; done ) )
          if (( $#lst[@] ))
          then stack="$( printf "%s," "$lst[@]" )"
          printf " %sn" "$cmdtrunk $stack%, -S $base/$sample/$sample##*/.bam"
          fi
          done


          I don't have anything like this structure, so haven't tested this as much as I'd like. Still, but all it does is print the commands, which you can save and inspect before executing.



          Let me know what's broken and we'll fix it.






          share|improve this answer

























          • Many thanks, the above command combine the libraries like this: cmdtrunk /media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,/media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz, But it misses the starting command: HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U Is it possible to sort it out? and make this command executable

            – Waqas Khokhar
            Mar 10 at 21:00







          • 1





            Two major things - 1) I didn't put a $ on my var (mea culpa) and 2) you have embedded spaces in your structure. I edited for that. As a rule, I avoid spaces in my filenames like the plague it is, but I totally understand that people don't always get to choose. Tell me what blows up this time. :)

            – Paul Hodges
            Mar 11 at 13:41











          • (stackoverflow.com/users/8656552/paul-hodges), is it possible to remove comma from the end of last joined fastq file. Means I want files joined like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz) not like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz,)

            – Waqas Khokhar
            Mar 27 at 19:45











          • edited, try that. :)

            – Paul Hodges
            Apr 1 at 14:03











          • Hm. Previous edit didn't take. Did it again.

            – Paul Hodges
            Apr 2 at 14:21













          1












          1








          1







          Don't parse ls.



          Full path filenames shouldn't be dups, so I dropped the sort.

          I'm going to assume a reasonable number of files per sample.

          For that -



          base="$PWD"
          cmdtrunk="HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U "
          shopt -s nullglob # return empty if not matched
          for sample in data/1547_2015/Accessions/* # assumes no spaces, etc
          do [[ -d "$base/$sample" ]] || continue # ignore files in this dir
          lst=( $( find "$base/$sample/transcriptome/fastq/trim/" -name *.fastq.bz2_trimmed.fq.gz -print0 |
          while read -r -d '' f; do printf "%sn" "$f"; done ) )
          if (( $#lst[@] ))
          then stack="$( printf "%s," "$lst[@]" )"
          printf " %sn" "$cmdtrunk $stack%, -S $base/$sample/$sample##*/.bam"
          fi
          done


          I don't have anything like this structure, so haven't tested this as much as I'd like. Still, but all it does is print the commands, which you can save and inspect before executing.



          Let me know what's broken and we'll fix it.






          share|improve this answer















          Don't parse ls.



          Full path filenames shouldn't be dups, so I dropped the sort.

          I'm going to assume a reasonable number of files per sample.

          For that -



          base="$PWD"
          cmdtrunk="HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U "
          shopt -s nullglob # return empty if not matched
          for sample in data/1547_2015/Accessions/* # assumes no spaces, etc
          do [[ -d "$base/$sample" ]] || continue # ignore files in this dir
          lst=( $( find "$base/$sample/transcriptome/fastq/trim/" -name *.fastq.bz2_trimmed.fq.gz -print0 |
          while read -r -d '' f; do printf "%sn" "$f"; done ) )
          if (( $#lst[@] ))
          then stack="$( printf "%s," "$lst[@]" )"
          printf " %sn" "$cmdtrunk $stack%, -S $base/$sample/$sample##*/.bam"
          fi
          done


          I don't have anything like this structure, so haven't tested this as much as I'd like. Still, but all it does is print the commands, which you can save and inspect before executing.



          Let me know what's broken and we'll fix it.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 2 at 14:20

























          answered Mar 8 at 19:30









          Paul HodgesPaul Hodges

          4,0261524




          4,0261524












          • Many thanks, the above command combine the libraries like this: cmdtrunk /media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,/media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz, But it misses the starting command: HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U Is it possible to sort it out? and make this command executable

            – Waqas Khokhar
            Mar 10 at 21:00







          • 1





            Two major things - 1) I didn't put a $ on my var (mea culpa) and 2) you have embedded spaces in your structure. I edited for that. As a rule, I avoid spaces in my filenames like the plague it is, but I totally understand that people don't always get to choose. Tell me what blows up this time. :)

            – Paul Hodges
            Mar 11 at 13:41











          • (stackoverflow.com/users/8656552/paul-hodges), is it possible to remove comma from the end of last joined fastq file. Means I want files joined like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz) not like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz,)

            – Waqas Khokhar
            Mar 27 at 19:45











          • edited, try that. :)

            – Paul Hodges
            Apr 1 at 14:03











          • Hm. Previous edit didn't take. Did it again.

            – Paul Hodges
            Apr 2 at 14:21

















          • Many thanks, the above command combine the libraries like this: cmdtrunk /media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,/media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz, But it misses the starting command: HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U Is it possible to sort it out? and make this command executable

            – Waqas Khokhar
            Mar 10 at 21:00







          • 1





            Two major things - 1) I didn't put a $ on my var (mea culpa) and 2) you have embedded spaces in your structure. I edited for that. As a rule, I avoid spaces in my filenames like the plague it is, but I totally understand that people don't always get to choose. Tell me what blows up this time. :)

            – Paul Hodges
            Mar 11 at 13:41











          • (stackoverflow.com/users/8656552/paul-hodges), is it possible to remove comma from the end of last joined fastq file. Means I want files joined like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz) not like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz,)

            – Waqas Khokhar
            Mar 27 at 19:45











          • edited, try that. :)

            – Paul Hodges
            Apr 1 at 14:03











          • Hm. Previous edit didn't take. Did it again.

            – Paul Hodges
            Apr 2 at 14:21
















          Many thanks, the above command combine the libraries like this: cmdtrunk /media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,/media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz, But it misses the starting command: HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U Is it possible to sort it out? and make this command executable

          – Waqas Khokhar
          Mar 10 at 21:00






          Many thanks, the above command combine the libraries like this: cmdtrunk /media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460433.fastq.bz2_trimmed.fq.gz,/media/waqas/Seagate Backup Plus Drive/Analysis/data/1547_2015/Accessions/Alst-1_6989/transcriptome/fastq/trim/SRR3460434.fastq.bz2_trimmed.fq.gz, But it misses the starting command: HISAT/hisat2-2.1.0/hisat2 --p 8 --min-intronlen 60 --max-intronlen 6000 --dta -x Hisat2_index/arabidopsis -U Is it possible to sort it out? and make this command executable

          – Waqas Khokhar
          Mar 10 at 21:00





          1




          1





          Two major things - 1) I didn't put a $ on my var (mea culpa) and 2) you have embedded spaces in your structure. I edited for that. As a rule, I avoid spaces in my filenames like the plague it is, but I totally understand that people don't always get to choose. Tell me what blows up this time. :)

          – Paul Hodges
          Mar 11 at 13:41





          Two major things - 1) I didn't put a $ on my var (mea culpa) and 2) you have embedded spaces in your structure. I edited for that. As a rule, I avoid spaces in my filenames like the plague it is, but I totally understand that people don't always get to choose. Tell me what blows up this time. :)

          – Paul Hodges
          Mar 11 at 13:41













          (stackoverflow.com/users/8656552/paul-hodges), is it possible to remove comma from the end of last joined fastq file. Means I want files joined like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz) not like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz,)

          – Waqas Khokhar
          Mar 27 at 19:45





          (stackoverflow.com/users/8656552/paul-hodges), is it possible to remove comma from the end of last joined fastq file. Means I want files joined like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz) not like this (SRR3460433.fastq.bz2_trimmed.fq.gz,SRR3460434.fastq.bz2_trimmed.fq.gz,SRR3460435.fastq.bz2_trimmed.fq.gz,)

          – Waqas Khokhar
          Mar 27 at 19:45













          edited, try that. :)

          – Paul Hodges
          Apr 1 at 14:03





          edited, try that. :)

          – Paul Hodges
          Apr 1 at 14:03













          Hm. Previous edit didn't take. Did it again.

          – Paul Hodges
          Apr 2 at 14:21





          Hm. Previous edit didn't take. Did it again.

          – Paul Hodges
          Apr 2 at 14:21



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55068476%2fcombine-commands-using-loop%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко