-
Notifications
You must be signed in to change notification settings - Fork 1
/
mergeBamFilesAsGroups.sh
executable file
·74 lines (50 loc) · 1.49 KB
/
mergeBamFilesAsGroups.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
#!/bin/bash
if [ $# -lt 3 ]; then
echo $0 sourceParent outputParent groupFileRelToRoot
exit
fi
sourceParent=$1
outputPrefix=$2
groupFile=$3
#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
scriptDir=`pwd`
cd ..
source $groupFile
rootDir=`pwd`
tophatOutputDir=`abspath.py $sourceParent`
#if [ -e $outputPrefix ]; then
# rm $outputPrefix #clean up everything!
#fi
mkdir.py ${outputPrefix}
cd $outputPrefix
outputPrefix=`pwd`
cd $rootDir
#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
vname=${thisGroup}
filelist=${!vname}
filelistArray=(`echo $filelist | tr "," " "`)
for((i=0;i<${#filelistArray[@]};i++)); do
filelistArray[$i]="$tophatOutputDir/${filelistArray[$i]}/accepted_hits.sorted.bam"
done
mkdir.py $outputPrefix/$thisGroup
cmd="samtools merge $outputPrefix/$thisGroup/accepted_hits.sorted.bam ${filelistArray[@]}"
echo $cmd > $outputPrefix/merge_for_$thisGroup.sh
cmd="samtools index $outputPrefix/$thisGroup/accepted_hits.sorted.bam"
bsub bash $outputPrefix/merge_for_$thisGroup.sh
#samtools merge $tophatOutputDir
done