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