comparison GEMBASSY-1.0.3/src/ggeneskew.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 ggeneskew
3 **
4 ** Calculate the gene strand bias of the given genome
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 "glibs.h"
30
31
32
33
34 /* @prog ggeneskew ************************************************************
35 **
36 ** Calculate the gene strand bias of the given genome
37 **
38 ******************************************************************************/
39
40 int main(int argc, char *argv[])
41 {
42 embInitPV("ggeneskew", argc, argv, "GEMBASSY", "1.0.3");
43
44 AjPSeqall seqall;
45 AjPSeq seq;
46 AjPStr inseq = NULL;
47
48 ajint window = 0;
49 ajint slide = 0;
50 AjBool cumulative = ajFalse;
51 AjBool gc3 = ajFalse;
52 AjPStr basetype = NULL;
53
54 AjBool accid = ajFalse;
55 AjPStr restid = NULL;
56 AjPStr seqid = NULL;
57
58 AjPStr base = NULL;
59 AjPStr url = NULL;
60
61 AjPFile tmpfile = NULL;
62 AjPStr tmpname = NULL;
63
64 AjBool plot = 0;
65 AjPFile outf = NULL;
66 AjPFilebuff buff = NULL;
67 AjPGraph mult = NULL;
68
69 gPlotParams gpp;
70 AjPStr title = NULL;
71
72 seqall = ajAcdGetSeqall("sequence");
73 window = ajAcdGetInt("window");
74 slide = ajAcdGetInt("slide");
75 cumulative = ajAcdGetBoolean("cumulative");
76 gc3 = ajAcdGetBoolean("gctri");
77 basetype = ajAcdGetSelectSingle("base");
78 accid = ajAcdGetBoolean("accid");
79
80 plot = ajAcdGetToggle("plot");
81 outf = ajAcdGetOutfile("outfile");
82 mult = ajAcdGetGraphxy("graph");
83
84 if(ajStrMatchC(base, "none"))
85 basetype = ajStrNewC("");
86
87 base = ajStrNewC("rest.g-language.org");
88
89 gAssignUniqueName(&tmpname);
90
91 while(ajSeqallNext(seqall, &seq))
92 {
93 inseq = NULL;
94
95 if(!accid)
96 {
97 if(gFormatGenbank(seq, &inseq))
98 {
99 gAssignUniqueName(&tmpname);
100
101 tmpfile = ajFileNewOutNameS(tmpname);
102
103 if(!tmpfile)
104 {
105 ajFmtError("Output file (%S) open error\n", tmpname);
106 embExitBad();
107 }
108
109 ajFmtPrintF(tmpfile, "%S", inseq);
110 ajFileClose(&tmpfile);
111 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
112 gFilePostSS(url, tmpname, &restid);
113 ajStrDel(&url);
114 ajSysFileUnlinkS(tmpname);
115 }
116 else
117 {
118 ajFmtError("Sequence does not have features\n"
119 "Proceeding with sequence accession ID\n");
120 accid = ajTrue;
121 }
122 }
123
124 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
125
126 if(ajStrGetLen(seqid) == 0)
127 {
128 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
129 }
130
131 if(ajStrGetLen(seqid) == 0)
132 {
133 ajWarn("No valid header information\n");
134 }
135
136 if(accid)
137 {
138 ajStrAssignS(&restid, seqid);
139 if(ajStrGetLen(seqid) == 0)
140 {
141 ajDie("Cannot proceed without header with -accid\n");
142 }
143
144 if(!gValID(seqid))
145 {
146 ajDie("Invalid accession ID:%S, exiting\n", seqid);
147 }
148 }
149
150 url = ajStrNew();
151
152 ajFmtPrintS(&url, "http://%S/%S/geneskew/window=%d/slide=%d/"
153 "cumulative=%d/gc3=%d/base=%S/output=f/tag=gene",
154 base, restid, window, slide, cumulative, gc3, basetype);
155
156 if(plot)
157 {
158 title = ajStrNew();
159
160 ajStrAppendC(&title, argv[0]);
161 ajStrAppendC(&title, " of ");
162 ajStrAppendS(&title, seqid);
163
164 gpp.title = ajStrNewS(title);
165 gpp.xlab = ajStrNewC("gene skew");
166 gpp.ylab = ajStrNewC("bp");
167
168 if(!gFilebuffURLS(url, &buff))
169 {
170 ajDie("File downloading error from:\n%S\n", url);
171 }
172
173 if(!gPlotFilebuff(buff, mult, &gpp))
174 {
175 ajDie("Error in plotting\n");
176 }
177
178 AJFREE(gpp.title);
179 AJFREE(gpp.xlab);
180 AJFREE(gpp.ylab);
181 ajStrDel(&title);
182 ajFilebuffDel(&buff);
183 }
184 else
185 {
186 ajFmtPrintF(outf, "Sequence: %S\n", seqid);
187 if(!gFileOutURLS(url, &outf))
188 {
189 ajDie("File downloading error from:\n%S\n", url);
190 }
191 }
192
193 ajStrDel(&url);
194 ajStrDel(&restid);
195 ajStrDel(&seqid);
196 ajStrDel(&inseq);
197 }
198
199 ajFileClose(&outf);
200
201 ajSeqallDel(&seqall);
202 ajSeqDel(&seq);
203 ajStrDel(&base);
204
205 embExit();
206
207 return 0;
208 }