Debian Codegraph @

gm2segs

raw
1 #!/bin/bash -norc
2
3 # Public domain notice for all NCBI EDirect scripts is located at:
4 # https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice
5
6 # cat smear.asn | gm2segs -1-based
7
8 oneBased=true
9 zeroBased=false
10 ucscBased=false
11
12 while [ $# -gt 0 ]
13 do
14 case "$1" in
15 -0-based | -zero-based )
16 zeroBased=true
17 oneBased=false
18 ucscBased=false
19 shift
20 ;;
21 -1-based | -one-based )
22 zeroBased=false
23 oneBased=true
24 ucscBased=false
25 shift
26 ;;
27 -ucsc-based | -ucsc-based )
28 zeroBased=false
29 oneBased=false
30 ucscBased=true
31 shift
32 ;;
33 * )
34 break
35 ;;
36 esac
37 done
38
39 processAlignments() {
40
41 xtract -pattern annot_E -select label/str -equals "BLASTN - mrna" |
42 xtract -rec One -pattern align_E \
43 -block denseg -wrp Accn -sep "." -element accession,version \
44 -block score_E -if id/str -equals score \
45 -wrp Score -element value/int \
46 -block starts -wrp Start -odd starts_E \
47 -block lens -wrp Length -element lens_E \
48 -block strands -wrp Strand -odd strands_E |
49 xtract -rec Two -pattern One \
50 -wrp Accn -element Accn -wrp Score -element Score \
51 -wrp FirstPos -first Start -wrp LastPos -last Start \
52 -wrp FirstLen -first Length -wrp LastLen -last Length \
53 -wrp Strand -first Strand |
54 xtract -pattern Two \
55 -block Two -if Strand -equals plus -def "-" \
56 -element Accn Score FirstPos LastPos LastLen Strand \
57 -block Two -if Strand -equals minus -def "-" \
58 -element Accn Score LastPos FirstPos FirstLen Strand |
59 print-columns '$1, $2, $3, $4 + $5 - 1, $4 + $5 - $3, $6' |
60 sort-table -k 6,6fr -k 3,3n -k 4,4nr -k 1,1f
61 }
62
63 generateTable() {
64
65 if [ "$zeroBased" = true ]
66 then
67 processAlignments
68 elif [ "$oneBased" = true ]
69 then
70 processAlignments |
71 print-columns '$1, $2, $3 + 1, $4 + 1, $5, $6'
72 elif [ "$ucscBased" = true ]
73 then
74 processAlignments |
75 print-columns '$1, $2, $3, $4 + 1, $5, $6'
76 else
77 processAlignments
78 fi
79 }
80
81 tbl=$( generateTable | sort-table -k 6,6fr -k 3,3n -k 4,4n -k 1,1V | uniq -i )
82
83 echo "RAW"
84 echo ""
85 echo "$tbl"
86 echo ""
87 echo ""
88
89 plus=$( echo "$tbl" | grep plus | cut -f 3,4 | fuse-segments )
90 minus=$( echo "$tbl" | grep minus | cut -f 3,4 | fuse-segments )
91 combo=$( echo "$tbl" | grep -e plus -e minus | cut -f 3,4 | fuse-segments )
92
93 echo "PLS"
94 echo ""
95 echo "$plus"
96 echo ""
97 echo ""
98
99 echo "MNS"
100 echo ""
101 echo "$minus"
102 echo ""
103 echo ""
104
105 echo "CMB"
106 echo ""
107 echo "$combo"
108 echo ""
109
110 pl=$( echo "$plus" | wc -l | tr -d ' ' )
111 mn=$( echo "$minus" | wc -l | tr -d ' ' )
112 cb=$( echo "$combo" | wc -l | tr -d ' ' )
113
114 echo "$cb both, $pl plus, $mn minus"
115
116 if [ "$cb" -lt "$((pl + mn))" ]
117 then
118 echo ""
119 echo "$cb < $pl + $mn => overlapping intervals"
120 fi