-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathannotate_module_v2.bash
More file actions
executable file
·182 lines (111 loc) · 3.58 KB
/
Copy pathannotate_module_v2.bash
File metadata and controls
executable file
·182 lines (111 loc) · 3.58 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
module purge
module load compiler/java/1.8.0_65-oracle
module load samtools/1.2-gcc5.2.0
module load tophat/2.1.1
module load bowtie2/2.3.2-gcc5.2.0
module load cufflinks/2.2.1
module load HTSeq/0.9.0
while getopts ha:b:p:g: option
do
case "${option}"
in
h) echo -ne "Usage:\$ bash $0 -a annotate-method -b bam_directory -p sample_phenotype -g reference_gtf\n"
echo -ne "Options\n-a: Method of annotation with values Cufflinks or Reference (default: Reference)\n"
echo -ne "-b: Input bam directory full-path(default: current working directory)\n"
echo -ne "-p: Input sample phynotype file in directory full-path(default: current working directory)\n"
echo -ne "-g: Input Reference gtf file full-path(default: current working directory)\n"
exit 1;;
a) annot=${OPTARG};;
b) bamdir=${OPTARG};;
p) sm_phtype=${OPTARG};;
g) refseq_gtf=${OPTARG};;
esac
done
if [ -z "$annot" ]
then
annot="Reference"
fi
if [ -z "$bamdir" ]
then
echo "No gtf path specified. Looking in current $(pwd)"
dir=$(pwd)
bam=$(ls ${dir}/*.bam)
fi
if [ -z "$sm_phtype" ]
then
echo "No gtf path specified. Looking in current $(pwd)"
dir=$(pwd)
sm_phtype=${dir}/sample_phenotype.txt
fi
if [ -z "$refseq_gtf" ]
then
echo "No gtf path specified. Looking in current $(pwd)"
dir=$(pwd)
refseq_gtf=$(ls ${dir}/*.gtf)
fi
#################################################
if [ $annot = "Cufflinks" ]
then
####### Assembly #################################
### cufflinks ###################
echo "Running cufflinks..."
for file in $(ls ${bamdir}/*.bam)
do
sample=$(basename $file .bam)
echo "Sample: $readname"
cufflinks_out=${readname}_cufflinks
if [ $(samtools view -c -f 1 $file) -gt 0 ]
then
cufflinks -p 1 -g $refseq_gtf -o $cufflinks_out --library-type fr-firststrand $file 2> ${cufflinks_out}.log &
else
cufflinks -p 1 -g $refseq_gtf -o $cufflinks_out $file 2> ${cufflinks_out}.log &
fi
echo "$cufflinks_out/transcripts.gtf" >> assembly_list.txt
done
wait
#### cuffmerge ###############################
cuffmerge_out=cuffmerge_output
cuffmerge -s ${index}.fa -g $refseq_gtf -p 1 -o $cuffmerge_out assembly_list.txt
input_gtf=${cuffmerge_out}/merged.gtf
#####################################################
else
input_gtf=$refseq_gtf
fi
#### HTSeq counts #########################
out_count=HTSeq_count
mkdir -p $out_count
#### Checking and sorting bam files for paired-end reads
echo "Checking and sorting bam files for paired-end reads"
for file in $(ls ${bamdir}/*.bam)
do
if [ $(samtools view -c -f 1 $file) -gt 0 ]
then
mkdir -p name_sorted
sample=$(basename $file .bam)
echo "Sample: $sample"
# To run HTSeq on paired end sort bam file by name
samtools sort -n $file ${bamdir}/name_sorted/${sample}.name_sorted &
fi
done
wait
##### Running HTSeq
echo "HTSeq count"
for file in $(ls ${bamdir}/*.bam)
do
sample=$(basename $file .bam)
echo "Sample: $sample"
if [ $(samtools view -c -f 1 $file) -gt 0 ]
then
htseq-count -f bam --stranded=no ${bamdir}/name_sorted/${sample}.name_sorted.bam $input_gtf > ${out_count}/${sample}_count.no_strand.txt &
else
htseq-count -f bam --stranded=no $file $input_gtf > ${out_count}/${sample}_count.no_strand.txt &
fi
done
wait
###### Combining files
cd $out_count
echo "gene_id" > gene_id; cat *.txt | cut -f 1 | sort -u >> gene_id
while read line; do sm=$(echo "$line" | cut -f 1); echo "$sm" > ${sm}_count; cat ${sm}*.txt | sort -k 1,1 | cut -f 2 >> ${sm}_count; done < $sm_phtype
paste gene_id *_count > htseq_count.txt
############################################################