1 /** @source taxgetup
2 **
3 ** Find taxons at higher ranks
4 **
5 ** @author Copyright (C) 2010 Jon Ison / EMBOSS
6 ** @version 1  First version</replaceable>
7 ** @modified July 2010  Jon Ison First version</replaceable>
8 ** @@
9 **
10 ** This program is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License
12 ** as published by the Free Software Foundation; either version 2
13 ** of the License, or (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 ********************************************************************/
24 
25 
26 /* ==================================================================== */
27 /* ========================== include files =========================== */
28 /* ==================================================================== */
29 
30 #include "emboss.h"
31 
32 /* Inclusion of system and local header files goes here */
33 
34 
35 
36 /* ==================================================================== */
37 /* ============================ constants ============================= */
38 /* ==================================================================== */
39 
40 /* #define and enum statements go here */
41 
42 
43 
44 /* ==================================================================== */
45 /* ======================== global variables ========================== */
46 /* ==================================================================== */
47 
48 /* Global variables definitions go here */
49 
50 
51 
52 /* ==================================================================== */
53 /* ============================== data ================================ */
54 /* ==================================================================== */
55 
56 /* Definition of datatypes go here */
57 
58 
59 
60 /* ==================================================================== */
61 /* ==================== function prototypes =========================== */
62 /* ==================================================================== */
63 
64 /* Function prototypes for public (external) functions go here */
65 
66 
67 
68 
69 /* @prog taxgetup ************************************************************
70 **
71 ** Find NCBI taxons above search term
72 **
73 ******************************************************************************/
74 
main(int argc,char ** argv)75 int main(int argc, char **argv)
76 {
77     /* Variable declarations */
78     AjPOutfile  outfile = NULL;
79     AjBool hidden = ajFalse;
80 
81     AjPTax tax = NULL;
82     AjPTax taxparent = NULL;
83     AjPTaxall taxall = NULL;
84     AjPTaxin taxinparent = NULL;
85 
86     AjPStr taxqryup = NULL;
87     AjPTable foundtable = NULL;
88 
89     ajuint up;
90     AjPList uplist = NULL;
91 
92     /* ACD processing */
93     embInit("taxgetup", argc, argv);
94 
95     taxall   = ajAcdGetTaxonall("taxons");
96     outfile  = ajAcdGetOuttaxon("outfile");
97     hidden = ajAcdGetBoolean("hidden");
98 
99     taxinparent = ajTaxinNew();
100     taxparent = ajTaxNew();
101     uplist = ajListNew();
102 
103     foundtable = ajTablestrNew(600);
104 
105     while(ajTaxallNext(taxall, &tax))
106     {
107         up = ajTaxGetParent(tax);
108         while (up > 1)
109         {
110             ajFmtPrintS(&taxqryup, "%S-id:%u", ajTaxGetDb(tax), up);
111             ajTaxinQryS(taxinparent, taxqryup);
112 
113             if(!ajTaxinRead(taxinparent, taxparent))
114                 break;
115 
116             if(hidden || !ajTaxIsHidden(taxparent))
117             {
118                 if(!ajTableMatchS(foundtable, taxparent->Id))
119                 {
120                     ajTaxoutWrite(outfile, taxparent);
121                     ajTablePut(foundtable,
122                                ajStrNewS(taxparent->Id),
123                                (void *) 1);
124                 }
125             }
126 
127             up = ajTaxGetParent(taxparent);
128         }
129     }
130 
131     /* Memory clean-up and exit */
132 
133     ajTaxallDel(&taxall);
134     ajTaxinDel(&taxinparent);
135     ajTaxDel(&tax);
136     ajTaxDel(&taxparent);
137 
138     ajListFree(&uplist);
139 
140     ajTablestrFreeKey(&foundtable);
141 
142     ajStrDel(&taxqryup);
143 
144     ajOutfileClose(&outfile);
145 
146     embExit();
147 
148     return 0;
149 }
150 
151 
152 /* ==================================================================== */
153 /* ============================ functions ============================= */
154 /* ==================================================================== */
155 
156