annotate GEMBASSY-1.0.3/src/gdistincc.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 gdistincc
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
3 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
4 ** Calculates distance betwwen two loci in cirular chromosomes
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 ** @modified 2015/2/7 Support sequences without features
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
11 ** @modified 2015/2/7 Remove negative distance bug
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
12 ** @modified 2015/2/7 Refactor
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
13 ** @@
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
14 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
15 ** This program is free software; you can redistribute it and/or
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
16 ** modify it under the terms of the GNU General Public License
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
17 ** as published by the Free Software Foundation; either version 2
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
18 ** of the License, or (at your option) any later version.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
19 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
20 ** This program is distributed in the hope that it will be useful,
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
21 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
22 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
23 ** GNU General Public License for more details.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
24 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
25 ** You should have received a copy of the GNU General Public License
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
26 ** along with this program; if not, write to the Free Software
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
27 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
28 ******************************************************************************/
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
29
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
30 #include "emboss.h"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
31 #include "glibs.h"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
32
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
33
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
34
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
35
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
36
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
37 /* @prog gdistincc **********************************************************
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
38 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
39 ** Calculates distance betwwen two loci in cirular chromosomes
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
40 **
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
41 ******************************************************************************/
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
42
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
43 int main(int argc, char *argv[])
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
44 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
45 embInitPV("gdistincc", argc, argv, "GEMBASSY", "1.0.3");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
46
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
47 AjPSeqall seqall;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
48 AjPSeq seq;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
49 AjPStr inseq;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
50
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
51 AjBool accid = ajFalse;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
52 AjPStr seqid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
53 AjPStr restid = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
54
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
55 AjPStr base = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
56 AjPStr url = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
57
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
58 ajint first;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
59 ajint second;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
60
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
61 AjPFile outfile = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
62 AjPFile tmpfile = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
63 AjPStr tmpname = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
64 AjPStr fstname = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
65 AjPFilebuff tmp = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
66 AjPStr line = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
67 AjPSeqout tmpout = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
68
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
69 seqall = ajAcdGetSeqall("sequence");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
70 first = ajAcdGetInt("first");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
71 second = ajAcdGetInt("second");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
72 accid = ajAcdGetBoolean("accid");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
73 outfile = ajAcdGetOutfile("outfile");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
74
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
75 base = ajStrNewC("rest.g-language.org");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
76
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
77 gAssignUniqueName(&tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
78 gAssignUniqueName(&fstname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
79 ajStrAppendC(&fstname, ".fasta");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
80
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
81 while(ajSeqallNext(seqall, &seq))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
82 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
83 inseq = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
84
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
85 tmpout = ajSeqoutNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
86
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
87 if(!accid)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
88 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
89 if(gFormatGenbank(seq, &inseq))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
90 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
91 tmpfile = ajFileNewOutNameS(tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
92 if(!tmpfile)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
93 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
94 ajDie("Output file (%S) open error\n", tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
95 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
96 ajFmtPrintF(tmpfile, "%S", inseq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
97 ajFileClose(&tmpfile);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
98 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
99 gFilePostSS(url, tmpname, &restid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
100 ajStrDel(&url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
101 ajSysFileUnlinkS(tmpname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
102 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
103 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
104 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
105 if(!ajSeqoutOpenFilename(tmpout, fstname))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
106 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
107 embExitBad();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
108 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
109
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
110 ajSeqoutSetFormatS(tmpout,ajStrNewC("fasta"));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
111 ajSeqoutWriteSeq(tmpout, seq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
112 ajSeqoutClose(tmpout);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
113 ajSeqoutDel(&tmpout);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
114 ajFmtPrintS(&url, "http://%S/upload/upl.pl", base);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
115 gFilePostSS(url, fstname, &restid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
116 ajStrDel(&url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
117 ajSysFileUnlinkS(fstname);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
118 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
119 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
120
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
121 ajStrAssignS(&seqid, ajSeqGetAccS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
122
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
123 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
124 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
125 ajStrAssignS(&seqid, ajSeqGetNameS(seq));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
126 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
127
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
128 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
129 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
130 ajWarn("No valid header information\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
131 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
132
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
133 if(accid)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
134 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
135 ajStrAssignS(&restid, seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
136 if(ajStrGetLen(seqid) == 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
137 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
138 ajDie("Cannot proceed without header with -accid\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
139 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
140
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
141 if(!gValID(seqid))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
142 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
143 ajDie("Invalid accession ID:%S, exiting\n", seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
144 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
145 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
146
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
147 url = ajStrNew();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
148
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
149 if(second >= 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
150 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
151 ajFmtPrintS(&url, "http://%S/%S/dist_in_cc/%d/%d",
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
152 base, restid, first, second);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
153 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
154 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
155 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
156 ajFmtPrintS(&url, "http://%S/%S/dist_in_cc/%d",
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
157 base, restid, first);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
158 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
159
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
160 if(!gFilebuffURLS(url, &tmp))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
161 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
162 ajDie("Failed to download result from:\n%S\n", url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
163 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
164
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
165 ajBuffreadLine(tmp, &line);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
166
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
167 ajStrRemoveSetC(&line, "\n");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
168
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
169 if(second >= 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
170 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
171 ajFmtPrintF(outfile, "Sequence: %S Position1: %d Position2: %d "
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
172 "Distance %S\n", seqid, first, line);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
173 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
174 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
175 {
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
176 ajFmtPrintF(outfile, "Sequence: %S Position1: %d Distance %S\n",
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
177 seqid, first, line);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
178 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
179
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
180 ajStrDel(&url);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
181 ajStrDel(&restid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
182 ajStrDel(&seqid);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
183 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
184
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
185 ajFileClose(&outfile);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
186
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
187 ajSeqallDel(&seqall);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
188 ajSeqDel(&seq);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
189 ajStrDel(&base);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
190
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
191 embExit();
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
192
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
193 return 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
194 }