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