-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscriptureRunScripturAsGroups.sh
executable file
·147 lines (99 loc) · 3.87 KB
/
scriptureRunScripturAsGroups.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
#!/bin/bash
if [ $# -lt 5 ]; then
echo $0 paired chromList chromFaDir outputPrefixRelToRoot groupFileRelToRoot
exit
fi
paired=$1
chromList=$2
chromFaDir=$3
outputPrefix=$4
groupFile=$5
#load the chrom list
#/lab/jaenisch_albert/genomes/hg18/hg18_nr.sizes
#or
#/lab/jaenisch_albert/genomes/mm9/mm9_nr.sizes
#bsub bash scriptureRunScripturAsGroups.sh 0 /lab/jaenisch_albert/genomes/mm9/mm9_nr.sizes /lab/jaenisch_albert/genomes/mm9/fa/byChr/ scriptureOutput_byCellTypes groups/cellTypes.grp
:<<'COMMENT'
format:
<groupName>=<FolderName1>,...
groups=<groupName1>,...
COMMENT
chroms=( `cut -f1 $chromList` )
echo There were ${#chroms[@]} chromosomes $chroms loaded from $chromList
scriptDir=`pwd`
cd ..
source $groupFile
rootDir=`pwd`
tophatOutputDir=${rootDir}/tophatOutput
if [ -e $outputPrefix ]; then
rm $outputPrefix #clean up everything!
fi
mkdir ${outputPrefix}
cd $outputPrefix
outputPrefix=`pwd`
cd $rootDir
if [[ $paired == 1 ]]; then
scriptureOutputDir=${rootDir}/scriptureOutput_paired
else
scriptureOutputDir=${rootDir}/scriptureOutput
fi
#parse the groups variable into an array
saveIFS=$IFS
IFS=`echo -en ","`
declare -a groups=($groups)
IFS=$saveIFS
#for each group
for thisGroup in ${groups[@]}; do
#make output folder for this group
thisGroupDir=${outputPrefix}/${thisGroup}
mkdir $thisGroupDir
vname=${thisGroup}
filelist=${!vname}
saveIFS=$IFS
IFS=`echo -en ","`
declare -a filelist=($filelist)
IFS=$saveIFS
#concatenate all alignment files
for perFolder in ${filelist[@]}; do
cat $scriptureOutputDir/$perFolder/sorted*.sam >> ${thisGroupDir}/all_alignments.sam
done
cd $thisGroupDir
cellspecificalignment=all_alignments.sam
#use SamTools for BAM instead
pref=${cellspecificalignment/.sam/}
echo convert $cellspecificalignment to ${pref}.bam
samtools view -b -S -t $chromList -o ${pref}.bam $cellspecificalignment
echo "sort ${pref}.bam as ${pref}.sorted.bam"
samtools sort ${pref}.bam ${pref}.sorted
echo "index ${pref}.sorted.bam as ${pref}.sorted.bam.bai"
samtools index ${pref}.sorted.bam
#should now have ${pref}.sorted.bam and ${pref}.sorted.bam.bai
if [[ $paired == 1 ]]; then
#combined paired end alignment files
#cat $scriptureOutputDir/*/paired.sam > all_alignments.paired.sam ###CHANGE BACK###CHANGE BACK###CHANGE BACK###CHANGE BACK###CHANGE BACK###CHANGE BACK###CHANGE BACK
for perFolder in ${filelist[@]}; do
cat $scriptureOutputDir/$perFolder/paired.sam >> ${thisGroupDir}/all_alignments.paired.sam
done
#use SamTools for BAM instead
echo "convert ${pref}.paired.sam to ${pref}.paired.bam"
samtools view -b -S -t $chromList -o ${pref}.paired.bam ${pref}.paired.sam
echo "sort ${pref}.paired.bam as ${pref}.paired.sorted.bam"
samtools sort ${pref}.paired.bam ${pref}.paired.sorted
echo "index ${pref}.paired.sorted.bam as ${pref}.sorted.bam.bai"
samtools index ${pref}.paired.sorted.bam
#now we have ${pref}.paired.sorted.bam and ${pref}.paired.sorted.bam.bai
fi
#now we can run scripture
#do this for each chromosome
for chrom in ${chroms[@]}; do
echo submitting scripture segment task for chrom $chrom to cluster
if [[ $paired == 1 ]]; then
#bsub scripture -alignment all_alignments.sorted.sam -out $chrom.scriptureESTest.segments -sizeFile $chromList -chr $chrom -chrSequence $chromFaDir/${chrom}.fa -pairedEnd all_alignments.paired.sorted.sam
bsub scripture -alignment ${pref}.sorted.bam -out $chrom.scriptureESTest.segments -sizeFile $chromList -chr $chrom -chrSequence $chromFaDir/${chrom}.fa -pairedEnd ${pref}.paired.sorted.bam
else
#bsub scripture -alignment all_alignments.sorted.sam -out $chrom.scriptureESTest.segments -sizeFile $chromList -chr $chrom -chrSequence $chromFaDir/${chrom}.fa
bsub scripture -alignment ${pref}.sorted.bam -out $chrom.scriptureESTest.segments -sizeFile $chromList -chr $chrom -chrSequence $chromFaDir/${chrom}.fa
fi
done
cd ..
done