comparison GEMBASSY-1.0.3/src/gconsensusz.c @ 0:8300eb051bea draft

Initial upload
author ktnyt
date Fri, 26 Jun 2015 05:19:29 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8300eb051bea
1 /******************************************************************************
2 ** @source gconsensusz
3 **
4 ** Calculate the consensus in givin array of sequences
5 **
6 ** @author Copyright (C) 2012 Hidetoshi Itaya
7 ** @version 1.0.3
8 ** @modified 2012/1/20 Hidetoshi Itaya Created!
9 ** @modified 2013/6/16 Revision 1
10 ** @modified 2015/2/7 Refactor
11 ** @@
12 **
13 ** This program is free software; you can redistribute it and/or
14 ** modify it under the terms of the GNU General Public License
15 ** as published by the Free Software Foundation; either version 2
16 ** of the License, or (at your option) any later version.
17 **
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
22 **
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ******************************************************************************/
27
28 #include "emboss.h"
29 #include "soapH.h"
30 #include "GLANGSoapBinding.nsmap"
31 #include "soapClient.c"
32 #include "soapC.c"
33 #include "../gsoap/stdsoap2.c"
34 #include "glibs.h"
35
36
37
38
39 /* @prog gconsensusz *********************************************************
40 **
41 ** Calculate the consensus in givin array of sequences
42 **
43 ******************************************************************************/
44
45 int main(int argc, char *argv[])
46 {
47 embInitPV("gconsensusz", argc, argv, "GEMBASSY", "1.0.3");
48
49 struct soap soap;
50 struct ns1__consensus_USCOREzInputParams params;
51 struct arrayIn array_seq;
52
53 AjPSeqall seqall;
54 AjPSeq seq;
55 ajint high = 0;
56 double low = 0;
57
58 char *result;
59
60 AjBool plot = 0;
61 AjPFile outf = NULL;
62 AjPFilebuff buff = NULL;
63 AjPGraph mult = NULL;
64
65 gPlotParams gpp;
66 AjPStr title = NULL;
67
68 ajint i;
69 ajint size = 0;
70 char **ptr = NULL;
71
72 seqall = ajAcdGetSeqall("sequence");
73 high = ajAcdGetInt("high");
74 low = ajAcdGetFloat("low");
75
76 plot = ajAcdGetToggle("plot");
77 outf = ajAcdGetOutfile("outfile");
78 mult = ajAcdGetGraphxy("graph");
79
80 params.high = high;
81 params.low = low;
82 params.output = "f";
83
84 array_seq.__ptr = NULL;
85 array_seq.__size = 0;
86
87 ptr = (char**)malloc(sizeof(char*));
88
89 if(!ptr)
90 {
91 ajDie("Error in allocation\n");
92 }
93
94 while(ajSeqallNext(seqall, &seq))
95 {
96 ptr = (char**)realloc(ptr, sizeof(char*) * (size + 1));
97
98 if(!ptr)
99 {
100 ajDie("Error in allocation\n");
101 }
102
103 *(ptr + size) = ajCharNewS(ajSeqGetSeqS(seq));
104
105 ++size;
106 }
107
108 if(size < 2)
109 {
110 AJFREE(*ptr);
111 AJFREE(ptr);
112
113 ajDie("File only has one sequence. Please input more than two.\n");
114 }
115
116 array_seq.__ptr = ptr;
117 array_seq.__size = size;
118
119 soap_init(&soap);
120
121 if(soap_call_ns1__consensus_USCOREz(
122 &soap,
123 NULL,
124 NULL,
125 &array_seq,
126 &params,
127 &result
128 ) == SOAP_OK)
129 {
130 if(plot)
131 {
132 ajStrAppendC(&title, argv[0]);
133
134 gpp.title = ajStrNewS(title);
135 gpp.xlab = ajStrNewC("position");
136 gpp.ylab = ajStrNewC("consensus");
137
138 if(!gFilebuffURLC(result, &buff))
139 {
140 ajDie("File downloading error from:\n%s\n", result);
141 }
142
143 if(!gPlotFilebuff(buff, mult, &gpp))
144 {
145 ajDie("Error in plotting\n");
146 }
147
148 ajStrDel(&title);
149 ajStrDel(&(gpp.xlab));
150 ajStrDel(&(gpp.ylab));
151 }
152 else
153 {
154 if(!gFileOutURLC(result, &outf))
155 {
156 ajDie("File downloading error from:\n%s\n", result);
157 embExitBad();
158 }
159 }
160 }
161 else
162 {
163 soap_print_fault(&soap, stderr);
164 }
165
166 soap_destroy(&soap);
167 soap_end(&soap);
168 soap_done(&soap);
169
170 ajFileClose(&outf);
171
172 ajSeqallDel(&seqall);
173 ajSeqDel(&seq);
174
175 i = 0;
176
177 while(i < size)
178 {
179 AJFREE(*(ptr + i));
180 ++i;
181 }
182
183 AJFREE(ptr);
184
185 embExit();
186
187 return 0;
188 }