1 /* @source martattributes application
2 **
3 ** Return biomart attributes given mart dataset info
4 **
5 ** @author Copyright (C) Alan Bleasby
6 ** @@
7 **
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
22
23 #include "emboss.h"
24
25
26
27
28 /* @prog martattributes *******************************************************
29 **
30 ** Reads and writes (returns) sequences
31 **
32 ******************************************************************************/
33
main(int argc,char ** argv)34 int main(int argc, char **argv)
35 {
36 AjPSeqin seqin = NULL;
37 AjPMartquery mq = NULL;
38 AjPMartquery pmq = NULL;
39 AjPMartAttribute att = NULL;
40
41 AjPStr dataset = NULL;
42 AjPStr host = NULL;
43 AjPStr path = NULL;
44
45 AjPStr pagekey = NULL;
46 AjPStr currpage = NULL;
47 const AjPStr pageval = NULL;
48 AjBool firstpage = ajTrue;
49
50 AjPFile outf = NULL;
51 ajint iport = 0;
52
53 ajuint i;
54 AjPStr key1 = NULL;
55 AjPStr key2 = NULL;
56 const AjPStr value1 = NULL;
57 const AjPStr value2 = NULL;
58
59
60 embInit("martattributes", argc, argv);
61
62
63 host = ajAcdGetString("host");
64 path = ajAcdGetString("path");
65 iport = ajAcdGetInt("port");
66 dataset = ajAcdGetString("dataset");
67
68 outf = ajAcdGetOutfile("outfile");
69
70 mq = ajMartqueryNew();
71 seqin = ajSeqinNew();
72
73 ajMartAttachMartquery(seqin,mq);
74 ajMartSetMarthostS(seqin,host);
75 ajMartSetMartpathS(seqin,path);
76 ajMartSetMartport(seqin,iport);
77
78 /*
79 **
80 ** This section retrieves the attributes given a mart dataset name
81 ** from a mart host.
82 */
83
84 ajMartGetAttributes(seqin, dataset);
85 ajMartattributesParse(seqin);
86
87 ajMartattributesPageSort(seqin);
88
89 key1 = ajStrNewC("name");
90 key2 = ajStrNewC("displayName");
91
92 pagekey = ajStrNewC("page");
93 currpage = ajStrNewC("Dummy_page_value");
94
95 pmq = ajMartGetMartqueryPtr(seqin);
96 att = pmq->Atts;
97
98 for(i=0; i < att->Natts; ++i)
99 {
100 pageval = ajTableFetchS(att->Attributes[i], pagekey);
101
102 if(!ajStrMatchS(currpage, pageval))
103 {
104 if(!firstpage)
105 ajFmtPrintF(outf,"\n\n");
106 else
107 firstpage = ajFalse;
108
109 ajStrAssignS(&currpage,pageval);
110 ajFmtPrintF(outf,"PAGE TITLE %S\n\n",pageval);
111 }
112
113 value1 = ajTableFetchS(att->Attributes[i], key1);
114 value2 = ajTableFetchS(att->Attributes[i], key2);
115 ajFmtPrintF(outf,"%-40S %S\n",value1,value2);
116 }
117
118
119 ajStrDel(&key1);
120 ajStrDel(&key2);
121 ajStrDel(&pagekey);
122 ajStrDel(&currpage);
123
124 ajStrDel(&host);
125 ajStrDel(&path);
126 ajStrDel(&dataset);
127
128 ajMartquerySeqinFree(seqin);
129
130 ajSeqinDel(&seqin);
131 ajFileClose(&outf);
132
133 embExit();
134
135 return 0;
136 }
137