Debian Codegraph @

sim4dbutils/convertToExtent.C

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5
6 #include "sim4.H"
7
8 // Writes polishes from stdin as a one-line-per-match format, space-based!
9
10 bool extendedFormat = false;
11
12 void
13 output(sim4polish *p,
14 char *Ep,
15 char *Gp,
16 uint32 a,
17 uint32 b,
18 bool isExon) {
19 uint32 beg = p->_exons[a]._estFrom - 1;
20 uint32 end = p->_exons[b]._estTo;
21
22 if (p->_matchOrientation == SIM4_MATCH_COMPLEMENT) {
23 beg = p->_estLen - beg;
24 end = p->_estLen - end;
25 }
26
27 double ident = p->_exons[a]._percentIdentity;
28 double cover = 0.0;
29
30 // If we're not a single exon, compute the real identity of the whole thing.
31 //
32 if (isExon == false) {
33 if (p->_exons[a]._estAlignment) {
34 ident = p->s4p_percentIdentityExact();
35 cover = p->s4p_percentCoverageExact();
36 } else {
37 ident = p->_percentIdentity;
38 cover = p->_querySeqIdentity;
39 }
40 }
41
42 if (extendedFormat)
43 fprintf(stdout, "%s\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t%s\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t%6.3f\t%6.3f\n",
44 Ep, p->_estID,
45 p->_estLen, a, beg, end,
46 Gp, p->_genID,
47 p->_exons[a]._genFrom - 1, p->_exons[b]._genTo,
48 ident, cover);
49 else
50 fprintf(stdout, "%s\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t%s\t"uint32FMT"\t"uint32FMT"\t%6.3f\t%6.3f\n",
51 Ep, p->_estLen, a, beg, end,
52 Gp, p->_exons[a]._genFrom - 1, p->_exons[b]._genTo,
53 ident, cover);
54 }
55
56
57 int
58 main(int argc, char **argv) {
59 bool beVerbose = false;
60 bool wholeEDefLine = false;
61 bool wholeGDefLine = false;
62 bool doExons = false;
63
64 int arg = 1;
65 int err = 0;
66 while (arg < argc) {
67 if (strcmp(argv[arg], "-v") == 0) {
68 beVerbose = true;
69 } else if (strcmp(argv[arg], "-fullquery") == 0) {
70 wholeEDefLine = true;
71 } else if (strcmp(argv[arg], "-fullgenomic") == 0) {
72 wholeGDefLine = true;
73 } else if (strcmp(argv[arg], "-exons") == 0) {
74 doExons = true;
75 } else if (strcmp(argv[arg], "-extended") == 0) {
76 extendedFormat = true;
77 } else {
78 fprintf(stderr, "Unknown arg '%s'\n", argv[arg]);
79 err++;
80 }
81 arg++;
82 }
83 if (isatty(fileno(stdin)) || (err)) {
84 fprintf(stderr, "usage: %s [options] < IN > OUT\n", argv[0]);
85 fprintf(stderr, " -v be chatty\n");
86 fprintf(stderr, " -fullquery output the whole query def line\n");
87 fprintf(stderr, " -fullgenomic output the whole genomic def line\n");
88 fprintf(stderr, " -exons include exons\n");
89 fprintf(stderr, " -extended include the IDX of each sequence\n");
90 exit(1);
91 }
92
93 if (extendedFormat)
94 fprintf(stdout, "cDNAid\tcDNAidx\tcDNAlen\texonNum\tbegin\tend\tgenomicid\tgenomicidx\tbegin\tend\tidentity\tcoverage\n");
95 else
96 fprintf(stdout, "cDNAid\tcDNAlen\texonNum\tbegin\tend\tgenomicid\tbegin\tend\tidentity\tcoverage\n");
97
98 char E[1024], *Ep;
99 char G[1024], *Gp;
100 splitToWords W;
101
102 sim4polishReader *R = new sim4polishReader("-");
103 sim4polish *p = 0L;
104
105 while (R->nextAlignment(p)) {
106 if (wholeEDefLine == true) {
107 Ep = p->_estDefLine;
108 } else {
109 W.split(p->_estDefLine);
110 strcpy(E, W[0] + ((W[0][0] == '>') ? 1 : 0));
111 Ep = E;
112 }
113
114 if (wholeGDefLine == true) {
115 Gp = p->_genDefLine;
116 } else {
117 W.split(p->_genDefLine);
118 strcpy(G, W[0] + ((W[0][0] == '>') ? 1 : 0));
119 Gp = G;
120 }
121
122 if (doExons == false) {
123 output(p, Ep, Gp, 0, p->_numExons-1, false);
124 } else {
125 for (uint32 i=0; i<p->_numExons; i++)
126 output(p, Ep, Gp, i, i, true);
127 }
128 }
129
130 return(0);
131 }
132