0
|
1 /******************************************************************************
|
|
2 ** @source gdeltaenc
|
|
3 **
|
|
4 ** Calculate the codon usage bias related to translation optimization
|
|
5 ** (delta enc)
|
|
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 gdeltaenc **********************************************************
|
|
36 **
|
|
37 ** Calculate the codon usage bias related to translation optimization
|
|
38 ** (delta enc)
|
|
39 **
|
|
40 ******************************************************************************/
|
|
41
|
|
42 int main(int argc, char *argv[])
|
|
43 {
|
|
44 embInitPV("gdeltaenc", argc, argv, "GEMBASSY", "1.0.3");
|
|
45
|
|
46 AjPSeqall seqall;
|
|
47 AjPSeq seq;
|
|
48 AjPStr inseq = NULL;
|
|
49
|
|
50 AjBool accid = ajFalse;
|
|
51 AjPStr restid = NULL;
|
|
52 AjPStr seqid = NULL;
|
|
53
|
|
54 AjPStr base = NULL;
|
|
55 AjPStr url = NULL;
|
|
56
|
|
57 AjPFile tmpfile = NULL;
|
|
58 AjPStr tmpname = NULL;
|
|
59 AjPFilebuff tmp = NULL;
|
|
60
|
|
61 AjPStr line = NULL;
|
|
62
|
|
63 AjPFile outf = NULL;
|
|
64
|
|
65 seqall = ajAcdGetSeqall("sequence");
|
|
66 accid = ajAcdGetBoolean("accid");
|
|
67 outf = ajAcdGetOutfile("outfile");
|
|
68
|
|
69 base = ajStrNewC("rest.g-language.org");
|
|
70
|
|
71 gAssignUniqueName(&tmpname);
|
|
72
|
|
73 while(ajSeqallNext(seqall, &seq))
|
|
74 {
|
|
75 inseq = NULL;
|
|
76
|
|
77 if(!accid)
|
|
78 {
|
|
79 if(gFormatGenbank(seq, &inseq))
|
|
80 {
|
|
81 tmpfile = ajFileNewOutNameS(tmpname);
|
|
82 if(!tmpfile)
|
|
83 {
|
|
84 ajDie("Output file (%S) open error\n", tmpname);
|
|
85 }
|
|
86 ajFmtPrintF(tmpfile, "%S", inseq);
|
|
87 ajFileClose(&tmpfile);
|
|
88 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
|
|
89 gFilePostSS(url, tmpname, &restid);
|
|
90 ajStrDel(&url);
|
|
91 ajSysFileUnlinkS(tmpname);
|
|
92 }
|
|
93 else
|
|
94 {
|
|
95 ajWarn("Sequence does not have features\n"
|
|
96 "Proceeding with sequence accession ID\n");
|
|
97 accid = ajTrue;
|
|
98 }
|
|
99 }
|
|
100
|
|
101 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
|
|
102
|
|
103 if(ajStrGetLen(seqid) == 0)
|
|
104 {
|
|
105 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
|
|
106 }
|
|
107
|
|
108 if(ajStrGetLen(seqid) == 0)
|
|
109 {
|
|
110 ajWarn("No valid header information\n");
|
|
111 }
|
|
112
|
|
113 if(accid)
|
|
114 {
|
|
115 ajStrAssignS(&restid, seqid);
|
|
116 if(ajStrGetLen(seqid) == 0)
|
|
117 {
|
|
118 ajDie("Cannot proceed without header with -accid\n");
|
|
119 }
|
|
120
|
|
121 if(!gValID(seqid))
|
|
122 {
|
|
123 ajDie("Invalid accession ID:%S, exiting\n", seqid);
|
|
124 }
|
|
125 }
|
|
126
|
|
127 url = ajStrNew();
|
|
128
|
|
129 ajFmtPrintS(&url, "http://%S/%S/delta_enc/", base, restid);
|
|
130
|
|
131 if(!gFilebuffURLS(url, &tmp))
|
|
132 {
|
|
133 ajDie("Failed to download result from:\n%S\n", url);
|
|
134 }
|
|
135
|
|
136 ajBuffreadLine(tmp, &line);
|
|
137
|
|
138 ajStrRemoveSetC(&line, "\n");
|
|
139
|
|
140 ajFmtPrintF(outf, "Sequence: %S DELTA-ENC %S\n", seqid, line);
|
|
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 embExit();
|
|
155
|
|
156 return 0;
|
|
157 }
|