-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathart_run.sh
executable file
·197 lines (186 loc) · 8.42 KB
/
art_run.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
module load bwa
ref=$(pwd)
REFERENCE=$2
OUTPUT_PREFIX=$1
SNP_RATE=$5
INDEL_RATE=$6
TRANSITION_TRANSVERSION_RATIO=2
CNV_RATE=$7
CNV_MIN_SIZE=$8
CNV_MAX_SIZE=$9
FOLD_COVERAGE=$3
SINGLE_OR_PAIRED=$4
READ_LENGTH="${10}"
PLOIDY="${11}"
SEED=$RANDOM
SUBCLONES="${12}"
GENOME="${13}"
sam="${14}"
SIMULATION_LOG_FILE=$ref/$OUTPUT_PREFIX/SIMULATION_IS_RUNNING.txt
M="-m 200"
if [[ "$SINGLE_OR_PAIRED" == "False" ]]; then
SINGLE_OR_PAIRED="-p"
else
unset SINGLE_OR_PAIRED
unset M
fi
#if the -s argument was used, then SINGLE_OR_PAIRED will be null. otherwise it will be -p. this way we can always supply SINGLE_OR_PAIRED to art.
mkdir -p $ref/$OUTPUT_PREFIX/normal
mkdir -p $ref/$OUTPUT_PREFIX/tumor
for i in `seq 1 $SUBCLONES`
do
mkdir -p $ref/$OUTPUT_PREFIX/tumor/subclone_$i
done
#make folders for each subclone file, within tumor
# print a starting message
timestamp(){ date +"%D %T";}
printf "SIMULATION STARTED AT `timestamp` WITH THE FOLLOWING PARAMETERS\n\n" > $SIMULATION_LOG_FILE
printf "SNP Rate: "$SNP_RATE"\n" >> $SIMULATION_LOG_FILE
printf "Indel Rate: "$INDEL_RATE"\n" >> $SIMULATION_LOG_FILE
printf "Transition/Transversion Ratio: "$TRANSITION_TRANSVERSION_RATIO"\n" >> $SIMULATION_LOG_FILE
printf "CNV Rate: "$CNV_RATE"\n" >> $SIMULATION_LOG_FILE
printf "CNV Minimum Size: "$CNV_MIN_SIZE"\n" >> $SIMULATION_LOG_FILE
printf "CNV Maximum Size: "$CNV_MAX_SIZE"\n" >> $SIMULATION_LOG_FILE
printf "Ploidy: "$PLOIDY"\n" >> $SIMULATION_LOG_FILE
printf "Subclones: "$SUBCLONES"\n" >> $SIMULATION_LOG_FILE
printf "Fold Coverage: "$FOLD_COVERAGE"\n" >> $SIMULATION_LOG_FILE
printf "Read Length: "$READ_LENGTH"\n\n" >> $SIMULATION_LOG_FILE
# creating and copying files
printf "Copying temporary files for normal reads ..\n" >> $SIMULATION_LOG_FILE
cp $ref/$REFERENCE /$ref/$OUTPUT_PREFIX/normal
if [[ $sam == True ]]; then
cp $ref/$GENOME /$ref/$OUTPUT_PREFIX
fi
#if -sam is used, we need an indexed copy of the original genome, within the output directory to align against.
printf "Copying temporary files for tumor reads ..\n\n" >> $SIMULATION_LOG_FILE
for i in `seq 1 $SUBCLONES`
do
cp $ref/$REFERENCE /$ref/$OUTPUT_PREFIX/tumor/subclone_$i
done
# generate normal reads
printf "Generating normal reads ..\n\n" >> $SIMULATION_LOG_FILE
cd $ref/
NORMAL_REFERENCE=$ref/$OUTPUT_PREFIX/normal/$REFERENCE
NORMAL_OUTPUT_PREFIX=$ref/$OUTPUT_PREFIX/normal/normal
./art_illumina -i $NORMAL_REFERENCE -rs $SEED $M -s 10 -l 100 $SINGLE_OR_PAIRED -f $FOLD_COVERAGE -o $NORMAL_OUTPUT_PREFIX >> $SIMULATION_LOG_FILE 2>&1
printf "Finished generating normal reads ..\n\n" >> $SIMULATION_LOG_FILE
# clean temporary files
cd $ref/$OUTPUT_PREFIX/normal
if [[ $sam == True ]]; then
bwa index $ref/$OUTPUT_PREFIX/$GENOME
if [[ "$SINGLE_OR_PAIRED" != "-p" ]]; then
bwa mem -t 2 -r "@RG\tID:Tum_Chr20\tSM:Tumor_Chr20" $ref/$OUTPUT_PREFIX/$GENOME $ref/$OUTPUT_PREFIX/normal/normal.fq > "normal.sam"
#align single end reads into SAM file
else
bwa mem -t 2 -r "@RG\tID:Tum_Chr20\tSM:Tumor_Chr20" $ref/$OUTPUT_PREFIX/$GENOME $ref/$OUTPUT_PREFIX/normal/normal1.fq $ref/$OUTPUT_PREFIX/normal/normal2.fq > "normal.sam"
#align paired end reads into sam file
fi
fi
#rm *.fa
# simulate tumor genome
for i in `seq 1 $SUBCLONES`
do
printf "Simulating tumor variations in subclone $i ..\n" >> $SIMULATION_LOG_FILE
printf "This step takes some time. \n\n" >> $SIMULATION_LOG_FILE 2>&1
cd /$ref/$OUTPUT_PREFIX/tumor/subclone_$i
if (( $PLOIDY == 3)); then
$ref/SInC/SInC_simulate -S $SNP_RATE -I $INDEL_RATE -p $CNV_RATE -l $CNV_MIN_SIZE -u $CNV_MAX_SIZE -t $TRANSITION_TRANSVERSION_RATIO $REFERENCE >> $SIMULATION_LOG_FILE
for entry in /$ref/$OUTPUT_PREFIX/tumor/subclone_$i/*
do
if [[ $entry == *"allele_1"* ]]; then
mv $entry 'allele_3.fa'
fi
if [[ $entry == *"allele_2"* ]]; then
rm $entry
fi
if [[ $entry == *"SNPs"* ]] && [[ $entry == *"_1.txt" ]]; then
mv $entry 'SNPs_3.txt'
fi
if [[ $entry == *"SNPs"* ]] && [[ $entry == *"_2.txt" ]]; then
rm $entry
fi
if [[ $entry == *"INDELs"* ]] && [[ $entry == *"_1.txt" ]]; then
mv $entry 'INDELs_3.txt'
fi
if [[ $entry == *"INDELs"* ]] && [[ $entry == *"_2.txt" ]]; then
rm $entry
fi
if [[ $entry == *"CNV"* ]] && [[ $entry == *"stdresults"* ]]; then
mv $entry 'CNV_stdresults_2.txt'
fi
if [[ $entry == *"CNV"* ]] && [[ $entry != *"stdresults"* ]]; then
mv $entry 'CNV_results_2.txt'
fi
done
printf "Measuring ploidy level .. Still simulating tumor variations in subclone $i ..\n\n" >> $SIMULATION_LOG_FILE
fi
$ref/SInC/SInC_simulate -S $SNP_RATE -I $INDEL_RATE -p $CNV_RATE -l $CNV_MIN_SIZE -u $CNV_MAX_SIZE -t $TRANSITION_TRANSVERSION_RATIO $REFERENCE >> $SIMULATION_LOG_FILE
for entry in $ref/$OUTPUT_PREFIX/tumor/subclone_$i/*
do
if [[ $entry == *"allele_1"* ]]; then
mv $entry 'allele_1.fa'
fi
if [[ $entry == *"allele_2"* ]]; then
mv $entry 'allele_2.fa'
fi
if [[ $entry == *"SNPs"* ]] && [[ $entry == *"_1.txt" ]]; then
mv $entry 'SNPs_1.txt'
fi
if [[ $entry == *"SNPs"* ]] && [[ $entry == *"_2.txt" ]]; then
mv $entry 'SNPs_2.txt'
fi
if [[ $entry == *"INDELs"* ]] && [[ $entry == *"_1.txt" ]]; then
mv $entry 'INDELs_1.txt'
fi
if [[ $entry == *"INDELs"* ]] && [[ $entry == *"_2.txt" ]]; then
mv $entry 'INDELs_2.txt'
fi
if [[ $entry == *"CNV"* ]] && [[ $entry == *"stdresults"* ]] && [[ $entry != *"_2.txt" ]]; then
mv $entry 'CNV_stdresults.txt'
fi
if [[ $entry == *"CNV"* ]] && [[ $entry != *"stdresults"* ]] && [[ $entry != *"_2.txt" ]]; then
mv $entry 'CNV_results.txt'
fi
done
printf "Wait! Wait! Simulating the variations in subclone $i is complete. But it's still generating reads ..\n\n" >> $SIMULATION_LOG_FILE
printf "Cleaning temporary files ..\n\n" >> $SIMULATION_LOG_FILE
rm $REFERENCE
# generate tumor reads
# allele 1
cd $ref/
printf "Generating reads for subclone $i ..\n\n" >> $SIMULATION_LOG_FILE
TUMOR_REFERENCE=$ref/$OUTPUT_PREFIX/tumor/subclone_$i/allele_1.fa
TUMOR_OUTPUT_PREFIX=$ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele1
./art_illumina -i $TUMOR_REFERENCE -rs $SEED $M -s 10 -l 100 $SINGLE_OR_PAIRED -f $FOLD_COVERAGE -o $TUMOR_OUTPUT_PREFIX >> $SIMULATION_LOG_FILE 2>&1
# allele 2
TUMOR_REFERENCE=$ref/$OUTPUT_PREFIX/tumor/subclone_$i/allele_2.fa
TUMOR_OUTPUT_PREFIX=$ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele2
./art_illumina -i $TUMOR_REFERENCE -rs $SEED $M -s 10 -l 100 -f $FOLD_COVERAGE $SINGLE_OR_PAIRED -o $TUMOR_OUTPUT_PREFIX >> $SIMULATION_LOG_FILE 2>&1
printf "Finished generating reads for subclone $i ..\n\n" >> $SIMULATION_LOG_FILE
# allele 3
if (( $PLOIDY == 3)); then
TUMOR_REFERENCE=$ref/$OUTPUT_PREFIX/tumor/subclone_$i/allele_3.fa
TUMOR_OUTPUT_PREFIX=$ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele3
./art_illumina -i $TUMOR_REFERENCE -rs $SEED $M -s 10 -l 100 -f $FOLD_COVERAGE $SINGLE_OR_PAIRED -o $TUMOR_OUTPUT_PREFIX >> $SIMULATION_LOG_FILE 2>&1
printf "Finished generating reads for subclone $i ..\n\n" >> $SIMULATION_LOG_FILE
fi
# clean temporary files
cd $ref/$OUTPUT_PREFIX/tumor/subclone_$i
if [[ $sam == True ]]; then
if [[ "$SINGLE_OR_PAIRED" != "-p" ]]; then
bwa mem -t 2 -r "@RG\tID:Tum_Chr20\tSM:Tumor_Chr20" $ref/$OUTPUT_PREFIX/$GENOME $ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele1.fq > "allele1.sam"
bwa mem -t 2 -r "@RG\tID:Tum_Chr20\tSM:Tumor_Chr20" $ref/$OUTPUT_PREFIX/$GENOME $ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele2.fq > "allele2.sam"
#align single end reads from each of the two alleles into seperate SAM files
else
bwa mem -t 2 -r "@RG\tID:Tum_Chr20\tSM:Tumor_Chr20" $ref/$OUTPUT_PREFIX/$GENOME $ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele11.fq $ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele12.fq > "allele1.sam"
bwa mem -t 2 -r "@RG\tID:Tum_Chr20\tSM:Tumor_Chr20" $ref/$OUTPUT_PREFIX/$GENOME $ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele21.fq $ref/$OUTPUT_PREFIX/tumor/subclone_$i/tumor_allele22.fq > "allele2.sam"
fi
fi
#align paired end read from each of the two alleles into seperate sam files
#rm *.bed*
rm *.fa
done
# at the end of the simulation, rename the log file
printf "SIMULATION IS COMPLETE. CHECK THE FOLDERS FOR READS!" >> $SIMULATION_LOG_FILE
mv $SIMULATION_LOG_FILE $ref/$OUTPUT_PREFIX/SIMULATION_IS_COMPLETE.txt