Last active
August 2, 2023 05:05
-
-
Save azmigueldario/eb4f11d9ead13a9e38c0200db29b21c2 to your computer and use it in GitHub Desktop.
Use bash to create a csv file as samplesheet for nextflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add headers | |
echo "sample,read1,read2" > input_samplesheet.csv | |
for read1 in $(ls path/to/directories{1,2,3}/fastq/*_1.{fastq.gz,fq,fq.gz}); | |
do | |
# get the basename of file and remove suffix | |
sample_id=$(echo $read1 | xargs -n 1 basename -s '_1.fastq.gz') | |
# replace string '_1' for '_2' | |
read2="${read1/_1/_2}" | |
# write in a new line for each sample | |
echo $sample_id,$read1,$read2 >> input_samplesheet.csv | |
done | |
# with tabs | |
echo "sample,read1,read2" > input_samplesheet.csv | |
for read1 in $(ls path/to/directories{1,2,3}/fastq/*_1.{fastq.gz,fq,fq.gz}); | |
do | |
# get the basename of file and remove suffix | |
sample_id=$(echo $read1 | xargs -n 1 basename -s '_1.fastq.gz') | |
# replace string '_1' for '_2' | |
read2="${read1/_1/_2}" | |
# write in a new line for each sample | |
echo -e "$sample_id\t$read1\t$read2" >> input_samplesheet.csv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment