2
$\begingroup$

This question was also asked on Biostars

I have two samples where the sequencing was done on 3-lanes paired end reads. The two samples are A44943_1 and A44944_1.

I would like to generate a for in loop to merge the R1 files of sample A44943_1 from the 3-lanes, and then do the same for R2 files of this sample, then I want to merge R1 files of sample A44944_1 from the 3-lanes and then do the same for R2 files of this sample. So I thought about for in loop. My fastq files looks like:

R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_L001_R1_trimmed.fastq
R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_L001_R2_trimmed.fastq
R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_L002_R1_trimmed.fastq
R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_L002_R2_trimmed.fastq
R0480-S0001_182602S1P1_A44943_1_H7YKTDRXY_CGCAACTA-GAATCCGA_L003_R1_trimmed.fastq
R0480-S0001_182602S1P1_A44943_1_H7YKTDRXY_CGCAACTA-GAATCCGA_L003_R2_trimmed.fastq
R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_L001_R1_trimmed.fastq
R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_L001_R2_trimmed.fastq
R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_L002_R1_trimmed.fastq
R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_L002_R2_trimmed.fastq
R0480-S0002_182602S1P2_A44944_1_H7YKTDRXY_CACAGACT-TGGTACAG_L003_R1_trimmed.fastq
R0480-S0002_182602S1P2_A44944_1_H7YKTDRXY_CACAGACT-TGGTACAG_L003_R2_trimmed.fastq

Could you advise me on a for in loop to do this task?

Thanks

$\endgroup$
0

1 Answer 1

5
$\begingroup$

You can certainly use a for loop for this if desired, but an easier method is to use the cat command - something like this:

cat R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_L00[123]_R1_trimmed.fastq > R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_R1_trimmed.fastq
cat R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_L00[123]_R2_trimmed.fastq > R0480-S0001_182602S1P1_A44943_1_H77YFDRXY_CGCAACTA-GAATCCGA_R2_trimmed.fastq
cat R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_L00[123]_R1_trimmed.fastq > R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_R1_trimmed.fastq
cat R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_L00[123]_R2_trimmed.fastq > R0480-S0002_182602S1P2_A44944_1_H77YFDRXY_CACAGACT-TGGTACAG_R2_trimmed.fastq
$\endgroup$
3
  • 2
    $\begingroup$ Holy s**t, have I been missing out all along? TIL, thank you @Scot! $\endgroup$
    – Ram RS
    Aug 22, 2023 at 15:41
  • 1
    $\begingroup$ I can relate, @RamRS! I love to learn a new trick... and bash is full of them. :) $\endgroup$
    – Scot
    Aug 22, 2023 at 17:48
  • $\begingroup$ This is news to me too so I had to look this one up. Evidently it's part of bash's "pathname expansion" feature set, just like * (and so, distinct from "brace expansion" in that it depends on what files are present; so like, cat [123].txt expands to cat 1.txt 2.txt 3.txt if those are present, but is just cat [123].txt if not, versus {1..3}.txt which always expands). Very handy, thanks Scot. $\endgroup$
    – Jesse
    Aug 25, 2023 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.