~ubuntu-branches/ubuntu/warty/ncbi-tools6/warty

« back to all changes in this revision

Viewing changes to biostruc/vastlocl.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2002-04-04 22:13:09 UTC
  • Revision ID: james.westby@ubuntu.com-20020404221309-vfze028rfnlrldct
Tags: upstream-6.1.20011220a
ImportĀ upstreamĀ versionĀ 6.1.20011220a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*   vastlocl.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:  vastlocl.c
 
27
*
 
28
* Author:  Christopher Hogue
 
29
*
 
30
* Version Creation Date:  21 February 97  
 
31
*
 
32
* $Revision: 6.6 $
 
33
*
 
34
* File Description: Used to provide VAST data to MMDB-API when
 
35
*  VAST files are on a local filesystem in standard VAST ftp-site format.
 
36
*                   
 
37
* Modifications:  
 
38
* --------------------------------------------------------------------------
 
39
* $Log: vastlocl.c,v $
 
40
* Revision 6.6  2000/06/21 21:40:07  lewisg
 
41
* change to using gzip
 
42
*
 
43
* Revision 6.5  1998/07/27 16:07:40  madej
 
44
* Pipe the results of gunzip when we get a BAS.
 
45
*
 
46
 * Revision 6.4  1998/05/19  20:13:21  madej
 
47
 * Gunzip needed to run vastsrv on Suns.
 
48
 *
 
49
 * Revision 6.3  1998/03/30  19:28:55  madej
 
50
 * Changes to enable subset filtering.
 
51
 *
 
52
 * Revision 6.2  1998/03/16  15:41:34  lewisg
 
53
 * got rid of gunzip in config file
 
54
 *
 
55
* Revision 6.1  1998/03/06 01:14:12  lewisg
 
56
* merge
 
57
*
 
58
*
 
59
*
 
60
* ==========================================================================
 
61
*/
 
62
 
 
63
 
 
64
/********   NOTE - .mmdbrc (UNIX) mmdb.ini (Win) mmdb.cnf (Mac) required   *******/
 
65
/* containing paths to database VAST          *****/
 
66
/* 
 
67
[VAST]
 
68
Database = /net/dorothy/export/home/hogue/mmdb/Oct96/vastdata/
 
69
 */
 
70
 
 
71
 
 
72
 
 
73
#include <ncbi.h>
 
74
#include <mmdbapi1.h>
 
75
#include "vastlocl.h"
 
76
 
 
77
#ifdef OS_UNIX
 
78
#define MMDB_UNIXCOMPRESSED 1
 
79
#endif
 
80
 
 
81
 
 
82
static Char database[PATH_MAX];
 
83
static Char gunzip[PATH_MAX];
 
84
 
 
85
    
 
86
 
 
87
BiostrucAnnotSetPtr LIBCALL VASTBsAnnotSetGet (Int4 uid)
 
88
{
 
89
   AsnIoPtr aip = NULL;
 
90
   AsnTypePtr atp = NULL;
 
91
   Char path[PATH_MAX];
 
92
   Char compath[PATH_MAX];
 
93
   Char tempfile[PATH_MAX];
 
94
   Char pcId[20];    
 
95
   Int2 iFileExists = 0;
 
96
   BiostrucAnnotSetPtr pbsa = NULL;
 
97
   int iAvail = 1;
 
98
   FILE *pipe;
 
99
 
 
100
   sprintf(pcId, "%ld", (long) uid);
 
101
   path[0] = '\0';
 
102
   StringCpy(path, database);
 
103
   StringCat(path, pcId);
 
104
   StringCat(path, ".bas");
 
105
 
 
106
#ifdef MMDB_UNIXCOMPRESSED
 
107
   compath[0] = '\0';
 
108
   sprintf(compath, "%s -d -c %s.gz ", gunzip, path);
 
109
   pipe = popen(compath, "rb");
 
110
 
 
111
   if (pipe == NULL) {
 
112
       ErrPostEx(SEV_FATAL,0,0, "VASTBsAnnotSetGet failed: Can't find gunzip in path.\n");
 
113
       return NULL;
 
114
   }
 
115
 
 
116
   aip = AsnIoNew(ASNIO_BIN_IN, pipe, NULL, NULL, NULL);
 
117
#else
 
118
   iFileExists = FileLength(path);
 
119
   if (iFileExists == 0)
 
120
      {
 
121
        return NULL;
 
122
      }
 
123
      
 
124
    aip = AsnIoOpen(path, "rb");
 
125
#endif
 
126
 
 
127
    if (aip) 
 
128
     {
 
129
       pbsa = BiostrucAnnotSetAsnRead(aip, NULL);
 
130
       AsnIoClose (aip);
 
131
     }
 
132
 
 
133
#ifdef MMDB_UNIXCOMPRESSED 
 
134
    pclose(pipe);
 
135
#endif
 
136
 
 
137
    if (!pbsa) return NULL;  
 
138
    return pbsa;
 
139
 
140
 
 
141
 
 
142
Boolean LIBCALL IsVASTData(Int4 uid)
 
143
{
 
144
   AsnIoPtr aip = NULL;
 
145
   AsnTypePtr atp = NULL;
 
146
   Char path[PATH_MAX];
 
147
   Char pcId[30];
 
148
 
 
149
   sprintf(pcId, "%ld", (long) uid);
 
150
   path[0] = '\0';
 
151
   StringCpy(path, database);
 
152
   StringCat(path, pcId);
 
153
   StringCat(path, ".bas");
 
154
 
 
155
#ifdef MMDB_UNIXCOMPRESSED 
 
156
   StringCat(path, ".gz");
 
157
   if (FileLength(path) != 0)
 
158
     return TRUE;
 
159
#else
 
160
 
 
161
   if (FileLength(path) != 0)
 
162
     return TRUE;
 
163
#endif
 
164
   return FALSE;
 
165
}
 
166
 
 
167
 
 
168
#ifndef _lygmerge
 
169
 
 
170
Boolean LIBCALL VASTInit (void)
 
171
{
 
172
  Char fname[PATH_MAX];
 
173
 
 
174
  database[0] = gunzip[0] = '\0';
 
175
  GetAppParam("vast", "VASTSRV", "Database", "", database, PATH_MAX);
 
176
  if (database[0] == '\0')
 
177
    {
 
178
        ErrPostEx(SEV_FATAL,0,0, "MMDB config file / path to VAST data missing.\n");
 
179
        return FALSE;
 
180
    }
 
181
  GetAppParam("vast", "VASTSRV", "Gunzip", "", gunzip, (size_t) 256 * (sizeof(char)));
 
182
  if (gunzip[0] == '\0')
 
183
    {
 
184
        ErrPostEx(SEV_FATAL,0,0, "VASTInit failed: gunzip path missing.\n");
 
185
        return FALSE;
 
186
    }
 
187
 
 
188
  GetAppParam("vast", "VASTSRV", "SubsetFile", "", fname, PATH_MAX);
 
189
 
 
190
  if (fname[0] == '\0') {
 
191
        ErrPostEx(SEV_FATAL, 0, 0, "VASTInit failed: no subset file name.\n");
 
192
        return FALSE;
 
193
  }
 
194
 
 
195
  if (LoadSubsetTable(fname) != 1) {
 
196
    ErrPostEx(SEV_FATAL, 0, 0, "VASTInit failed: can't load subset table.\n");
 
197
    return FALSE;
 
198
  }
 
199
 
 
200
  return TRUE;
 
201
 
 
202
}
 
203
 
 
204
#else
 
205
Boolean LIBCALL VASTInit (void)
 
206
{
 
207
 
 
208
  GetAppParam("mmdb", "VAST", "Database", "", database, PATH_MAX);
 
209
  if (database[0] == NULL)
 
210
    {
 
211
        ErrPostEx(SEV_FATAL,0,0, "MMDB config file / path to VAST data missing.\n");
 
212
        return FALSE;
 
213
    }
 
214
  return TRUE;
 
215
}
 
216
#endif
 
217
 
 
218
void LIBCALL VASTFini (void)
 
219
{
 
220
  return;
 
221
}