-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNAseq_Process_interactive.sh
153 lines (126 loc) · 4.22 KB
/
RNAseq_Process_interactive.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
help(){
cat << EOF
Description:
This mini tool can be used to process clean RNA-seq data and produce bam, bigwig, bedgraph files.
CAUTION: THE INPUT DATA MUST BE CLEANED!!!
Required tools:
- STAR
- bedtools
- samtools
- featureCounts
Usage:
RNAseq_Process -1 <r1.fq> -2 <r2.fq> -r <ref> -g <gtf> -b <bed> -n <processers> -p <prefix> -o <output>
Options:
-1 the path of read1 fastq, can't be gzip. [PATH]
-2 the path of read1 fastq, can't be gzip. [PATH]
-r the ref genome for STAR to do reads alignments. [PATH]
-g the GTF annotation file for reads summary. [PATH]
-b the genome annotation bed file used for determine library type. [PATH]
-n the number of processers to perform this task. [NUM]
-p the prefix of output file. [CHAR]
-o the output dir for this task, can be created automatically. [CHAR]
Owner:
Kunming Shui, [email protected], Nanjing University.
Last Modified:
2022-07-18
EOF
}
if [ $# -eq 0 ] || [ $1 = "-h" ] || [ $1 = "--help" ]
then
help
exit 1
fi
echo "=================== Begin Analysis at $(date) ==================="
while getopts "1:2:r:g:b:n:p:o:" option
do
case $option in
1) read1=$OPTARG;;
2) read2=$OPTARG;;
r) ref=$OPTARG;;
g) gtf=$OPTARG;;
b) bed=$OPTARG;;
n) num=$OPTARG;;
p) prefix=$OPTARG;;
o) out=$OPTARG;;
esac
done
echo "=================== Reads Alignment with STAR ==================="
if [ -d $out ]
then
echo "$out is exiting."
else
mkdir -p $out
fi
#data check
echo "The read1 file is $read1"
echo "The read2 file is $read2"
STAR --runThreadN $num \
--genomeDir $ref \
--readFilesIn $read1 $read2 \
--outSAMtype BAM SortedByCoordinate \
--outBAMsortingThreadN $[ $num/2 ] \
--outFileNamePrefix $out/$prefix
echo "=================== Filter out low quality alignments ==================="
samtools view -q 255 -b -@ $num -o $out/$prefix.highquality.bam $out/${prefix}Ali*.bam
echo "=================== Determine the library type ==================="
class=`infer_experiment.py -i $out/$prefix.highquality.bam -r $bed`
echo $class
echo "Here, you should determine the library type by yourself..."
echo "if the number after '1++,1--,2+-,2-+' is larger than the number after '1+-,1-+,2++,2--', you should enter S."
echo "if the number after '1++,1--,2+-,2-+' is smaller than the number after '1+-,1-+,2++,2--', you should enter R."
read -p "enter S or R:" library
if [ $library = "S" ]
then
echo "Your RNA-seq library is stranded..."
else
echo "Your RNA-seq library is reverse stranded..."
fi
cd $out
samtools index $prefix.highquality.bam
samtools view -f 99 -b -@ $num -o $prefix.r1.fwd.bam $prefix.highquality.bam
samtools view -f 163 -b -@ $num -o $prefix.r2.fwd.bam $prefix.highquality.bam
samtools view -f 147 -b -@ $num -o $prefix.r2.rev.bam $prefix.highquality.bam
samtools view -f 83 -b -@ $num -o $prefix.r1.rev.bam $prefix.highquality.bam
if [ $library = "S" ]
then
samtools merge -@ $num tmp.forward.bam $prefix.r1.fwd.bam $prefix.r2.rev.bam
samtools merge -@ $num tmp.reverse.bam $prefix.r1.rev.bam $prefix.r2.fwd.bam
else
samtools merge -@ $num tmp.forward.bam $prefix.r1.rev.bam $prefix.r2.fwd.bam
samtools merge -@ $num tmp.reverse.bam $prefix.r1.fwd.bam $prefix.r2.rev.bam
fi
echo "=================== Perform reads summary with featureCounts ==================="
if [ $library = "S" ]
then
type=1
else
type=2
fi
mkdir featureCounts
featureCounts -a $gtf \
-o featureCounts/${prefix}.txt \
-t exon \
-g gene_id \
-s $type \
-p \
--countReadPairs \
-B \
-C \
-T $num $prefix.highquality.bam
echo "=================== Produce bedgraph, bigwig files ==================="
samtools sort -@ $num -o $prefix.fwd.bam tmp.forward.bam
samtools sort -@ $num -o $prefix.rev.bam tmp.reverse.bam
rm tmp.forward.bam tmp.reverse.bam
samtools index $prefix.fwd.bam
samtools index $prefix.rev.bam
#bedgraph file
genomeCoverageBed -bga -ibam $prefix.fwd.bam -split > $prefix.fwd.bedgraph
genomeCoverageBed -bga -ibam $prefix.rev.bam -split > $prefix.rev.bedgraph
#bigwig file
bamCoverage -b $prefix.fwd.bam -o $prefix.fwd.bigwig -bs 10 --normalizeUsing CPM -p $num
bamCoverage -b $prefix.rev.bam -o $prefix.rev.bigwig -bs 10 --normalizeUsing CPM -p $num
echo $class >> log.txt
echo $library >> log.txt
cd -
echo "=================== Finished at $(date) ==================="