Running MegaHit using while loop doesnot creat separate dir with file names.
0
0
Entering edit mode
4 months ago

I have files with file names

SK_1-forward_paired.fq.gz    
SK_2-forward_paired.fq.gz     
SK_1-forward_unpaired.fq.gz    
SK_2-forward_unpaired.fq.gz        

So i created a file with filenames

SK_1   
SK_2     
SK_3    
SK_4    
SK_5    
SK_6    
SK_7     
SK_8    
SK_9  

for 9 different files

And a while loop script

#!/bin/bash    

#sh megahit.sh filenames.txt Path    


file="$1";    
path="$2";    
while read filename     
do
    #mkdir $filename     
    /opt/apps/MEGAHIT-1.2.9-Linux-x86_64-static/bin/megahit -1 $path/"$filename"-forward_paired.fq.gz -2 $path/"$filename"-reverse_paired.fq.gz   -r   $path/"$filename"-forward_unpaired.fq.gz, $path/"$filename"-reverse_unpaired.fq.gz -t 10  --out-dir megahit/$filename --out-prefix $filename  --keep-tmp-files      

done < $file  

But it creates default output folder megahit_out.

MEGAHIT • 440 views
ADD COMMENT
0
Entering edit mode

Please always keep the code sample. Add echo wherever possible. Naming conventions in example files is confusing IMO. Please let forum users know that you have mixed libraries (paired end and single end). In general, SE files belong to another samples.

ADD REPLY
0
Entering edit mode

These files are output of Trimmomatic and for each PE read it generates 4 files out of which 2 are PE and the other 2 are SE reads. All these files are input for megahit with options -1 , -2 and -r .
-1 and -2 for PE forward and reverse reads respectively and -r for SE forward and reverse unpaired reads.

ADD REPLY
1
Entering edit mode

Since $file, $1, $2 are not clear to me, I have created some files in a test directory and assumption is that all samples have "forward_paired" reads and Assumption is that file naming format is identical for all the samples as given below. Following is the example code:

input:

tree .
.
└── test
    ├── SK_1-forward_paired.fq.gz
    ├── SK_1-forward_unpaired.fq.gz
    ├── SK_1-reverse_paired.fq.gz
    ├── SK_1-reverse_unpaired.fq.gz
    ├── SK_2-forward_paired.fq.gz
    ├── SK_2-forward_unpaired.fq.gz
    ├── SK_2-reverse_paired.fq.gz
    └── SK_2-reverse_unpaired.fq.gz

1 directory, 8 files

output dry run:

$ find * -type f -name "*forward_paired*" | while read line ; do p=$(basename $line -forward_paired.fq.gz)  r=$(dirname $line) ; echo mkdir -p $r/megahit/$p; echo /opt/apps/MEGAHIT-1.2.9-Linux-x86_64-static/bin/megahit -1 $p-forward_paired.fq.gz -2 $p-reverse_paired.fq.gz   -r   $p-forward_unpaired.fq.gz, $p-reverse_unpaired.fq.gz -t 10  --out-dir $r/megahit/$p --out-prefix $p --keep-tmp-files ; done


mkdir -p test/megahit/SK_2
/opt/apps/MEGAHIT-1.2.9-Linux-x86_64-static/bin/megahit -1 SK_2-forward_paired.fq.gz -2 SK_2-reverse_paired.fq.gz -r SK_2-forward_unpaired.fq.gz, SK_2-reverse_unpaired.fq.gz -t 10 --out-dir test/megahit/SK_2 --out-prefix SK_2 --keep-tmp-files
mkdir -p test/megahit/SK_1
/opt/apps/MEGAHIT-1.2.9-Linux-x86_64-static/bin/megahit -1 SK_1-forward_paired.fq.gz -2 SK_1-reverse_paired.fq.gz -r SK_1-forward_unpaired.fq.gz, SK_1-reverse_unpaired.fq.gz -t 10 --out-dir test/megahit/SK_1 --out-prefix SK_1 --keep-tmp-files

This would create a megahit directory and within megahit directory, it would create sample specific directory.

ADD REPLY
0
Entering edit mode

Thank you for your valuable time and suggestion .It worked

ADD REPLY

Login before adding your answer.

Traffic: 1839 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6