comparison GEMBASSY-1.0.3/src/gviewcds.c @ 2:8947fca5f715 draft default tip

Uploaded
author ktnyt
date Fri, 26 Jun 2015 05:21:44 -0400
parents 84a17b3fad1f
children
comparison
equal deleted inserted replaced
1:84a17b3fad1f 2:8947fca5f715
1 /******************************************************************************
2 ** @source gviewcds
3 **
4 ** Displays a graph of nucleotide contents around start and stop codons
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 gviewcds ************************************************************
35 **
36 ** Displays a graph of nucleotide contents around start and stop codons
37 **
38 ******************************************************************************/
39
40 int main(int argc, char *argv[])
41 {
42 embInitPV("gviewcds", argc, argv, "GEMBASSY", "1.0.3");
43
44 AjPSeqall seqall;
45 AjPSeq seq;
46 AjPStr inseq = NULL;
47
48 ajint length = 0;
49 ajint gap = 0;
50
51 AjBool accid = ajFalse;
52 AjPStr restid = NULL;
53 AjPStr seqid = NULL;
54
55 AjPStr base = NULL;
56 AjPStr url = NULL;
57
58 AjPFile tmpfile = NULL;
59 AjPStr tmpname = NULL;
60
61 AjBool plot = 0;
62 AjPFile outf = NULL;
63 AjPFilebuff buff = NULL;
64 AjPGraph mult = NULL;
65
66 gPlotParams gpp;
67 AjPStr title = NULL;
68 AjPPStr names = NULL;
69
70 ajint i;
71
72 seqall = ajAcdGetSeqall("sequence");
73 length = ajAcdGetInt("length");
74 gap = ajAcdGetInt("gap");
75 accid = ajAcdGetBoolean("accid");
76
77 plot = ajAcdGetToggle("plot");
78 outf = ajAcdGetOutfile("outfile");
79 mult = ajAcdGetGraphxy("graph");
80
81 base = ajStrNewC("rest.g-language.org");
82
83 gAssignUniqueName(&tmpname);
84
85 while(ajSeqallNext(seqall, &seq))
86 {
87 inseq = NULL;
88
89 if(!accid)
90 {
91 if(gFormatGenbank(seq, &inseq))
92 {
93 gAssignUniqueName(&tmpname);
94
95 tmpfile = ajFileNewOutNameS(tmpname);
96
97 if(!tmpfile)
98 {
99 ajFmtError("Output file (%S) open error\n", tmpname);
100 embExitBad();
101 }
102
103 ajFmtPrintF(tmpfile, "%S", inseq);
104 ajFileClose(&tmpfile);
105 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
106 gFilePostSS(url, tmpname, &restid);
107 ajStrDel(&url);
108 ajSysFileUnlinkS(tmpname);
109 }
110 else
111 {
112 ajFmtError("Sequence does not have features\n"
113 "Proceeding with sequence accession ID\n");
114 accid = ajTrue;
115 }
116 }
117
118 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
119
120 if(ajStrGetLen(seqid) == 0)
121 {
122 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
123 }
124
125 if(ajStrGetLen(seqid) == 0)
126 {
127 ajWarn("No valid header information\n");
128 }
129
130 if(accid)
131 {
132 ajStrAssignS(&restid, seqid);
133 if(ajStrGetLen(seqid) == 0)
134 {
135 ajDie("Cannot proceed without header with -accid\n");
136 }
137
138 if(!gValID(seqid))
139 {
140 ajDie("Invalid accession ID:%S, exiting\n", seqid);
141 }
142 }
143
144 url = ajStrNew();
145
146 ajFmtPrintS(&url, "http://%S/%S/view_cds/length=%d/gap=%d/"
147 "output=f/tag=gene", base, restid, length, gap);
148
149 if(plot)
150 {
151 if((names = (AjPPStr)malloc(sizeof(AjPStr) * 5)) == NULL) {
152 ajDie("Error in memory allocation, exiting\n");
153 }
154
155 names[0] = NULL;
156 names[1] = ajStrNewC("A");
157 names[2] = ajStrNewC("T");
158 names[3] = ajStrNewC("G");
159 names[4] = ajStrNewC("C");
160
161 title = ajStrNew();
162
163 ajStrAppendC(&title, argv[0]);
164 ajStrAppendC(&title, " of ");
165 ajStrAppendS(&title, seqid);
166
167 gpp.title = ajStrNewS(title);
168 gpp.xlab = ajStrNewC("position");
169 gpp.ylab = ajStrNewC("percentage");
170 gpp.names = names;
171
172 if(!gFilebuffURLS(url, &buff))
173 {
174 ajDie("File downloading error from:\n%S\n", url);
175 }
176
177 if(!gPlotFilebuff(buff, mult, &gpp))
178 {
179 ajDie("Error in plotting\n");
180 }
181
182 i = 0;
183 while(names[i])
184 {
185 AJFREE(names[i]);
186 ++i;
187 }
188
189 AJFREE(names);
190
191 AJFREE(gpp.title);
192 AJFREE(gpp.xlab);
193 AJFREE(gpp.ylab);
194 ajStrDel(&title);
195 ajFilebuffDel(&buff);
196 }
197 else
198 {
199 ajFmtPrintF(outf, "Sequence: %S\n", seqid);
200 if(!gFileOutURLS(url, &outf))
201 {
202 ajDie("File downloading error from:\n%S\n", url);
203 }
204 }
205 }
206
207 ajFileClose(&outf);
208
209 ajSeqallDel(&seqall);
210 ajSeqDel(&seq);
211 ajStrDel(&seqid);
212
213 embExit();
214
215 return 0;
216 }