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