-
Notifications
You must be signed in to change notification settings - Fork 21
/
hapmers.sh
executable file
·138 lines (116 loc) · 3.98 KB
/
hapmers.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
#!/usr/bin/env bash
if [[ "$#" -lt 2 ]]; then
echo
echo "Usage: hapmers.sh <hap1.meryl> <hap2.meryl> [child.meryl] [-no-filt]"
echo -e "\t<hap1.meryl>\tHaplotype1 k-mers (all, ex. maternal)"
echo -e "\t<hap2.meryl>\tHaplotype2 k-mers (all, ex. paternal)"
echo -e "\t[child.meryl]\tChilds' k-mers (all, from WGS reads)"
echo -e "\t-no-filt\tDo not filter parental kmers.\n\t\tUse only if parental dbs aren't from regular sequencing dbs"
echo
echo -e "\tOutput"
echo -e "\t\thap1.only.meryl\tHaplotype1 specific k-mers (parental)"
echo -e "\t\thap2.only.meryl\tHaplotype2 specific k-mers (parental)"
echo -e "\t\tshrd.meryl\tShared k-mers"
echo
echo -e "\tOutput (when [child.meryl is given)"
echo -e "\t\thap1.hapmer.meryl\tHaplotype1, inherited k-mers (ex. maternal hap-mers)"
echo -e "\t\thap2.hapmer.meryl\tHaplotype2, inherited k-mers (ex. paternal hap-mers)"
echo -e "\t\tshrd.inherited.meryl\tShared, inherited k-mers"
echo
echo -e "\t*Build each .meryl dbs using the same k-size"
echo
exit -1
fi
source $MERQURY/util/util.sh
hap1_meryl=`link $1`
hap2_meryl=`link $2`
if ! [[ "$3" == "-no-filt" ]]; then
child_meryl=`link $3`
fi
if [[ "${@: -1}" == "-no-filt" ]]; then
nofilt="-no-filt"
fi
hap1=${hap1_meryl%.meryl*}
hap2=${hap2_meryl%.meryl*}
echo "# Maternal specific k-mers"
if [[ -e $hap1.only.meryl ]]; then
echo "*** Found hap1.only.meryl. ***"
else
bash $MERQURY/build/diff.sh $hap1_meryl $hap2_meryl $hap1.only $nofilt
fi
echo
echo "# Paternal specific k-mers"
if [[ -e $hap2.only.meryl ]]; then
echo "*** Found hap2.only.meryl. ***"
else
bash $MERQURY/build/diff.sh $hap2_meryl $hap1_meryl $hap2.only $nofilt
fi
echo
echo "# Shared k-mers"
if [[ -e shrd.meryl ]]; then
echo "*** Found shrd.meryl. ***"
else
bash $MERQURY/build/intersect.sh $hap1_meryl $hap2_meryl shrd
fi
echo
if [[ -z $child_meryl ]]; then
echo "No child.meryl given. Done!"
exit 0
fi
child=${child_meryl/.meryl}
echo "# $hap1 hap-mers"
if [[ -e $hap1.hapmer.meryl ]]; then
echo "*** Found $hap1.inherited.meryl. ***"
else
bash $MERQURY/build/intersect.sh $child_meryl $hap1.only.meryl $hap1.inherited
bash $MERQURY/build/filt.sh $hap1.inherited.meryl $hap1.hapmer
fi
echo
echo -e "$hap1\t"`cat $hap1.inherited.filt` > cutoffs.txt
echo "# $hap2 hap-mers"
if [[ -e $hap2.hapmer.meryl ]]; then
echo "*** Found hap2.inherited.meryl. ***"
else
bash $MERQURY/build/intersect.sh $child_meryl $hap2.only.meryl $hap2.inherited
bash $MERQURY/build/filt.sh $hap2.inherited.meryl $hap2.hapmer
fi
echo
echo -e "$hap2\t"`cat $hap2.inherited.filt` >> cutoffs.txt
echo "# Shared k-mers"
if [[ -e shrd.filt.meryl ]]; then
echo "*** Found shrd.inherited.meryl. ***"
else
bash $MERQURY/build/intersect.sh $child_meryl shrd.meryl shrd.inherited
bash $MERQURY/build/filt.sh shrd.inherited.meryl shrd.filt
fi
echo
echo -e "shared\t"`cat shrd.inherited.filt` >> cutoffs.txt
echo "# Read only"
if [[ -e read.only.meryl ]]; then
echo "*** Found read.only.meryl ***"
else
meryl union-sum output $child.inherited.meryl $hap1.inherited.meryl $hap2.inherited.meryl shrd.inherited.meryl
meryl difference output read.only.meryl $child_meryl $child.inherited.meryl
fi
echo
echo "# Get histogram"
hist=inherited_hapmers.hist
echo -e "k-mer\tkmer_multiplicity\tCount" > $hist
meryl histogram read.only.meryl | awk -v kmer="child-only" '{print kmer"\t"$1"\t"$2}' >> $hist
meryl histogram $hap1.inherited.meryl | awk -v kmer="$hap1" '{print kmer"\t"$1"\t"$2}' >> $hist
meryl histogram $hap2.inherited.meryl | awk -v kmer="$hap2" '{print kmer"\t"$1"\t"$2}' >> $hist
meryl histogram shrd.inherited.meryl | awk -v kmer="shared" '{print kmer"\t"$1"\t"$2}' >> $hist
echo
echo "# Plot $hist"
source $MERQURY/util/util.sh
has_module=$(check_module)
if [[ $has_module -gt 0 ]]; then
echo "No modules available.."
else
module load R
fi
echo
echo "Rscript $MERQURY/plot/plot_spectra_cn.R -f $hist -o ${hist/.hist/} -l cutoffs.txt"
Rscript $MERQURY/plot/plot_spectra_cn.R -f $hist -o ${hist/.hist/} -l cutoffs.txt
echo
echo "Done!"