forked from albertwcheng/RNASeqMappingScripts3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptureRunScripturAsSeparateSamples.sh
executable file
·120 lines (79 loc) · 3.25 KB
/
scriptureRunScripturAsSeparateSamples.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
#!/bin/bash
if [ $# -lt 3 ]; then
echo $0 paired chromList chromFaDir
exit
fi
paired=$1
chromList=$2
chromFaDir=$3
#load the chrom list
#/lab/jaenisch_albert/genomes/hg18/hg18_nr.sizes
#or
#/lab/jaenisch_albert/genomes/mm9/mm9_nr.sizes
#bsub bash scriptureRunScripture.sh 1 /lab/jaenisch_albert/genomes/mm9/mm9_nr.sizes /lab/jaenisch_albert/genomes/mm9/fa/byChr/
chroms=( `cut -f1 $chromList` )
echo There were ${#chroms[@]} chromosomes $chroms loaded from $chromList
scriptDir=`pwd`
cd ..
rootDir=`pwd`
tophatOutputDir=${rootDir}/tophatOutput
if [[ $paired == 1 ]]; then
scriptureOutputDir=${rootDir}/scriptureOutput_paired
else
scriptureOutputDir=${rootDir}/scriptureOutput
fi
#### old version ####
#tmpdir=$scriptureOutputDir/tmp
#if [ ! -e tmpdir ]; then
# mkdir $tmpdir
#fi
############
#concatenate all alignment files
#cat $scriptureOutputDir/*/sorted*.sam > $scriptureOutputDir/all_alignments.sam ###CHANGE BACK###CHANGE BACK###CHANGE BACK###CHANGE BACK###CHANGE BACK###CHANGE BACK
cd $scriptureOutputDir
for cellspecificalignmentfolder in *; do
if [ ! -e $cellspecificalignmentfolder/sorted*.sam ]; then
continue
fi
cd $cellspecificalignmentfolder
if [[ $paired == 1 ]]; then
cellspecificalignment=mergedpair.sam
cat sorted.1.sam sorted.2.sam > $cellspecificalignment
else
cellspecificalignment=sorted.sam
fi
#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
#use SamTools for BAM instead
echo "convert paired.sam to paired.bam"
samtools view -b -S -t $chromList -o paired.bam paired.sam
echo "sort paired.bam as paired.sorted.bam"
samtools sort paired.bam paired.sorted
echo "index paired.sorted.bam as ${pref}.sorted.bam.bai"
samtools index paired.sorted.bam
#now we have paired.sorted.bam and 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 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