comparison GEMBASSY-1.0.3/src/gldabias.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 gldabias
3 **
4 ** Calculate strand bias of bacterial genome using linear discriminant
5 ** analysis (LDA)
6 **
7 ** @author Copyright (C) 2012 Hidetoshi Itaya
8 ** @version 1.0.3
9 ** @modified 2012/1/20 Hidetoshi Itaya Created!
10 ** @modified 2013/6/16 Revision 1
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 gldabias ************************************************************
36 **
37 ** Calculate strand bias of bacterial genome using linear discriminant
38 ** analysis (LDA)
39 **
40 ******************************************************************************/
41
42 int main(int argc, char *argv[])
43 {
44 embInitPV("gldabias", argc, argv, "GEMBASSY", "1.0.3");
45
46 AjPSeqall seqall;
47 AjPSeq seq;
48 AjPStr inseq = NULL;
49
50 ajint coefficients = 0;
51 AjPStr variable = NULL;
52
53 AjBool accid = ajFalse;
54 AjPStr restid = NULL;
55 AjPStr seqid = NULL;
56
57 AjPStr base = NULL;
58 AjPStr url = NULL;
59
60 AjPFile tmpfile = NULL;
61 AjPStr tmpname = NULL;
62
63 AjPFilebuff tmp = NULL;
64 AjPStr line = NULL;
65
66 AjPFile outf = NULL;
67
68 seqall = ajAcdGetSeqall("sequence");
69 coefficients = ajAcdGetInt("coefficients");
70 variable = ajAcdGetSelectSingle("variable");
71 accid = ajAcdGetBoolean("accid");
72 outf = ajAcdGetOutfile("outfile");
73
74 base = ajStrNewC("rest.g-language.org");
75
76 gAssignUniqueName(&tmpname);
77
78 while(ajSeqallNext(seqall, &seq))
79 {
80 inseq = NULL;
81
82 if(!accid)
83 {
84 if(gFormatGenbank(seq, &inseq))
85 {
86 tmpfile = ajFileNewOutNameS(tmpname);
87 if(!tmpfile)
88 {
89 ajDie("Output file (%S) open error\n", tmpname);
90 }
91 ajFmtPrintF(tmpfile, "%S", inseq);
92 ajFileClose(&tmpfile);
93 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
94 gFilePostSS(url, tmpname, &restid);
95 ajStrDel(&url);
96 ajSysFileUnlinkS(tmpname);
97 }
98 else
99 {
100 ajWarn("Sequence does not have features\n"
101 "Proceeding with sequence accession ID\n");
102 accid = ajTrue;
103 }
104 }
105
106 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
107
108 if(ajStrGetLen(seqid) == 0)
109 {
110 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
111 }
112
113 if(ajStrGetLen(seqid) == 0)
114 {
115 ajWarn("No valid header information\n");
116 }
117
118 if(accid)
119 {
120 ajStrAssignS(&restid, seqid);
121 if(ajStrGetLen(seqid) == 0)
122 {
123 ajDie("Cannot proceed without header with -accid\n");
124 }
125
126 if(!gValID(seqid))
127 {
128 ajDie("Invalid accession ID:%S, exiting\n", seqid);
129 }
130 }
131
132 url = ajStrNew();
133
134 ajFmtPrintS(&url, "http://%S/%S/lda_bias/coefficients=%d/variable=%S",
135 base, restid, coefficients, variable);
136
137 if(!gFilebuffURLS(url, &tmp))
138 {
139 ajDie("Failed to download result from:\n%S\n", url);
140 }
141
142 ajBuffreadLine(tmp, &line);
143
144 ajStrRemoveSetC(&line, "\n");
145
146 ajFmtPrintF(outf, "Sequence: %S LDA-BIAS: %S\n", seqid, line);
147
148 ajStrDel(&url);
149 ajStrDel(&restid);
150 ajStrDel(&seqid);
151 ajStrDel(&inseq);
152 }
153
154 ajFileClose(&outf);
155
156 ajSeqallDel(&seqall);
157 ajSeqDel(&seq);
158 ajStrDel(&base);
159
160 embExit();
161
162 return 0;
163 }