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