1 /* $Id: setsts.c,v 6.0 1997/08/25 18:20:40 madden Exp $ */
2 /*****************************************************************************
3 
4     Name: setsts.c
5 
6     Description:  Program for formatting memory map for WWW STS Search Tool
7 
8     Author: Sergei Shavirin
9 
10    ***************************************************************************
11 
12                           PUBLIC DOMAIN NOTICE
13               National Center for Biotechnology Information
14 
15     This software/database is a "United States Government Work" under the
16     terms of the United States Copyright Act.  It was written as part of
17     the author's official duties as a United States Government employee
18     and thus cannot be copyrighted.  This software/database is freely
19     available to the public for use. The National Library of Medicine and
20     the U.S. Government have not placed any restriction on its use or
21     reproduction.
22 
23     Although all reasonable efforts have been taken to ensure the accuracy
24     and reliability of the software and data, the NLM and the U.S.
25     Government do not and cannot warrant the performance or results that
26     may be obtained by using this software or data. The NLM and the U.S.
27     Government disclaim all warranties, express or implied, including
28     warranties of performance, merchantability or fitness for any
29     particular purpose.
30 
31     Please cite the author in any work or product based on this material.
32 
33    ***************************************************************************
34 
35  File Name:  $RCSfile: setsts.c,v $
36 
37   Author:  Sergei Shavirin
38 
39   Version Creation Date: 12/19/1996
40 
41   $Revision: 6.0 $
42 
43   File Description:
44           Main program for formatting databases of Electronic PCR
45 
46   $Log: setsts.c,v $
47   Revision 6.0  1997/08/25 18:20:40  madden
48   Revision changed to 6.0
49 
50   Revision 5.1  1997/05/23 15:28:21  shavirin
51   Initial revision
52 
53 
54 *****************************************************************************/
55 
56 #include <ncbi.h>
57 #include <stsutil.h>
58 
59 #define RealAddress(x)  (MMAddress + ((Int4)x))
60 #define MemMapFileName "sts.map" /* STS map file with initialized hash info */
61 
62 typedef struct STSHash {
63   Int4 offset;
64   Int4 organism;
65   Int4 len;
66   CharPtr pr1;
67   CharPtr pr2;
68   struct STSHash *next;
69 } STSHash, PNTR STSHashPtr;
70 
71 /* Functions used to create STS map file */
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 extern STSHashPtr PNTR InitHashTable(STSDbNamesPtr db_name,
78                                      Int4Ptr StsCount_out,
79                                      Int4Ptr StsInvalid_out);
80 extern Int4 DumpHashTable(STSDbNamesPtr db_name,
81                           STSHashPtr PNTR StsHashTable);
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 /* Static functions */
88 
89 static Int4 CheckHashTable(void);
90 
91 /* Global variables */
92 
93 static CharPtr MMAddress; /* address of MM hash file */
94 
95 #define NUMARGS 4
96 
97 Args dump_args[NUMARGS] = {
98 
99   {"Input STS dump file for formatting (this parameter must be set)",
100    NULL, NULL,NULL,FALSE,'i',ARG_FILE_IN, 0.0,0,NULL},
101   {"Organism Index file",
102    "org.db", NULL,NULL,TRUE,'o',ARG_FILE_IN, 0.0,0,NULL},
103   {"Output STS Map file name",
104    "sts.map", NULL,NULL,TRUE,'m',ARG_FILE_OUT, 0.0,0,NULL},
105   {"Logfile name:",
106    "setsts.log", NULL,NULL,TRUE,'l',ARG_FILE_OUT, 0.0,0,NULL}
107 };
108 
109 #define StsName     (CharPtr)      dump_args[0].strvalue
110 #define OrgName     (CharPtr)      dump_args[1].strvalue
111 #define MapName     (CharPtr)      dump_args[2].strvalue
112 #define LogFileName (CharPtr)      dump_args[3].strvalue
113 
Main(void)114 Int2 Main(void)
115 {
116   Int4 StsCount = 0, StsInvalid = 0;
117   STSHashPtr PNTR StsHashTable;
118   STSDbNamesPtr db_name;
119 
120   if (!GetArgs("setsts",NUMARGS,dump_args)) {
121     return 1;
122   }
123   if (!ErrSetLog (LogFileName)) {
124     ErrShow();
125   } else {
126     ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON);
127   }
128 
129   db_name = MemNew(sizeof(STSDbNames));
130   db_name->sts_db_name = StsName;
131   db_name->sts_map_name = MapName;
132   db_name->sts_org_name = OrgName;
133 
134   if((StsHashTable = InitHashTable(db_name, &StsCount, &StsInvalid)) == NULL) {
135     ErrLogPrintf("Error in initialization of Hash Table. Exiting...");
136     return 1;
137   }
138 
139   ErrLogPrintf("Invalid database entries found: %d\n",   StsInvalid);
140   ErrLogPrintf("Hash table created with %d sequences\n", StsCount);
141 
142   if((StsCount = DumpHashTable(db_name, StsHashTable)) < 0) {
143     ErrLogPrintf("Error in dumping of Hash Table. Exiting...");
144     return 1;
145   }
146 
147   ErrLogPrintf("Map file dumped with %d sequences\n", StsCount);
148   return 0;
149 }
150 
CheckHashTable(void)151 static Int4 CheckHashTable(void)
152 {
153   register Int4 i;
154   STSHashPtr sts;
155   Nlm_MemMapPtr mmp;
156   Uint4Ptr int_ptr, tmp_ptr;
157   Int4 TotalCount =0;
158 
159   /* Now, lets try to read this map file */
160 
161   mmp = Nlm_MemMapInit(MemMapFileName);
162   MMAddress = mmp->mmp_begin;
163   printf("Allocated %d bytes of memory on address %x\n",
164          mmp->file_size, MMAddress);
165   int_ptr = (Uint4Ptr) MMAddress;
166 
167   if((sts = (STSHashPtr)(RealAddress(int_ptr[7733]))) ==
168      (STSHashPtr)MMAddress) {
169     printf("No entries found\n");
170     exit(1);
171   }
172 
173   printf("Off = %d Org = %d Len = %d "
174          "Pr1=%d Pr2=%d Next= %d\n",
175          sts->offset,
176          sts->organism,
177          sts->len, sts->pr1,
178          sts->pr2, sts->next );
179 
180   printf("Primer1 = %s, Primer2 = %s\n",
181          RealAddress(sts->pr1),
182          RealAddress(sts->pr2)
183          );
184 
185   tmp_ptr = (Uint4Ptr)(RealAddress(int_ptr[7733]));
186 
187   printf("\nMM Start address %x\n", MMAddress);
188 
189   printf("\nRelative address %lu, Real Address %x\n",
190          int_ptr[0], tmp_ptr);
191 
192   for(i=0; i < 120; i++) {
193     printf("%ld ", tmp_ptr[i]);
194   }
195 
196   printf("\nNext STS:\n");
197 
198   tmp_ptr = (Uint4Ptr)(RealAddress(sts->next));
199 
200   printf("\nRelative address %lu, Real Address %x\n",
201          sts->next, tmp_ptr);
202 
203   for(i=0; i < 12; i++) {
204     printf("%ld ", tmp_ptr[i]);
205     fflush(stdout);
206   }
207 
208   printf("\n");
209 
210 
211   sts = (STSHashPtr)(MMAddress + (Int4)(sts->next));
212 
213   printf("\n Offset = %d Organism = %d Length = %d\n",
214          sts->offset,
215          sts->organism,
216          sts->len);
217 
218   return TotalCount;
219 }
220