-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunBulkCHIP_fastq.pbs
executable file
·136 lines (106 loc) · 4.42 KB
/
runBulkCHIP_fastq.pbs
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
#!/bin/bash
#PBS -q condo
#PBS -N chiseq
#PBS -l nodes=1:ppn=16
#PBS -l walltime=8:00:00
#PBS -V
#PBS -m abe
#PBS -A epigen-group
source activate aquas_chipseq
WORKDIR="/oasis/tscc/scratch/$(whoami)/outputs/"
FASTQDIR="/projects/ps-epigen/seqdata/"
# chipseq or not
[[ "$chipseq" = true ]] && c="-type chip-seq"
# select libs col1:libid,col2:genome,col3:PE/SE
ncol=$(awk 'END{print NF}' $samples)
[[ $ncol -ne 4 ]] && { echo "sample file dosen't have 4 columns "; exit 0; }
samplenames=(`cat $samples`)
INPREFIX=${samplenames[${PBS_ARRAYID}*4]} #index start from 0
GENOME=${samplenames[${PBS_ARRAYID}*4+1]}
READ=${samplenames[${PBS_ARRAYID}*4+2]}
IS_INPUT=${samplenames[${PBS_ARRAYID}*4+3]}
# split name into subnames
subnames=($(echo $INPREFIX|awk -v FS='_' '{for(i=1;i<=NF;i++) print $i}'))
n_subnames=${#subnames[@]} # number of subnames split at _
snap='true' #default turn on snap-chip
# parameters
type="histone"
true_rep="true"
no_pseudo_rep="true"
# output dir
OUTDIR="${WORKDIR}${INPREFIX}"
mkdir -p $OUTDIR
if [ $READ = 'PE' ]
then
echo "Using PE pipepline"
# check fastqs
fastq1="${FASTQDIR}/${INPREFIX}_R1.fastq.gz"
fastq2="${FASTQDIR}/${INPREFIX}_R2.fastq.gz"
echo $fastq1
# no fastqs and not merged libs
[[ ! -f $fastq1 ]] && [[ $n_subnames -lt 4 ]] && { echo "$fastq1 fastq1 not found"; exit 0; }
[[ ! -f $fastq2 ]] && [[ $n_subnames -lt 4 ]] && { echo "$fastq1 fastq2 not found"; exit 0; }
## merge submembers if submembers presents
if [ ! -f $fastq1 ] || [ ! -f $fastq2 ] # break down to check components
then
base_id=${subnames[0]}_${subnames[1]}
tmp=(${subnames[@]/#/${base_id}_})
sub_libs=($(echo ${tmp[@]:2}| sed 's/_1 / /g'))
tmp=($(echo ${sub_libs[@]./#/${FASTQDIR}}))
tmp_r1=${tmp[@]/%/_R1.fastq.gz}
tmp_r2=${tmp[@]/%/_R2.fastq.gz}
[[ ! -f $fastq1 ]] && { echo "cat $tmp_r1 > $fastq1 & sleep 1" | bash;}
[[ ! -f $fastq2 ]] && { echo "cat $tmp_r2 > $fastq2 & sleep 1" | bash;}
fi
wait
# runPipeline
bds /projects/ps-epigen/software/atac_dnase_pipelines/atac.bds -species $GENOME -nth $PBS_NP \
-fastq1_1 "$fastq1" \
-fastq1_2 "$fastq2" \
-true_rep -no_idr -no_par -no_xcor \
-out_dir $OUTDIR $c
wait
## addtional check
[[ -z $(find ${OUTDIR}/qc/rep1 -name "*_qc.txt") ]] && { echo "pipeline failed"; exit 0; }
# runFastQC & fastq_screen
runFastQC_screen.sh $INPREFIX &
## snap-chip
#export PATH=$PATH:/projects/ps-epigen/software/SNAP-CHIP_epicypher
#bash epicypher.sh -i $fastq1 -m 2 -k true -o /projects/ps-epigen/outputs/libQCs/${INPREFIX}/ 1 | tee /projects/ps-epigen//outputs/libQCs/${INPREFIX}/${INPREFIX}_R1.fastq.gz.snap.cnt.tab &
#bash epicypher.sh -i $fastq2 -m 2 -k true -o /projects/ps-epigen/outputs/libQCs/${INPREFIX}/ 1 | tee /projects/ps-epigen//outputs/libQCs/${INPREFIX}/${INPREFIX}_R2.fastq.gz.snap.cnt.tab
else
echo "Using SE pipepline"
# fastq check
fq="${FASTQDIR}/${INPREFIX}.fastq.gz"
[[ ! -f $fq ]] && [[ $n_subnames -lt 4 ]] && { echo "$fq fastq not found"; exit 0; }
## merge submembers if submembers presents
if [ ! -f $fq ]
then
base_id=${subnames[0]}_${subnames[1]}
tmp=(${subnames[@]/#/${base_id}_})
sub_libs=($(echo ${tmp[@]:2}| sed 's/_1 / /g'))
tmp=($(echo ${sub_libs[@]./#/${FASTQDIR}}))
tmp_r1=(${tmp[@]/%/_R1.fastq.gz})
i=0;for fl in ${tmp_r1[@]};do [[ ! -f $fl ]] && tmp_r1[$i]=${fl/_R1./.};i=$[i+1];echo $i; done
echo "cat ${tmp_r1[@]} > $fq & sleep 1" | bash
fi
wait
# run pipeline
bds /projects/ps-epigen/software/atac_dnase_pipelines/atac.bds -species $GENOME -nth $PBS_NP \
-se -fastq1 $fq \
-true_rep -no_idr -no_par \
-out_dir $OUTDIR $c
wait
## addtional check
[[ -z $(find ${OUTDIR}/qc/rep1 -name "*_qc.txt") ]] && { echo "pipeline failed"; exit 0; }
# fastqc and screen
runFastQC_screen_se.sh $INPREFIX &
## snap-chip
#export PATH=$PATH:/projects/ps-epigen/software/SNAP-CHIP_epicypher
#bash epicypher.sh -i $fq -m 2 -k true -o /projects/ps-epigen/outputs/libQCs/${INPREFIX}/ 1 | tee /projects/ps-epigen//outputs/libQCs/${INPREFIX}/${INPREFIX}.fastq.gz.snap.cnt.tab &
fi
wait
# result transfer
results_transfer.sh $INPREFIX $(whoami)
# add .finished.txt tag
touch /projects/ps-epigen/outputs/libQCs/${INPREFIX}/.finished.txt