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