-
Notifications
You must be signed in to change notification settings - Fork 1
/
scripturePrepareJobOnTophatFolder.sh
80 lines (49 loc) · 1.73 KB
/
scripturePrepareJobOnTophatFolder.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
#!/bin/bash
if [ $# -lt 2 ]; then
echo $0 sampleName paired [ 1 or 0 ]
exit
fi
sampleName=$1
paired=$2
targetSam="accepted_hits.sam"
#according to scripture manual and examples
scriptDir=`pwd`
cd ..
rootDir=`pwd`
if [[ $paired == 1 ]]; then
tophatOutputDir=${rootDir}/tophatOutput_paired
scriptureOutputDir=${rootDir}/scriptureOutput_paired
else
tophatOutputDir=${rootDir}/tophatOutput
scriptureOutputDir=${rootDir}/scriptureOutput
fi
if [ ! -e $scriptureOutputDir ]; then
mkdir $scriptureOutputDir
fi
#now sort individually
if [[ $paired == 1 ]]; then
sampleNameL=${sampleName}_1
sampleNameR=${sampleName}_2
thisScripturePath=${scriptureOutputDir}/${sampleName}_paired #path name to differentiate the unpaired ones
mkdir $thisScripturePath
target_sam1=${tophatOutputDir}/${sampleNameL}/${targetSam}
target_sam2=${tophatOutputDir}/${sampleNameR}/${targetSam}
#for the new tophat, need to convert back to sam file
if [ ! -e $target_sam1 ]; then
samtools view -h -o $target_sam1 ${target_sam1/.sam/}.bam
fi
if [ ! -e $target_sam2 ]; then
samtools view -h -o $target_sam2 ${target_sam2/.sam/}.bam
fi
#now remove @ and sort by readname
sed '1,2d' $target_sam1 | sort > ${thisScripturePath}/sorted.1.sam
sed '1,2d' $target_sam2 | sort > ${thisScripturePath}/sorted.2.sam
#run scripture makePairedFile task
scripture -task makePairedFile -pair1 ${thisScripturePath}/sorted.1.sam -pair2 ${thisScripturePath}/sorted.2.sam -out ${thisScripturePath}/paired.sam -sorted
else
#single end data only
thisScripturePath=${scriptureOutputDir}/${sampleName}
mkdir $thisScripturePath
sed '1,2d' ${tophatOutputDir}/${sampleName}/${targetSam} | sort > ${thisScripturePath}/sorted.sam
#cannot run makePairedFile task
fi