Mercurial > repos > ktnyt > gembassy
comparison GEMBASSY-1.0.3/src/greporiter.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 greporiter | |
3 ** | |
4 ** Get the positions of replication origin and terminus | |
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 greporiter ********************************************************* | |
36 ** | |
37 ** Get the positions of replication origin and terminus | |
38 ** | |
39 ******************************************************************************/ | |
40 | |
41 int main(int argc, char *argv[]) | |
42 { | |
43 embInitPV("greporiter", argc, argv, "GEMBASSY", "1.0.3"); | |
44 | |
45 AjPSeqall seqall; | |
46 AjPSeq seq; | |
47 AjPStr inseq = NULL; | |
48 | |
49 AjBool accid = ajFalse; | |
50 AjPStr restid = NULL; | |
51 AjPStr seqid = NULL; | |
52 | |
53 AjPStr base = NULL; | |
54 AjPStr url = NULL; | |
55 | |
56 AjBool oriloc = 0; | |
57 AjBool gcskew = 0; | |
58 AjBool dbonly = 0; | |
59 ajint difthreshold = 0; | |
60 | |
61 AjPFile outf = NULL; | |
62 | |
63 AjPFile tmpfile = NULL; | |
64 AjPStr tmpname = NULL; | |
65 AjPStr fstname = NULL; | |
66 AjPFilebuff tmp = NULL; | |
67 AjPStr line = NULL; | |
68 AjPSeqout tmpout = NULL; | |
69 | |
70 AjPRegexp regex; | |
71 | |
72 AjPStr ori = NULL; | |
73 AjPStr ter = NULL; | |
74 | |
75 seqall = ajAcdGetSeqall("sequence"); | |
76 difthreshold = ajAcdGetInt("difthreshold"); | |
77 oriloc = ajAcdGetBoolean("oriloc"); | |
78 gcskew = ajAcdGetBoolean("gcskew"); | |
79 dbonly = ajAcdGetBoolean("dbonly"); | |
80 accid = ajAcdGetBoolean("accid"); | |
81 outf = ajAcdGetOutfile("outfile"); | |
82 | |
83 base = ajStrNewC("rest.g-language.org"); | |
84 | |
85 gAssignUniqueName(&tmpname); | |
86 gAssignUniqueName(&fstname); | |
87 ajStrAppendC(&fstname, ".fasta"); | |
88 | |
89 while(ajSeqallNext(seqall, &seq)) | |
90 { | |
91 inseq = ajStrNew(); | |
92 | |
93 tmpout = ajSeqoutNew(); | |
94 | |
95 if(!accid) | |
96 { | |
97 if(gFormatGenbank(seq, &inseq)) | |
98 { | |
99 tmpfile = ajFileNewOutNameS(tmpname); | |
100 if(!tmpfile) | |
101 { | |
102 ajDie("Output file (%S) open error\n", tmpname); | |
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 if(!ajSeqoutOpenFilename(tmpout, fstname)) | |
114 { | |
115 embExitBad(); | |
116 } | |
117 | |
118 ajSeqoutSetFormatS(tmpout,ajStrNewC("fasta")); | |
119 ajSeqoutWriteSeq(tmpout, seq); | |
120 ajSeqoutClose(tmpout); | |
121 ajSeqoutDel(&tmpout); | |
122 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); | |
123 gFilePostSS(url, fstname, &restid); | |
124 ajStrDel(&url); | |
125 ajSysFileUnlinkS(fstname); | |
126 } | |
127 } | |
128 | |
129 ajStrAssignS(&seqid, ajSeqGetAccS(seq)); | |
130 | |
131 if(ajStrGetLen(seqid) == 0) | |
132 { | |
133 ajStrAssignS(&seqid, ajSeqGetNameS(seq)); | |
134 } | |
135 | |
136 if(ajStrGetLen(seqid) == 0) | |
137 { | |
138 ajWarn("No valid header information\n"); | |
139 } | |
140 | |
141 if(accid) | |
142 { | |
143 ajStrAssignS(&restid, seqid); | |
144 if(ajStrGetLen(seqid) == 0) | |
145 { | |
146 ajDie("Cannot proceed without header with -accid\n"); | |
147 } | |
148 | |
149 if(!gValID(seqid)) | |
150 { | |
151 ajDie("Invalid accession ID:%S, exiting\n", seqid); | |
152 } | |
153 } | |
154 | |
155 url = ajStrNew(); | |
156 | |
157 ajFmtPrintS(&url, "http://%S/%S/rep_ori_ter/oriloc=%d/gcskew=%d/" | |
158 "difthreshold=%d/dbonly=%d/", base, restid, oriloc, gcskew, | |
159 difthreshold, dbonly); | |
160 | |
161 if(!gFilebuffURLS(url, &tmp)) | |
162 { | |
163 ajDie("Failed to download result from:\n%S\n", url); | |
164 } | |
165 | |
166 ajBuffreadLine(tmp, &line); | |
167 | |
168 regex = ajRegCompC("([0-9]+),([0-9]+)"); | |
169 | |
170 if(ajRegExec(regex, line)) { | |
171 if(ajRegSubI(regex, 1, &ori), ajRegSubI(regex, 2, &ter)) { | |
172 ajFmtPrint("%S Origin: %S Terminus %S\n", seqid, ori, ter); | |
173 } | |
174 } | |
175 | |
176 ajStrDel(&url); | |
177 ajStrDel(&restid); | |
178 ajStrDel(&seqid); | |
179 ajStrDel(&inseq); | |
180 } | |
181 | |
182 ajFileClose(&outf); | |
183 | |
184 ajSeqallDel(&seqall); | |
185 ajSeqDel(&seq); | |
186 ajStrDel(&base); | |
187 | |
188 embExit(); | |
189 | |
190 return 0; | |
191 } |