-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_5S_cov.sh
executable file
·65 lines (52 loc) · 2.36 KB
/
get_5S_cov.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
#!/bin/bash
if [ -z ${SLURM_CPUS_PER_TASK+x} ]; then
cpus=32
else
cpus=$SLURM_CPUS_PER_TASK
fi
SCRIPT_DIR=$1
fastq=$2
ref=$3
out_dir=$4
group=$(basename $fastq | cut -d. -f1)
echo $group
prefix=$out_dir/alignment/5S/$group
temp_prefix=$out_dir/alignment/5S/temp/$group
# minimap2 \
# -t $cpus \
# -a \
# -x map-ont \
# -y \
# --MD \
# -Y \
# $ref \
# $fastq \
# | samtools sort -@$cpus -O BAM --write-index -o $temp_prefix.nofilter.bam##idx##$temp_prefix.nofilter.bam.bai -
# samtools view -@$cpus -F 260 -h -O BAM --write-index -o $temp_prefix.bam##idx##$temp_prefix.bam.bai $temp_prefix.nofilter.bam
# samtools view -@$cpus -h -O SAM -o $temp_prefix.sam $temp_prefix.bam
# samtools view -@$cpus $temp_prefix.bam > $temp_prefix.no_header.sam
# samtools view -@$cpus -H $temp_prefix.bam > $temp_prefix.just_header.sam
# paftools.js sam2paf $temp_prefix.sam > $temp_prefix.paf
# python $SCRIPT_DIR/filter_both_18S.py $temp_prefix.no_header.sam $temp_prefix.paf sam 85 > $temp_prefix.filtered.sam
# python $SCRIPT_DIR/filter_both_18S.py $temp_prefix.no_header.sam $temp_prefix.paf paf 85 > $temp_prefix.filtered.paf
# awk '{print $1, $3, $4, $5}' $temp_prefix.filtered.paf > $temp_prefix.filtered.bed
# bash $SCRIPT_DIR/get_chimeras_for_python.sh $temp_prefix.filtered.bed > $temp_prefix.chimeras.txt
# if [[ $(cat $temp_prefix.chimeras.txt | wc -l) -eq 0 ]]; then
# cp $temp_prefix.filtered.paf $prefix.paf
# cp $temp_prefix.filtered.bed $prefix.bed
# cat $temp_prefix.just_header.sam $temp_prefix.filtered.sam | samtools sort -@$cpus -O BAM --write-index -o $prefix.bam##idx##$prefix.bam.bai -
# else
# python $SCRIPT_DIR/remove_chimeras.py $temp_prefix.filtered.paf $temp_prefix.chimeras.txt > $prefix.paf
# python $SCRIPT_DIR/remove_chimeras.py $temp_prefix.filtered.bed $temp_prefix.chimeras.txt > $prefix.bed
# cat $temp_prefix.just_header.sam $temp_prefix.filtered.sam > $temp_prefix.temp.sam
# python $SCRIPT_DIR/remove_chimeras.py $temp_prefix.temp.sam $temp_prefix.chimeras.txt | samtools sort -@$cpus -O BAM --write-index -o $prefix.bam##idx##$prefix.bam.bai -
# fi
num_alns=$(cat $prefix.paf | wc -l)
echo -e "final alignments (reads to ref) $num_alns"
if [[ $num_alns -gt 0 ]]; then
samtools depth \
-@$cpus \
-a \
$prefix.bam \
| awk '{sum+=$3} END {print sum/NR}' > $prefix.5S_cov.txt
fi