-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.sh
executable file
·69 lines (56 loc) · 1.45 KB
/
convert.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/bash
# load modules
module load sra-tools
module load samtools
help(){
echo "Usage: use this script to convert SRA files to fastq or bam"
echo
echo "Options :"
echo " -b : convert to bam file. "
echo " -q : convert to fastq file. "
echo " -h : show this help message and exit"
echo
echo " dont forget to change the output directory inside the script"
echo "if not the output will be ./"
exit 1
}
# change your own path here
destination="./"
conversion_type=""
while getopts "bq:h" op; do
case $op in
q)
conversion_type="fastq"
;;
b)
conversion_type="bam"
;;
h)
help
;;
\?)
echo "wrong operator: -$OPTARG" >&2
help
;;
esac
done
if [ -z "$conversion_type" ]; then
echo " you need to specify a conversion option: -q or -b"
help
fi
find . -name "*.sra" -exec mv {} $destination \;
for sra_file in $destination*.sra; do
echo "running $sra_file..."
base_name=$(basename "$sra_file" .sra)
case $conversion_type in
fastq)
echo "conversion of $sra_file in fastq...."
fastq-dump.3 --ngc a.ngc "$sra_file"
;;
bam)
echo "conversion of $sra_file in bam....."
sam_dump.3 --ngc a.ngc $sra_file | samtools view -bS - > "${base_name}.bam"
;;
esac
done
echo "treatment's over"