Mercurial > repos > ktnyt > gembassy
comparison GEMBASSY-1.0.3/src/gew.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 gew | |
3 ** | |
4 ** Calculate a measure of synonymous codon usage evenness (Ew) | |
5 ** | |
6 ** @author Copyright (C) 2012 Hidetoshi Itaya | |
7 ** @version 1.0.3 Revision 1 | |
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 gew ****************************************************************** | |
35 ** | |
36 ** Calculate a measure of synonymous codon usage evenness (Ew) | |
37 ** | |
38 ******************************************************************************/ | |
39 | |
40 int main(int argc, char *argv[]) | |
41 { | |
42 embInitPV("gew", argc, argv, "GEMBASSY", "1.0.3"); | |
43 | |
44 AjPSeqall seqall; | |
45 AjPSeq seq; | |
46 AjPStr inseq = NULL; | |
47 | |
48 AjBool translate = ajFalse; | |
49 AjPStr delkey = 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 translate = ajAcdGetBoolean("translate"); | |
65 delkey = ajAcdGetString("delkey"); | |
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/Ew/translate=%d/delkey=%S/" | |
130 "output=f/tag=gene", base, restid, translate, delkey); | |
131 | |
132 ajFmtPrintF(outf, "Sequence: %S\n", seqid); | |
133 if(!gFileOutURLS(url, &outf)) | |
134 { | |
135 ajDie("Failed to download result from:\n%S\n", url); | |
136 } | |
137 | |
138 ajStrDel(&url); | |
139 ajStrDel(&restid); | |
140 ajStrDel(&seqid); | |
141 ajStrDel(&inseq); | |
142 } | |
143 | |
144 ajFileClose(&outf); | |
145 | |
146 ajSeqallDel(&seqall); | |
147 ajSeqDel(&seq); | |
148 ajStrDel(&base); | |
149 | |
150 ajStrDel(&delkey); | |
151 | |
152 embExit(); | |
153 | |
154 return 0; | |
155 } |