comparison GEMBASSY-1.0.3/src/gbasecounter.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 gbasecounter
3 **
4 ** Creates a position weight matrix of oligomers around start codon
5 **
6 ** @author Copyright (C) 2012 Hidetoshi Itaya
7 ** @version 1.0.3
8 ** @modified 2012/1/20 Hidetoshi Itaya Created!
9 ** @modified 2015/2/7 Refactor
10 ** @@
11 **
12 ** This program is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License
14 ** as published by the Free Software Foundation; either version 2
15 ** of the License, or (at your option) any later version.
16 **
17 ** This program is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
21 **
22 ** You should have received a copy of the GNU General Public License
23 ** along with this program; if not, write to the Free Software
24 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ******************************************************************************/
26
27 #include "emboss.h"
28 #include "glibs.h"
29
30
31
32
33 /* @prog gbasecounter *********************************************************
34 **
35 ** Creates a position weight matrix of oligomers around start codon
36 **
37 ******************************************************************************/
38
39 int main(int argc, char *argv[])
40 {
41 embInitPV("gbasecounter", argc, argv, "GEMBASSY", "1.0.3");
42
43 AjPSeqall seqall;
44 AjPSeq seq;
45 AjPStr inseq = NULL;
46
47 AjPStr position = NULL;
48 ajint PatLen = 0;
49 ajint upstream = 0;
50 ajint downstream = 0;
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 AjPFile outf = NULL;
63
64 seqall = ajAcdGetSeqall("sequence");
65 position = ajAcdGetSelectSingle("position");
66 PatLen = ajAcdGetInt("patlen");
67 upstream = ajAcdGetInt("upstream");
68 downstream = ajAcdGetInt("downstream");
69 accid = ajAcdGetBoolean("accid");
70 outf = ajAcdGetOutfile("outfile");
71
72 base = ajStrNewC("rest.g-language.org");
73
74 gAssignUniqueName(&tmpname);
75
76 while(ajSeqallNext(seqall, &seq))
77 {
78 inseq = NULL;
79
80 if(!accid)
81 {
82 if(gFormatGenbank(seq, &inseq))
83 {
84 tmpfile = ajFileNewOutNameS(tmpname);
85 if(!tmpfile)
86 {
87 ajDie("Output file (%S) open error\n", tmpname);
88 }
89 ajFmtPrintF(tmpfile, "%S", inseq);
90 ajFileClose(&tmpfile);
91 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
92 gFilePostSS(url, tmpname, &restid);
93 ajStrDel(&url);
94 ajSysFileUnlinkS(tmpname);
95 }
96 else
97 {
98 ajWarn("Sequence does not have features\n"
99 "Proceeding with sequence accession ID\n");
100 accid = ajTrue;
101 }
102 }
103
104 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
105
106 if(ajStrGetLen(seqid) == 0)
107 {
108 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
109 }
110
111 if(ajStrGetLen(seqid) == 0)
112 {
113 ajWarn("No valid header information\n");
114 }
115
116 if(accid)
117 {
118 ajStrAssignS(&restid, seqid);
119 if(ajStrGetLen(seqid) == 0)
120 {
121 ajDie("Cannot proceed without header with -accid\n");
122 }
123
124 if(!gValID(seqid))
125 {
126 ajDie("Invalid accession ID:%S, exiting\n", seqid);
127 }
128 }
129
130 url = ajStrNew();
131
132 ajFmtPrintS(&url, "http://%S/%S/base_counter/position=%S/PatLen=%d"
133 "upstream=%d/downstream=%d/output=f/tag=gene",
134 base, restid, position, PatLen, upstream, downstream);
135
136 ajFmtPrintF(outf, "Sequence: %S\n", seqid);
137 if(!gFileOutURLS(url, &outf))
138 {
139 ajDie("Failed to download result from:\n%S\n", url);
140 }
141
142 ajStrDel(&url);
143 ajStrDel(&restid);
144 ajStrDel(&seqid);
145 ajStrDel(&inseq);
146 }
147
148 ajFileClose(&outf);
149
150 ajSeqallDel(&seqall);
151 ajSeqDel(&seq);
152 ajStrDel(&base);
153
154 ajStrDel(&position);
155
156 embExit();
157
158 return 0;
159 }