-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxgetSRAacc
executable file
·102 lines (94 loc) · 2.49 KB
/
xgetSRAacc
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
if [ $# -eq 0 ]; then
echo ""
echo "Usage: xgetSRAacc accession <'fasterq-dump options'>"
echo ""
echo "Examples:"
echo " xgetSRAcc SRR1270128"
echo " (will retrieve SRR1270128)"
echo ""
echo " xgetSRAcc SRR1270128 '-t /dev/shm'"
echo " (will retrieve SRR1270128 using /dev/shm as tmp directory)"
echo ""
echo " xgetSRAcc SRR1270128_SRR1270129_SRR1270130 '-e 8 -t /dev/shm'"
echo " (will retrieve SRR1270128, SRR1270129, and SRR1270130"
echo " using 8 processors and then combine the data to files"
echo " SRR1270128_SRR1270129_SRR1270130*.fastq using /dev/shm as"
echo " tmp directory)"
echo ""
exit
fi
SAMPLE=$1
FASTERQ_DUMP_OPTIONS=$2
echo ""
echo "Running xgetSRAcc ${SAMPLE} ${FASTERQ_DUMP_OPTIONS} ..."
echo ""
runs=${SAMPLE//_/ }
tmpdir=$(grep -o '\-t [^\S]*' <<< ${FASTERQ_DUMP_OPTIONS})
tmpdir=$(grep -o ' [^\S]*' <<< ${tmpdir})
if [ -z "${tmpdir}" ]; then
tmpdir=./
fi
echo "tmp directory set to: ${tmpdir}"
echo ""
for run in ${runs}; do
echo "... attempting to get ${run} from NCBI SRA"
n=1
until [ $n -ge 8 ]; do
echo ""
echo "... attempt $n: if successful, ${run}*.fastq will have been deposited."
echo ""
fasterq-dump ${FASTERQ_DUMP_OPTIONS} ${run} && break
touch ${tmpdir}/fasterq.tmp. && \rm -rf ${tmpdir}/fasterq.tmp.*
n=$((n+1))
sleep 30
done
if [ $n -eq 8 ]; then \
echo "Time to figure out a different way to download the data from NCBI."; \
echo "Or wait for better internet connection ..."; \
else
echo "... done"
fi
done
runa=( ${runs} )
if [ ${#runa[@]} -gt 1 ]; then
catcmd1="cat"
catcmd2="cat"
if [ -f ${run}_1.fastq ]; then
for run in ${runs}; do
catcmd1="${catcmd1} ${run}_1.fastq "
catcmd2="${catcmd2} ${run}_2.fastq "
done
catcmd1="${catcmd1} > ${SAMPLE}_1.fastq"
catcmd2="${catcmd2} > ${SAMPLE}_2.fastq"
echo ""
echo ${catcmd1}
eval ${catcmd1}
echo ${catcmd2}
eval ${catcmd2}
elif [ -f ${run}.fastq ]; then
for run in ${runs}; do
catcmd1="${catcmd1} ${run}.fastq"
done
catcmd1="${catcmd1} > ${SAMPLE}.fastq"
echo ""
echo ${catcmd1}
eval ${catcmd1}
else
echo ""
echo "Error: neither ${run}.fastq nor ${run}_1.fastq found."
echo "Please check."
echo ""
exit
fi
if [ -f ${run}_1.fastq ]; then
for run in ${runs}; do
\rm ${run}_1.fastq ${run}_2.fastq
done
else
for run in ${runs}; do
\rm ${run}.fastq
done
fi
fi