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