annotate GEMBASSY-1.0.3/src/ggenomicskew.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 ggenomicskew
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
3 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
4 ** Calculates the GC skew in different regions of the given genome
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 ggenomicskew *********************************************************
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
36 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
37 ** Calculates the GC skew in different regions of the given genome
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("ggenomicskew", 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 ajint divide = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
50 AjBool at = ajFalse;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
51
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
52 AjBool accid = ajFalse;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
53 AjPStr restid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
54 AjPStr seqid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
55
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
56 AjPStr base = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
57 AjPStr url = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
58
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
59 AjPFile tmpfile = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
60 AjPStr tmpname = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
61
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
62 AjBool plot = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
63 AjPFile outf = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
64 AjPFilebuff buff = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
65 AjPGraph mult = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
66
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
67 gPlotParams gpp;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
68 AjPStr title = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
69 AjPPStr names = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
70
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
71 ajint i;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
72
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
73 seqall = ajAcdGetSeqall("sequence");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
74 divide = ajAcdGetInt("divide");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
75 at = ajAcdGetBoolean("at");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
76 accid = ajAcdGetBoolean("accid");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
77
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
78 plot = ajAcdGetToggle("plot");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
79 outf = ajAcdGetOutfile("outfile");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
80 mult = ajAcdGetGraphxy("graph");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
81
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
82 base = ajStrNewC("rest.g-language.org");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
83
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
84 gAssignUniqueName(&tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
85
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
86 while (ajSeqallNext(seqall, &seq))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
87 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
88 inseq = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
89
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
90 if(!accid)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
91 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
92 if(gFormatGenbank(seq, &inseq))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
93 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
94 gAssignUniqueName(&tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
95
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
96 tmpfile = ajFileNewOutNameS(tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
97
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
98 if(!tmpfile)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
99 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
100 ajFmtError("Output file (%S) open error\n", tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
101 embExitBad();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
102 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
103
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
104 ajFmtPrintF(tmpfile, "%S", inseq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
105 ajFileClose(&tmpfile);
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 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
112 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
113 ajFmtError("Sequence does not have features\n"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
114 "Proceeding with sequence accession ID\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
115 accid = ajTrue;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
116 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
117 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
118
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
119 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
120
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
121 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
122 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
123 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
124 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
125
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
126 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
127 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
128 ajWarn("No valid header information\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
129 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
130
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
131 if(accid)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
132 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
133 ajStrAssignS(&restid, seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
134 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
135 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
136 ajDie("Cannot proceed without header with -accid\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
137 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
138
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
139 if(!gValID(seqid))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
140 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
141 ajDie("Invalid accession ID:%S, exiting\n", seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
142 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
143 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
144
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
145 url = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
146
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
147 ajFmtPrintS(&url, "http://%S/%S/genomicskew/divide=%d/at=%d/"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
148 "output=f/tag=gene", base, restid, divide, at);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
149 if(plot)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
150 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
151 if((names = (AjPPStr)malloc(sizeof(AjPStr) * 5)) == NULL) {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
152 ajDie("Error in memory allocation, exiting\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
153 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
154
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
155 names[0] = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
156 names[1] = ajStrNewC("whole genome");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
157 names[2] = ajStrNewC("coding region");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
158 names[3] = ajStrNewC("intergenic region");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
159 names[4] = ajStrNewC("codon third position");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
160
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
161 ajStrAppendC(&title, argv[0]);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
162 ajStrAppendC(&title, " of ");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
163 ajStrAppendS(&title, seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
164
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
165 gpp.title = ajStrNewS(title);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
166 gpp.xlab = ajStrNewC("location");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
167 gpp.ylab = ajStrNewC("GC skew");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
168 gpp.names = names;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
169
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
170 if(!gFilebuffURLS(url, &buff))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
171 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
172 ajDie("File downloading error from:\n%S\n", url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
173 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
174
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
175 if(!gPlotFilebuff(buff, mult, &gpp))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
176 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
177 ajDie("Error in plotting\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
178 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
179
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
180 i = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
181 while(names[i])
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
182 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
183 AJFREE(names[i]);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
184 ++i;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
185 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
186
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
187 AJFREE(names);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
188
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
189 ajStrDel(&title);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
190 ajStrDel(&(gpp.title));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
191 ajStrDel(&(gpp.xlab));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
192 ajStrDel(&(gpp.ylab));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
193 ajFilebuffDel(&buff);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
194 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
195 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
196 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
197 ajFmtPrintF(outf, "Sequence: %S\n", seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
198 if(!gFileOutURLS(url, &outf))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
199 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
200 ajDie("File downloading error from:\n%S\n", url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
201 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
202 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
203
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
204 ajStrDel(&url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
205 ajStrDel(&restid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
206 ajStrDel(&seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
207 ajStrDel(&inseq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
208 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
209
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
210 ajFileClose(&outf);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
211
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
212 ajSeqallDel(&seqall);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
213 ajSeqDel(&seq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
214 ajStrDel(&base);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
215
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
216 embExit();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
217
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
218 return 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
219 }