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