source: tags/initial/ORS_CGI/ORS_C_PT.cxx

Last change on this file was 2, checked in by oldcode, 23 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/*
2#################################
3#                               #
4#    ORS_CLIENT:  PT            #
5#    PT database functions      #
6#                               #
7################################# */
8#include <stdio.h>
9#include <stdlib.h>
10#include <memory.h>
11#include <malloc.h>
12#include <string.h>
13#include <arbdb.h>
14
15#include <PT_com.h>
16#include <client.h>
17#include <servercntrl.h>
18
19#include <cat_tree.hxx>
20#include "ors_lib.h"
21//#include "ors_c_java.hxx"
22#include "ors_c.hxx"
23#include "ors_c_proto.hxx"
24
25struct pdgl_struct {
26        aisc_com *link;
27        T_PT_LOCS locs;
28        T_PT_MAIN com;
29        } pd_gl;
30
31// results of probe match
32struct result_struct { 
33        T_PT_MATCHLIST match_list;
34        long match_list_cnt;
35        bytestring bs;
36        } pt_result;
37
38
39/************************************
40  create communication with server
41*************************************/
42int init_pt_local_struct()
43{
44        char *user;
45        if (!(user = (char *)getenv("USER"))) user = "unknown user";
46
47        /* @@@ use finger, date and whoami */
48        if( aisc_create(pd_gl.link, PT_MAIN, pd_gl.com,
49                MAIN_LOCS, PT_LOCS, &pd_gl.locs,
50                LOCS_USER, user,
51                NULL)){
52                return 1;
53        }
54        return 0;
55}
56
57/****************************
58  return name of server #n
59*****************************/
60char *probe_pt_look_for_server(int server_nr)   // 0 = 16s 1 = 23s ...
61        {
62        char choice[256];
63        sprintf(choice,"ARB_PT_SERVER%i",server_nr);
64        return ORS_read_a_line_in_a_file(ORS_LIB_PATH "CONFIG",choice);
65}
66
67/******************************************************************************
68  PROBE MATCH:
69                Send probe request to server and receive probe match results
70*******************************************************************************/
71void probe_match (      int server_nr, char *probe_seq, int max_mismatches,
72                        int weighted_mis, int reversed, int complement,
73                        int max_hits)
74{
75        char    *servername;
76        char    *locs_error;
77
78        if( !(servername=(char *)probe_pt_look_for_server(server_nr)) ){
79                quit_with_error (ORS_export_error("PT_SERVER #%i is unknown (see: ors_lib/servers)",server_nr));
80        }
81
82        // Open Connection
83        pd_gl.link = (aisc_com *)aisc_open(servername, &pd_gl.com,AISC_MAGIC_NUMBER);
84
85        if (!pd_gl.link) {
86                quit_with_error (ORS_export_error("PT_SERVER #%i (%s) not up. Please contact system administrator.",server_nr,servername));
87        }
88
89
90        // Initialize server
91        if (init_pt_local_struct() ) {
92                quit_with_error (ORS_export_error("Lost contact to PT_SERVER - dammit!"));
93        }
94
95        if (aisc_nput(pd_gl.link,PT_LOCS, pd_gl.locs,
96                LOCS_MATCH_REVERSED,            reversed,
97                LOCS_MATCH_SORT_BY,             weighted_mis,
98                LOCS_MATCH_COMPLEMENT,          complement,
99                LOCS_MATCH_MAX_MISMATCHES,      max_mismatches,
100                LOCS_MATCH_MAX_SPECIES,         max_hits,
101                LOCS_SEARCHMATCH,               probe_seq,
102                0)) {
103                quit_with_error ("Connection to PT_SERVER lost (2)");
104        }
105
106        pt_result.bs.data = 0;
107
108        aisc_get( pd_gl.link, PT_LOCS, pd_gl.locs, 
109                LOCS_MATCH_LIST,        &pt_result.match_list,          // short names of species
110                LOCS_MATCH_LIST_CNT,    &pt_result.match_list_cnt,      // count of species short names
111                LOCS_MATCH_STRING,      &pt_result.bs,                  // output of pt_Server
112                LOCS_ERROR,             &locs_error,
113                0);
114        if (*locs_error) {
115                quit_with_error(ORS_export_error("Error in PT_SERVER communication (5): %s",locs_error));
116        }
117        free(locs_error);
118
119        aisc_close(pd_gl.link);
120        free (servername); servername = 0;
121
122}
123
124/******************************************************************************
125  PROBE FIND:
126                Send probe request to server and receive probe match results
127*******************************************************************************/
128#if 0
129
130void probe_find (int server_nr, char *probe_seq)
131{
132        char    *servername;
133        char    *locs_error;
134
135        if( !(servername=(char *)probe_pt_look_for_server(server_nr)) ){
136                quit_with_error (ORS_export_error("PT_SERVER #%i is unknown (see: ors_lib/servers)",server_nr));
137        }
138
139        // Open Connection
140        pd_gl.link = (aisc_com *)aisc_open(servername, (int *)&pd_gl.com,AISC_MAGIC_NUMBER);
141
142        if (!pd_gl.link) {
143                quit_with_error (ORS_export_error("PT_SERVER #%i (%s) not up. Please contact system administrator.",server_nr,servername));
144        }
145
146        // Initialize server
147        if (init_pt_local_struct() )    quit_with_error (ORS_export_error("Lost contact to PT_SERVER - dammit!"));
148
149        if (aisc_nput(pd_gl.link,PT_LOCS, pd_gl.locs,
150                LOCS_PROBE_FIND,        probe_seq,
151                0)) {
152                quit_with_error ("Connection to PT_SERVER lost (8)");
153        }
154
155        pt_result.bs.data = 0;
156
157        aisc_get( pd_gl.link, PT_LOCS, pd_gl.locs,
158                LOCS_MATCH_LIST,        &pt_result.match_list,          // short names of species
159                LOCS_MATCH_LIST_CNT,    &pt_result.match_list_cnt,      // count of species short names
160                LOCS_MATCH_STRING,      &pt_result.bs,                  // output of pt_Server
161                LOCS_ERROR,             &locs_error,
162                0);
163        if (*locs_error) {
164                quit_with_error(ORS_export_error("Error in PT_SERVER communication (7): %s",locs_error));
165        }
166        free(locs_error);
167
168        aisc_close(pd_gl.link);
169        free (servername); servername = 0;
170
171}
172#endif
173
174/******************************************************************************
175
176  OUTPUT RESULTS OF PROBE MATCH AS HTML PAGE (with references)
177
178  output looks like: header line, name line, main line, name line, main line,...
179        name line: 8 characters with name
180        main line: 8 char name (right aligned) space full name space ...
181
182*******************************************************************************/
183void output_html_match_result(void) {
184        char *start, *end, *name;
185        int line=0;
186        if (!pt_result.bs.data) return;
187
188        printf("<PRE>");
189        for (start=pt_result.bs.data; *start;  ) {
190                end=strchr(start,1);
191                if (!end) end = start + strlen(start);
192                // name line
193                if (line != 0 && (line % 2) == 1) {
194                        name=start;
195                }
196                else {
197
198                        if (line) {
199                                printf("<A HREF=\"sp=");
200                                if (name[7]==1) name[7]=' ';   // correct buggy output of server
201                                if (name[6]==1) name[6]=' ';
202                                if (name[5]==1) name[5]=' ';
203                                if (name[4]==1) name[4]=' ';
204                                if (name[3]==1) name[3]=' ';
205                                fwrite(name,8,1,stdout);  // output name (left aligned)
206                                printf("/GS\">");
207                                fwrite(name,8,1,stdout);  // output name (left aligned)
208                                printf("</A>");
209                                fwrite(start + 9,end - start - 9,1,stdout);  // output to eol
210                        }
211                        else {
212                                fwrite(start,end - start,1,stdout);  // output to eol
213                                printf("\n");
214                        }
215
216                        printf("\n");
217                }
218
219                if (*(end)) start=end+1; else start=end;
220                line++;
221        }
222
223        printf("</PRE>");
224}
225
226
227
228char *output_java_match_result(char *filename,char *path_of_tree){
229        char *start = strchr(pt_result.bs.data,1);
230        if (!start){
231                quit_with_error(ORS_export_error("No hits"));
232        }
233
234        FILE *out = fopen(filename,"w");
235        if (!out){
236                quit_with_error(ORS_export_error("Cannot write to file '%s'",filename));
237        }
238        struct T2J_transfer_struct *transfer = T2J_read_query_result_from_pts(pt_result.bs.data);
239        if (!transfer)          quit_with_error( GB_get_error() );
240        GB_ERROR error = T2J_transform(path_of_tree,0,transfer,ors_gl.focus,out);
241
242        fclose(out);
243        GB_set_mode_of_file(filename,00666);
244        return 0;
245}
246
247void free_results(void) {
248        delete pt_result.bs.data; pt_result.bs.data = 0;
249}
Note: See TracBrowser for help on using the repository browser.