Mercurial > repos > ktnyt > gembassy
comparison GEMBASSY-1.0.3/src/gqueryarm.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 gqueryarm | |
3 ** | |
4 ** Get the replication arm name (left or right) from the given position | |
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 gqueryarm *********************************************************** | |
36 ** | |
37 ** Get the replication arm name (left or right) from the given position | |
38 ** | |
39 ******************************************************************************/ | |
40 | |
41 int main(int argc, char *argv[]) | |
42 { | |
43 embInitPV("gqueryarm", 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 ajint position = 0; | |
57 | |
58 AjPFile outf = NULL; | |
59 | |
60 AjPFile tmpfile = NULL; | |
61 AjPStr tmpname = NULL; | |
62 | |
63 AjPFilebuff tmp = NULL; | |
64 AjPStr line = NULL; | |
65 | |
66 seqall = ajAcdGetSeqall("sequence"); | |
67 position = ajAcdGetInt("position"); | |
68 accid = ajAcdGetBoolean("accid"); | |
69 outf = ajAcdGetOutfile("outfile"); | |
70 | |
71 base = ajStrNewC("rest.g-language.org"); | |
72 | |
73 gAssignUniqueName(&tmpname); | |
74 | |
75 while(ajSeqallNext(seqall, &seq)) | |
76 { | |
77 inseq = NULL; | |
78 | |
79 if(!accid) | |
80 { | |
81 if(gFormatGenbank(seq, &inseq)) | |
82 { | |
83 tmpfile = ajFileNewOutNameS(tmpname); | |
84 if(!tmpfile) | |
85 { | |
86 ajDie("Output file (%S) open error\n", tmpname); | |
87 } | |
88 ajFmtPrintF(tmpfile, "%S", inseq); | |
89 ajFileClose(&tmpfile); | |
90 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); | |
91 gFilePostSS(url, tmpname, &restid); | |
92 ajStrDel(&url); | |
93 ajSysFileUnlinkS(tmpname); | |
94 } | |
95 else | |
96 { | |
97 ajWarn("Sequence does not have features\n" | |
98 "Proceeding with sequence accession ID\n"); | |
99 accid = ajTrue; | |
100 } | |
101 } | |
102 | |
103 ajStrAssignS(&seqid, ajSeqGetAccS(seq)); | |
104 | |
105 if(ajStrGetLen(seqid) == 0) | |
106 { | |
107 ajStrAssignS(&seqid, ajSeqGetNameS(seq)); | |
108 } | |
109 | |
110 if(ajStrGetLen(seqid) == 0) | |
111 { | |
112 ajWarn("No valid header information\n"); | |
113 } | |
114 | |
115 if(accid) | |
116 { | |
117 ajStrAssignS(&restid, seqid); | |
118 if(ajStrGetLen(seqid) == 0) | |
119 { | |
120 ajDie("Cannot proceed without header with -accid\n"); | |
121 } | |
122 | |
123 if(!gValID(seqid)) | |
124 { | |
125 ajDie("Invalid accession ID:%S, exiting\n", seqid); | |
126 } | |
127 } | |
128 | |
129 url = ajStrNew(); | |
130 | |
131 ajFmtPrintS(&url, "http://%S/%S/query_arm/%d/", base, restid, position); | |
132 | |
133 if(!gFilebuffURLS(url, &tmp)) | |
134 { | |
135 ajDie("Failed to download result from:\n%S\n", url); | |
136 } | |
137 | |
138 ajBuffreadLine(tmp, &line); | |
139 | |
140 ajStrRemoveSetC(&line, "\n"); | |
141 | |
142 ajFmtPrintF(outf, "Sequence: %S Arm: %S\n", seqid, line); | |
143 | |
144 ajStrDel(&url); | |
145 ajStrDel(&restid); | |
146 ajStrDel(&seqid); | |
147 ajStrDel(&inseq); | |
148 } | |
149 | |
150 ajFileClose(&outf); | |
151 | |
152 ajSeqallDel(&seqall); | |
153 ajSeqDel(&seq); | |
154 ajStrDel(&base); | |
155 | |
156 embExit(); | |
157 | |
158 return 0; | |
159 } |