-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortmerna_script.sh
More file actions
43 lines (31 loc) · 1.91 KB
/
Copy pathsortmerna_script.sh
File metadata and controls
43 lines (31 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# this script will remove ribosomal RNA sequences
# use this echo command to know where your sortmerna is running from
echo "Using sortmerna from: $(which sortmerna)"
# use this echo command to load your start date. I intentionally do this for sortmerna because it takes a while, and it might be longer depending on the file size
# so when you run on screen, you want to be sure it is still running by simply checking the log file and seeing the date for the last sample
echo "Start time: $(date)"
mkdir my_sorted_samples
for sample in $(cat my_samples.txt); do
# run sortmerna first the normal way
# put the full part to the sortmerna database you are using in the path space below
sortmerna -ref /path_to_sortmerna_database/smr_v4.3_default_db.fasta -reads "$PWD/${sample}.fastq.gz" -num_alignments 1 -fastx -other -workdir "$PWD" -threads 8
# sortmerna output will come as a folder named out
#move the out folder to your individual file name so the output of the next file run won't override your last run
mv out "${sample}"
# then move the renamed folder into the over sorted folder
mv "${sample}" my_sorted_samples
# kvdb is another default sortmerna output, but it must always be purged before another file run, so purge it
rm -rf "$PWD/kvdb"
done
# when the initial sortmerna is done for all samples, you can go ahead to check the outputs (now renamed by sample prefix)
#inside each of the samples folders, you'll find three files: aligned.fq.gz, log, other.fq.gz
# what you need is the other.fq.gz file
#but all the folders will have this repetitive file naming system, so rename the other.fq.gz to your sample name and move it out
for x in my_sorted_samples/*/other.fq.gz; do
d=$(dirname "$x")
sample=$(basename "$d")
mv "$x" "${d}/${sample}_sorted.fastq.gz"
cp "${d}/${sample}_sorted.fastq.gz" my_sorted_samples/
done
echo "All samples finished at: $(date)"