annotate GEMBASSY-1.0.3/src/gphx.c @ 1:84a17b3fad1f draft

Uploaded
author ktnyt
date Fri, 26 Jun 2015 05:20:29 -0400
parents 8300eb051bea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
1 /******************************************************************************
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
2 ** @source gphx
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
3 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
4 ** Identify predict highly expressed gene
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
5 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
6 ** @author Copyright (C) 2012 Hidetoshi Itaya
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
7 ** @version 1.0.3
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
8 ** @modified 2012/1/20 Hidetoshi Itaya Created!
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
9 ** @modified 2013/6/16 Revision 1
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
10 ** @@
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
11 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
12 ** This program is free software; you can redistribute it and/or
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
13 ** modify it under the terms of the GNU General Public License
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
14 ** as published by the Free Software Foundation; either version 2
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
15 ** of the License, or (at your option) any later version.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
16 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
17 ** This program is distributed in the hope that it will be useful,
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
20 ** GNU General Public License for more details.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
21 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
22 ** You should have received a copy of the GNU General Public License
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
23 ** along with this program; if not, write to the Free Software
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
24 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
25 ******************************************************************************/
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
26
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
27 #include "emboss.h"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
28 #include "glibs.h"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
29
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
30
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
31
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
32
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
33 /* @prog gphx *****************************************************************
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
34 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
35 ** Identify predict highly expressed gene
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
36 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
37 ******************************************************************************/
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
38
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
39 int main(int argc, char *argv[])
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
40 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
41 embInitPV("gphx", argc, argv, "GEMBASSY", "1.0.3");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
42
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
43 AjPSeqall seqall;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
44 AjPSeq seq;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
45 AjPStr inseq = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
46
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
47 AjBool translate = ajFalse;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
48 AjPStr delkey = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
49
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
50 AjBool accid = ajFalse;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
51 AjPStr restid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
52 AjPStr seqid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
53
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
54 AjPStr base = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
55 AjPStr url = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
56
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
57 AjPFile tmpfile = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
58 AjPStr tmpname = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
59
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
60 AjPFile outf = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
61
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
62 seqall = ajAcdGetSeqall("sequence");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
63 translate = ajAcdGetBoolean("translate");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
64 delkey = ajAcdGetString("delkey");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
65 accid = ajAcdGetBoolean("accid");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
66 outf = ajAcdGetOutfile("outfile");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
67
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
68 base = ajStrNewC("rest.g-language.org");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
69
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
70 gAssignUniqueName(&tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
71
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
72 while(ajSeqallNext(seqall, &seq))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
73 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
74 inseq = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
75
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
76 if(!accid)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
77 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
78 if(gFormatGenbank(seq, &inseq))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
79 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
80 tmpfile = ajFileNewOutNameS(tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
81 if(!tmpfile)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
82 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
83 ajDie("Output file (%S) open error\n", tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
84 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
85 ajFmtPrintF(tmpfile, "%S", inseq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
86 ajFileClose(&tmpfile);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
87 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
88 gFilePostSS(url, tmpname, &restid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
89 ajStrDel(&url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
90 ajSysFileUnlinkS(tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
91 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
92 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
93 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
94 ajWarn("Sequence does not have features\n"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
95 "Proceeding with sequence accession ID\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
96 accid = ajTrue;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
97 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
98 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
99
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
100 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
101
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
102 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
103 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
104 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
105 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
106
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
107 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
108 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
109 ajWarn("No valid header information\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
110 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
111
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
112 if(accid)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
113 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
114 ajStrAssignS(&restid, seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
115 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
116 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
117 ajDie("Cannot proceed without header with -accid\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
118 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
119
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
120 if(!gValID(seqid))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
121 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
122 ajDie("Invalid accession ID:%S, exiting\n", seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
123 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
124 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
125
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
126 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
127
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
128 url = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
129
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
130 ajFmtPrintS(&url, "http://%S/%S/phx/translate=%d/delkey=%S/"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
131 "output=f/tag=gene", base, restid, translate, delkey);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
132
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
133 ajFmtPrintF(outf, "Sequence: %S\n", seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
134 if(!gFileOutURLS(url, &outf))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
135 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
136 ajDie("Failed to download result from:\n%S\n", url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
137 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
138
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
139 ajStrDel(&url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
140 ajStrDel(&restid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
141 ajStrDel(&seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
142 ajStrDel(&inseq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
143 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
144
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
145 ajFileClose(&outf);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
146
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
147 ajSeqallDel(&seqall);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
148 ajSeqDel(&seq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
149 ajStrDel(&base);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
150
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
151 ajStrDel(&delkey);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
152
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
153 embExit();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
154
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
155 return 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
156 }