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