NCBI C Toolkit Cross Reference

C/access/cddapi.c


  1 /*   cddapi.c
  2 * ===========================================================================
  3 *
  4 *                            PUBLIC DOMAIN NOTICE
  5 *            National Center for Biotechnology Information (NCBI)
  6 *
  7 *  This software/database is a "United States Government Work" under the
  8 *  terms of the United States Copyright Act.  It was written as part of
  9 *  the author's official duties as a United States Government employee and
 10 *  thus cannot be copyrighted.  This software/database is freely available
 11 *  to the public for use. The National Library of Medicine and the U.S.
 12 *  Government do not place any restriction on its use or reproduction.
 13 *  We would, however, appreciate having the NCBI and the author cited in
 14 *  any work or product based on this material
 15 *
 16 *  Although all reasonable efforts have been taken to ensure the accuracy
 17 *  and reliability of the software and data, the NLM and the U.S.
 18 *  Government do not and cannot warrant the performance or results that
 19 *  may be obtained by using this software or data. The NLM and the U.S.
 20 *  Government disclaim all warranties, express or implied, including
 21 *  warranties of performance, merchantability or fitness for any particular
 22 *  purpose.
 23 *
 24 * ===========================================================================
 25 *
 26 * File Name:  cddapi.c
 27 *
 28 * Author:  Jonathan Kans
 29 *
 30 * Version Creation Date:   8/16/00
 31 *
 32 * $Revision: 1.13 $
 33 *
 34 * File Description: 
 35 *
 36 * Modifications:  
 37 * --------------------------------------------------------------------------
 38 * Date     Name        Description of modification
 39 * -------  ----------  -----------------------------------------------------
 40 *
 41 *
 42 * ==========================================================================
 43 */
 44 
 45 #include <ncbi.h>
 46 #include <urlquery.h>
 47 #include <cddapi.h>
 48 #include <seqport.h>
 49 #include <sqnutils.h>
 50 
 51 /* low-level connection functions */
 52 
 53 NLM_EXTERN CONN CddOpenConnection (
 54   BioseqPtr bsp,
 55   FloatHi expectValue,
 56   Boolean findBest,
 57   Boolean doFilter,
 58   Boolean makeFeats,
 59   CharPtr dataLib,
 60   Boolean precalc
 61 )
 62 
 63 {
 64   CONN        conn;
 65   Char        expect [32];
 66   Char        feats [16];
 67   Char        filter [8];
 68   Char        graph [8];
 69   Char        id [42];
 70   Char        inputtype [32];
 71   size_t      len;
 72   CharPtr     query;
 73   SeqIdPtr    sip;
 74   CharPtr     str;
 75   /*
 76   size_t      n_written;
 77   EIO_Status  status;
 78   */
 79 
 80   if (bsp == NULL) return NULL;
 81   if (! ISA_aa (bsp->mol)) return NULL;
 82 
 83   str = GetSequenceByBsp (bsp);
 84   if (StringHasNoText (str)) return NULL;
 85   len = StringLen (str);
 86   query = (CharPtr) MemNew (len + 128);
 87   if (query == NULL) {
 88     MemFree (str);
 89     return NULL;
 90   }
 91   sprintf (expect, "%7.4lf", (double) expectValue);
 92   TrimSpacesAroundString (expect);
 93 
 94   if (findBest) {
 95     StringCpy (graph, "1");
 96   } else {
 97     StringCpy (graph, "2");
 98   }
 99 
100   if (doFilter) {
101     StringCpy (filter, "T");
102   } else {
103     StringCpy (filter, "F");
104   }
105 
106   if (makeFeats) {
107     StringCpy (feats, "AONLY");
108   } else {
109     StringCpy (feats, "LONLY");
110   }
111 
112   if (StringHasNoText (dataLib)) {
113     dataLib = "cdd";
114   }
115 
116   if (precalc) {
117     StringCpy (inputtype, "INPUT_TYPE=precalc&FULL&");
118   } else {
119     StringCpy (inputtype, "");
120   }
121 
122   sip = SeqIdFindBest (bsp->id, 0);
123   if (precalc) {
124     SeqIdWrite (sip, id, PRINTID_REPORT, sizeof (id) - 1);
125   } else {
126     SeqIdWrite (sip, id, PRINTID_FASTA_SHORT, sizeof (id) - 1);
127   }
128   if (StringHasNoText (id)) {
129     StringCpy (id, "tmpseq_0");
130   }
131 
132   /*
133   sprintf (query, "%s&NOHTML&DATALIB=%s&EXPECT=%s&FILTER=%s&GRAPH=%s&SEQUENCE=>%s%s%s",
134            feats, dataLib, expect, filter, graph, id, "%0A", str);
135   conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80, "/Structure/cdd/wrpsb.cgi",
136                              NULL, "Entrez2Tool", 30, eMIME_T_NcbiData,
137                              eMIME_Plain, eENCOD_None, 0);
138   status = CONN_Write (conn, (const void *) query, StringLen (query), &n_written, eIO_WritePersist);
139   if (status != eIO_Success) {
140     CONN_Close (conn);
141     MemFree (str);
142     MemFree (query);
143     return NULL;
144   }
145   */
146 
147   if (precalc) {
148     sprintf (query, "%s&NOHTML&DATALIB=%s&EXPECT=%s&FILTER=%s&GRAPH=%s&%sSEQUENCE=%s",
149              feats, dataLib, expect, filter, graph, inputtype, id);
150   } else {
151     sprintf (query, "%s&NOHTML&DATALIB=%s&EXPECT=%s&FILTER=%s&GRAPH=%s&%sSEQUENCE=>%s%s%s",
152              feats, dataLib, expect, filter, graph, inputtype, id, "%0A", str);
153   }
154   conn = QUERY_OpenServiceQuery ("CddSearch2", query, 30);
155 
156   MemFree (str);
157   MemFree (query);
158   return conn;
159 }
160 
161 NLM_EXTERN SeqAnnotPtr CddReadReply (
162   CONN conn,
163   EIO_Status status
164 )
165 
166 {
167   AsnIoConnPtr  aicp;
168   SeqAnnotPtr   sap = NULL;
169 
170   if (conn != NULL && status == eIO_Success) {
171     aicp = QUERY_AsnIoConnOpen ("r", conn);
172     if (aicp == NULL || aicp->aip == NULL) return NULL;
173 
174     /*
175     aicp->aip->scan_for_start = TRUE;
176     */
177 
178     sap = SeqAnnotAsnRead (aicp->aip, NULL);
179     QUERY_AsnIoConnClose (aicp);
180 
181     if (sap != NULL && sap->data == NULL) {
182       sap = SeqAnnotFree (sap);
183     }
184   }
185   return sap;
186 }
187 
188 #ifdef OS_MAC
189 #include <Events.h>
190 #endif
191 
192 NLM_EXTERN SeqAnnotPtr CddWaitForReply (
193   CONN conn
194 )
195 
196 {
197   time_t        currtime, starttime;
198   time_t        max = 0;
199   SeqAnnotPtr   sap = NULL;
200   EIO_Status    status;
201   STimeout      timeout;
202 #ifdef OS_MAC
203   EventRecord   currEvent;
204 #endif
205 
206   if (conn == NULL) return NULL;
207 
208 #ifdef OS_MAC
209   timeout.sec = 0;
210   timeout.usec = 0;
211 #else
212   timeout.sec = 100;
213   timeout.usec = 0;
214 #endif
215 
216   starttime = GetSecs ();
217   while ((status = CONN_Wait (conn, eIO_Read, &timeout)) == eIO_Timeout && max < 300) {
218     currtime = GetSecs ();
219     max = currtime - starttime;
220 #ifdef OS_MAC
221     WaitNextEvent (0, &currEvent, 0, NULL);
222 #endif
223   }
224   if (status == eIO_Success) {
225     sap = CddReadReply (conn, status);
226   }
227   CONN_Close (conn);
228 
229   return sap;
230 }
231 
232 /* high-level connection functions */
233 
234 NLM_EXTERN SeqAnnotPtr CddSynchronousQuery (
235   BioseqPtr bsp,
236   FloatHi expectValue,
237   Boolean findBest,
238   Boolean doFilter,
239   Boolean makeFeats,
240   CharPtr dataLib,
241   Boolean precalc
242 )
243 
244 {
245   CONN         conn;
246   SeqAnnotPtr  sap;
247 
248   conn = CddOpenConnection (bsp, expectValue, findBest, doFilter, makeFeats, dataLib, precalc);
249 
250   if (conn == NULL) return NULL;
251 
252   QUERY_SendQuery (conn);
253 
254   sap = CddWaitForReply (conn);
255 
256   return sap;
257 }
258 
259 NLM_EXTERN Boolean CddAsynchronousQuery (
260   BioseqPtr bsp,
261   FloatHi expectValue,
262   Boolean findBest,
263   Boolean doFilter,
264   Boolean makeFeats,
265   CharPtr dataLib,
266   Boolean precalc,
267   QUEUE* queue,
268   QueryResultProc resultproc,
269   VoidPtr userdata
270 )
271 
272 {
273   CONN  conn;
274 
275   conn = CddOpenConnection (bsp, expectValue, findBest, doFilter, makeFeats, dataLib, precalc);
276 
277   if (conn == NULL) return FALSE;
278 
279   QUERY_SendQuery (conn);
280 
281   QUERY_AddToQueue (queue, conn, resultproc, userdata, TRUE);
282 
283   return TRUE;
284 }
285 
286 NLM_EXTERN Int4 CddCheckQueue (
287   QUEUE* queue
288 )
289 
290 {
291   return QUERY_CheckQueue (queue);
292 }
293 
294 /* utility functions */
295 
296 static void PromoteSeqId (SeqIdPtr sip, Pointer userdata)
297 
298 {
299   SeqIdPtr  bestid, newid, oldid;
300 
301   if (sip == NULL) return;
302 
303   /* change lcl|tmpseq_0 returned from CGI, or gi if precalcualted */
304 
305   if (sip->choice != SEQID_LOCAL && sip->choice != SEQID_GI) return;
306 
307   bestid = (SeqIdPtr) userdata;
308 
309   newid = SeqIdDup (bestid);
310   if (newid == NULL) return;
311 
312   oldid = ValNodeNew (NULL);
313   if (oldid == NULL) return;
314 
315   MemCopy (oldid, sip, sizeof (ValNode));
316   oldid->next = NULL;
317 
318   sip->choice = newid->choice;
319   sip->data.ptrvalue = newid->data.ptrvalue;
320 
321   SeqIdFree (oldid);
322   ValNodeFree (newid);
323 
324   SeqIdStripLocus (sip);
325 }
326 
327 static void CorrectFeatureSeqIds (
328   SeqFeatPtr sfp,
329   Pointer userdata
330 )
331 
332 {
333   VisitSeqIdsInSeqLoc (sfp->location, userdata, PromoteSeqId);
334 }
335 
336 static void CorrectAlignmentSeqIds (
337   SeqAlignPtr sap,
338   Pointer userdata
339 )
340 
341 {
342   VisitSeqIdsInSeqAlign (sap, userdata, PromoteSeqId);
343 }
344 
345 NLM_EXTERN void CddCorrectIDs (
346   BioseqPtr bsp,
347   SeqAnnotPtr sap
348 )
349 
350 {
351   SeqEntryPtr  scope;
352   SeqIdPtr     sip;
353 
354   if (bsp == NULL || sap == NULL) return;
355 
356   sip = SeqIdFindBest (bsp->id, 0);
357   scope = SeqEntrySetScope (NULL);
358   VisitFeaturesOnSap (sap, (Pointer) sip, CorrectFeatureSeqIds);
359   VisitAlignmentsOnSap (sap, (Pointer) sip, CorrectAlignmentSeqIds);
360   SeqEntrySetScope (scope);
361 }
362 
363 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.