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