annotate GEMBASSY-1.0.3/src/ggcsi.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 ggcsi
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
3 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
4 ** GC Skew Index: an index for strand-specific mutational bias
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 RESTify
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
11 ** @modified 2015/2/7 Refactor
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
12 ** @@
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
13 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
14 ** This program is free software; you can redistribute it and/or
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
15 ** modify it under the terms of the GNU General Public License
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
16 ** as published by the Free Software Foundation; either version 2
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
17 ** of the License, or (at your option) any later version.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
18 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
19 ** This program is distributed in the hope that it will be useful,
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
22 ** GNU General Public License for more details.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
23 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
24 ** You should have received a copy of the GNU General Public License
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
25 ** along with this program; if not, write to the Free Software
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
26 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
27 ******************************************************************************/
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
28
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
29 #include "emboss.h"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
30 #include "glibs.h"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
31
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
32
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
33
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
34
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
35 /* @prog ggcsi ****************************************************************
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
36 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
37 ** GC Skew Index: an index for strand-specific mutational bias
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
38 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
39 ******************************************************************************/
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
40
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
41 int main(int argc, char *argv[])
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
42 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
43 embInitPV("ggcsi", argc, argv, "GEMBASSY", "1.0.3");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
44
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
45 AjPSeqall seqall;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
46 AjPSeq seq;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
47 AjPStr inseq = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
48
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
49 AjPStr restid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
50 AjPStr seqid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
51
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
52 AjPStr base = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
53 AjPStr url = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
54
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
55 ajint window = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
56 AjBool at = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
57 AjBool purine = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
58 AjBool keto = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
59 AjBool pval = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
60 AjPStr version = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
61
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
62 AjPStr tmpname = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
63 AjPSeqout tmpout = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
64 AjPFilebuff tmpbuff = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
65
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
66 AjPStr tmp = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
67 AjPStr parse = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
68 AjPStr gcsi = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
69 AjPStr sa = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
70 AjPStr dist = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
71 AjPStr z = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
72 AjPStr p = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
73
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
74 AjPStrTok handle = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
75
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
76 AjPFile outf = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
77
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
78 seqall = ajAcdGetSeqall("sequence");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
79 window = ajAcdGetInt("window");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
80 at = ajAcdGetBoolean("at");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
81 purine = ajAcdGetBoolean("purine");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
82 keto = ajAcdGetBoolean("keto");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
83 pval = ajAcdGetBoolean("pval");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
84 version = ajAcdGetSelectSingle("gcsi");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
85 outf = ajAcdGetOutfile("outfile");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
86
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
87 base = ajStrNewC("rest.g-language.org");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
88
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
89 gAssignUniqueName(&tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
90 ajStrAppendC(&tmpname, ".fasta");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
91
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
92 while(ajSeqallNext(seqall, &seq))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
93 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
94 tmpout = ajSeqoutNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
95
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
96 if(!ajSeqoutOpenFilename(tmpout, tmpname))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
97 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
98 embExitBad();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
99 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
100
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
101 ajSeqoutSetFormatS(tmpout,ajStrNewC("fasta"));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
102 ajSeqoutWriteSeq(tmpout, seq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
103 ajSeqoutClose(tmpout);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
104 ajSeqoutDel(&tmpout);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
105
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
106 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
107 gFilePostSS(url, tmpname, &restid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
108 ajStrDel(&url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
109 ajSysFileUnlinkS(tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
110
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
111 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
112
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
113 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
114 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
115 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
116 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
117
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
118 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
119 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
120 ajWarn("No valid header information\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
121 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
122
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
123 url = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
124
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
125 ajFmtPrintS(&url, "http://%S/%S/gcsi/window=%d/at=%d/purine=%d/"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
126 "keto=%d/p=%d/version=%d/", base, restid, window, at, purine,
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
127 keto, pval, version);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
128
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
129 if(!gFilebuffURLS(url, &tmpbuff))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
130 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
131 ajDie("Failed to download result from:\n%S\n", url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
132 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
133
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
134 ajBuffreadLine(tmpbuff, &tmp);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
135
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
136 parse = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
137 gcsi = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
138 sa = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
139 dist = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
140 z = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
141 p = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
142
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
143 ajStrRemoveLastNewline(&tmp);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
144
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
145 handle = ajStrTokenNewC(tmp, ",");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
146
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
147 while (ajStrTokenNextParse(handle, &parse))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
148 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
149 if (ajStrIsFloat(parse))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
150 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
151 if(!ajStrGetLen(gcsi))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
152 ajStrAssignS(&gcsi, parse);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
153 else if(!ajStrGetLen(sa))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
154 ajStrAssignS(&sa, parse);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
155 else if(!ajStrGetLen(dist))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
156 ajStrAssignS(&dist, parse);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
157 else if(!ajStrGetLen(z))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
158 ajStrAssignS(&z, parse);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
159 else if(!ajStrGetLen(p))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
160 ajStrAssignS(&p, parse);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
161 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
162 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
163
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
164 tmp = ajFmtStr("Sequence: %S GCSI: %S SA: %S DIST: %S",
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
165 seqid, gcsi, sa, dist);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
166
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
167 if(pval)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
168 tmp = ajFmtStr("%S Z: %S P: %S", tmp, z, p);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
169
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
170 ajFmtPrintF(outf, "%S\n", tmp);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
171
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
172 ajStrDel(&tmp);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
173 ajStrDel(&parse);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
174 ajStrDel(&gcsi);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
175 ajStrDel(&sa);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
176 ajStrDel(&dist);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
177 ajStrDel(&z);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
178 ajStrDel(&p);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
179
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
180 ajStrDel(&inseq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
181 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
182
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
183 ajFileClose(&outf);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
184
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
185 ajSeqallDel(&seqall);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
186 ajSeqDel(&seq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
187 ajStrDel(&seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
188
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
189 embExit();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
190
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
191 return 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
192 }