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