Mercurial > repos > ktnyt > gembassy
comparison GEMBASSY-1.0.3/src/ggenomicskew.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 ggenomicskew | |
3 ** | |
4 ** Calculates the GC skew in different regions 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 RESTify | |
11 ** @modified 2015/2/7 Refactor | |
12 ** @@ | |
13 ** | |
14 ** This program is free software; you can redistribute it and/or | |
15 ** modify it under the terms of the GNU General Public License | |
16 ** as published by the Free Software Foundation; either version 2 | |
17 ** of the License, or (at your option) any later version. | |
18 ** | |
19 ** This program is distributed in the hope that it will be useful, | |
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ** GNU General Public License for more details. | |
23 ** | |
24 ** You should have received a copy of the GNU General Public License | |
25 ** along with this program; if not, write to the Free Software | |
26 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
27 ******************************************************************************/ | |
28 | |
29 #include "emboss.h" | |
30 #include "glibs.h" | |
31 | |
32 | |
33 | |
34 | |
35 /* @prog ggenomicskew ********************************************************* | |
36 ** | |
37 ** Calculates the GC skew in different regions of the given genome | |
38 ** | |
39 ******************************************************************************/ | |
40 | |
41 int main(int argc, char *argv[]) | |
42 { | |
43 embInitPV("ggenomicskew", argc, argv, "GEMBASSY", "1.0.3"); | |
44 | |
45 AjPSeqall seqall; | |
46 AjPSeq seq; | |
47 AjPStr inseq = NULL; | |
48 | |
49 ajint divide = 0; | |
50 AjBool at = ajFalse; | |
51 | |
52 AjBool accid = ajFalse; | |
53 AjPStr restid = NULL; | |
54 AjPStr seqid = NULL; | |
55 | |
56 AjPStr base = NULL; | |
57 AjPStr url = NULL; | |
58 | |
59 AjPFile tmpfile = NULL; | |
60 AjPStr tmpname = NULL; | |
61 | |
62 AjBool plot = 0; | |
63 AjPFile outf = NULL; | |
64 AjPFilebuff buff = NULL; | |
65 AjPGraph mult = NULL; | |
66 | |
67 gPlotParams gpp; | |
68 AjPStr title = NULL; | |
69 AjPPStr names = NULL; | |
70 | |
71 ajint i; | |
72 | |
73 seqall = ajAcdGetSeqall("sequence"); | |
74 divide = ajAcdGetInt("divide"); | |
75 at = ajAcdGetBoolean("at"); | |
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 ajFmtError("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/genomicskew/divide=%d/at=%d/" | |
148 "output=f/tag=gene", base, restid, divide, at); | |
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("whole genome"); | |
157 names[2] = ajStrNewC("coding region"); | |
158 names[3] = ajStrNewC("intergenic region"); | |
159 names[4] = ajStrNewC("codon third position"); | |
160 | |
161 ajStrAppendC(&title, argv[0]); | |
162 ajStrAppendC(&title, " of "); | |
163 ajStrAppendS(&title, seqid); | |
164 | |
165 gpp.title = ajStrNewS(title); | |
166 gpp.xlab = ajStrNewC("location"); | |
167 gpp.ylab = ajStrNewC("GC skew"); | |
168 gpp.names = names; | |
169 | |
170 if(!gFilebuffURLS(url, &buff)) | |
171 { | |
172 ajDie("File downloading error from:\n%S\n", url); | |
173 } | |
174 | |
175 if(!gPlotFilebuff(buff, mult, &gpp)) | |
176 { | |
177 ajDie("Error in plotting\n"); | |
178 } | |
179 | |
180 i = 0; | |
181 while(names[i]) | |
182 { | |
183 AJFREE(names[i]); | |
184 ++i; | |
185 } | |
186 | |
187 AJFREE(names); | |
188 | |
189 ajStrDel(&title); | |
190 ajStrDel(&(gpp.title)); | |
191 ajStrDel(&(gpp.xlab)); | |
192 ajStrDel(&(gpp.ylab)); | |
193 ajFilebuffDel(&buff); | |
194 } | |
195 else | |
196 { | |
197 ajFmtPrintF(outf, "Sequence: %S\n", seqid); | |
198 if(!gFileOutURLS(url, &outf)) | |
199 { | |
200 ajDie("File downloading error from:\n%S\n", url); | |
201 } | |
202 } | |
203 | |
204 ajStrDel(&url); | |
205 ajStrDel(&restid); | |
206 ajStrDel(&seqid); | |
207 ajStrDel(&inseq); | |
208 } | |
209 | |
210 ajFileClose(&outf); | |
211 | |
212 ajSeqallDel(&seqall); | |
213 ajSeqDel(&seq); | |
214 ajStrDel(&base); | |
215 | |
216 embExit(); | |
217 | |
218 return 0; | |
219 } |