Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lkomo
    Junior Member
    • Apr 2015
    • 4

    #1

    nested for loop to concatenate fastq files

    My pooled PE RNA-Seq data was demultiplexed by the sequencing facility, so the data I receive is a directory with sub directories for each sample that contain the R1 and R2 fastq files for each lane (i.e., the main directory "FISH_RNA_SEQ" has 96 folders, each labeled by sample-like "SpA.Treatment1.Rep1", etc.). If I am in a sub-directory for a particular sample, I can concatenate across lanes and write to a file in a new directory so I have two files for each sample (R1/R2) using this for loop:

    for SUFFIX in R1_001.fastq R2_001.fastq
    do
    cat *L001_$SUFFIX *L002_$SUFFIX *L003_$SUFFIX > ../test.cat.DDIG/samplename_cat_$SUFFIX
    done

    However, this requires me to manually run this for each of the 96 samples, going into the sub-directory and typing in the desired output name. Since I will have to repeat this in the future, does anyone have suggestions about how to use a nested for loop (or other way) to do this automatically/iteratively do this from the main directory for all subdirectories, naming the output files with by the subdirectory (i.e. sample name)?

    Working from the main directory, I was testing something like:
    for dir in *; do
    (for SUFFIX in R1_001.fastq R2_001.fastq
    do
    cat *L001_$SUFFIX *L002_$SUFFIX *L003_$SUFFIX > ../test.cat.DDIG/test_cat_$SUFFIX
    done)

    But this doesn't seem to work, and it doesn't solve the problem of naming the output files according to the sample names. Any suggestions appreciated!
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    Do you just want to use the directory name (e.g., SpA.Treatment1.Rep1) as the prefix, or some variant of whatever the file names are?

    Comment

    • lkomo
      Junior Member
      • Apr 2015
      • 4

      #3
      Yes, ideally the directory name would be the file name prefix, so for example a 'Sample1.treatment1.Rep1' directory would produce two output files like: 'Sample1.treatment1.Rep1_cat_R1.001.fastq' and 'Sample1.treatment1.Rep1_cat_R2.001.fastq'

      And then the same for all the other directories/samples...
      Thank you!

      Comment

      • dpryan
        Devon Ryan
        • Jul 2011
        • 3478

        #4
        Code:
        for dir in `find . -maxdepth 1 -mindepth 1 -type d -printf "%f\n"`
        do
            cd $dir
            cat *_L???_R1_*.fastq > $dir_R1.fastq
            cat *_L???_R2_*.fastq > $dir_R2.fastq
            cd ..
        done
        or something like that.

        Comment

        • lkomo
          Junior Member
          • Apr 2015
          • 4

          #5
          thank you! I think I see what each part does except the "%f\n"? my apologies if it's obvious-I'm still fairly new.

          Comment

          • dpryan
            Devon Ryan
            • Jul 2011
            • 3478

            #6
            That's just the formatting that the results should be returned in.

            Comment

            • lkomo
              Junior Member
              • Apr 2015
              • 4

              #7
              great, thank you so much for the help!

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
                by SEQadmin2



                CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

                Despite this, “CRISPR helped turn genome editing from a specialized technique into
                ...
                07-31-2026, 11:01 AM
              • SEQadmin2
                Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                by SEQadmin2


                Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                The systematic characterization of the human proteome has
                ...
                07-20-2026, 11:48 AM
              • SEQadmin2
                Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                by SEQadmin2



                Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                ...
                07-09-2026, 11:10 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, Today, 10:13 AM
              0 responses
              10 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-31-2026, 02:55 AM
              0 responses
              22 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-24-2026, 12:17 PM
              0 responses
              19 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-23-2026, 11:41 AM
              0 responses
              17 views
              0 reactions
              Last Post SEQadmin2  
              Working...