annotate mrfast-2.1.0.4/HashTable.c @ 0:7b3dc85dc7fd

Uploaded mrfast source tarball
author calkan
date Tue, 21 Feb 2012 10:29:47 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
1 /*
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
2 * Copyright (c) <2008 - 2012>, University of Washington, Simon Fraser University
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
3 * All rights reserved.
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
4 *
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without modification,
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
6 * are permitted provided that the following conditions are met:
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
7 *
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
8 * Redistributions of source code must retain the above copyright notice, this list
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
9 * of conditions and the following disclaimer.
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
10 * - Redistributions in binary form must reproduce the above copyright notice, this
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
11 * list of conditions and the following disclaimer in the documentation and/or other
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
12 * materials provided with the distribution.
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
13 * - Neither the names of the University of Washington, Simon Fraser University,
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
14 * nor the names of its contributors may be
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
15 * used to endorse or promote products derived from this software without specific
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
16 * prior written permission.
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
17 *
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
29 */
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
30
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
31 /*
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
32 Authors:
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
33 Farhad Hormozdiari
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
34 Faraz Hach
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
35 Can Alkan
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
36 Emails:
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
37 farhadh AT uw DOT edu
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
38 fhach AT cs DOT sfu DOT ca
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
39 calkan AT uw DOT edu
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
40 */
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
41
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
42
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
43
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
44 #include <stdio.h>
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
45 #include <stdlib.h>
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
46 #include <string.h>
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
47 #include <math.h>
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
48 #include "Common.h"
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
49 #include "RefGenome.h"
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
50 #include "HashTable.h"
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
51 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
52 FILE *_ih_fp = NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
53 IHashTable *_ih_hashTable = NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
54 int _ih_maxHashTableSize = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
55 char *_ih_refGen = NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
56 char *_ih_refGenName = NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
57 long long _ih_memUsage = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
58 int _ih_refGenOff = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
59 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
60
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
61 int hashVal(char *seq)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
62 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
63 int i=0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
64 int val=0, numericVal=0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
65
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
66 while(i<WINDOW_SIZE)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
67 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
68 switch (seq[i])
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
69 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
70 case 'A':
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
71 numericVal = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
72 break;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
73 case 'C':
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
74 numericVal = 1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
75 break;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
76 case 'G' :
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
77 numericVal = 2;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
78 break;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
79 case 'T':
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
80 numericVal = 3;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
81 break;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
82 default:
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
83 return -1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
84 break;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
85 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
86 val = (val << 2)|numericVal;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
87 i++;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
88 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
89 return val;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
90 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
91 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
92 void freeIHashTableContent(IHashTable *hashTable, unsigned int maxSize)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
93 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
94 int i=0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
95 for (i=0; i<maxSize; i++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
96 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
97 if (hashTable[i].locs != NULL)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
98 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
99 freeMem(hashTable[i].locs, (hashTable[i].locs[0]+1)*(sizeof(unsigned int)));
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
100 hashTable[i].locs = NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
101 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
102 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
103 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
104 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
105 void initSavingIHashTable(char *fileName)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
106 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
107 int tmp;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
108 _ih_fp = fileOpen(fileName, "w");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
109 unsigned char bIndex = 0; // Bisulfite Index
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
110
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
111 // First Two bytes are indicating the type of the index & window size
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
112 tmp = fwrite(&bIndex, sizeof(bIndex), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
113 tmp = fwrite(&WINDOW_SIZE, sizeof(WINDOW_SIZE), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
114
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
115 if (tmp == 0)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
116 fprintf(stderr, "Write error while initializing hash table.\n");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
117
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
118 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
119 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
120 void finalizeSavingIHashTable()
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
121 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
122 fclose(_ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
123 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
124 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
125 void saveIHashTable(IHashTable *hashTable, unsigned int size, unsigned int maxSize, char *refGen, char *refGenName, int refGenOffset)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
126 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
127 int tmp;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
128
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
129 // Every Chunk starts with a byte indicating whether it has extra info;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
130 unsigned char extraInfo = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
131 tmp = fwrite (&extraInfo, sizeof(extraInfo), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
132
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
133 short len = strlen(refGenName);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
134 tmp = fwrite(&len, sizeof(len), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
135 tmp = fwrite(refGenName, sizeof(char), len, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
136
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
137 tmp = fwrite(&refGenOffset, sizeof(refGenOffset), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
138
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
139 unsigned int refGenLength = strlen(refGen);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
140 tmp = fwrite(&refGenLength, sizeof(refGenLength), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
141
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
142 tmp = fwrite(refGen, sizeof(char), refGenLength, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
143 tmp = fwrite(&size, sizeof(size), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
144
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
145 int i=0,j=0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
146 unsigned char cnt=0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
147 for (i=0; i<maxSize; i++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
148 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
149 if (hashTable[i].locs != NULL)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
150 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
151 tmp = fwrite(&i, sizeof(i), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
152
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
153 if (hashTable[i].locs[0] < 250)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
154 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
155 cnt = hashTable[i].locs[0];
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
156 tmp = fwrite(&cnt, sizeof(cnt), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
157 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
158 else
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
159 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
160 cnt =0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
161 tmp = fwrite (&cnt, sizeof(cnt), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
162 tmp = fwrite (&(hashTable[i].locs[0]), sizeof(hashTable[i].locs[0]), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
163 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
164
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
165 for (j=1; j<=hashTable[i].locs[0]; j++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
166 tmp = fwrite(&(hashTable[i].locs[j]), sizeof(hashTable[i].locs[j]), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
167 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
168 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
169
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
170 if (tmp == 0)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
171 fprintf(stderr, "Write error while saving hash table.\n");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
172 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
173 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
174 unsigned int addIHashTableLocation(IHashTable *hashTable, int hv, int location)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
175 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
176 unsigned int sizeInc = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
177
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
178 if (hashTable[hv].locs == NULL)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
179 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
180 sizeInc = 1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
181 hashTable[hv].locs = getMem (sizeof(unsigned int)*2);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
182 hashTable[hv].locs[0]=1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
183 hashTable[hv].locs[1]=location;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
184 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
185 else
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
186 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
187 int size = hashTable[hv].locs[0];
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
188 int i;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
189 unsigned int *tmp = getMem( (size + 2) * sizeof(unsigned int) );
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
190
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
191 for (i = 0; i <= size; i++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
192 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
193 tmp[i] = hashTable[hv].locs[i];
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
194 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
195 size++;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
196 tmp[0] = size;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
197 tmp[size] = location;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
198
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
199 freeMem(hashTable[hv].locs, (hashTable[hv].locs[0]*(sizeof(unsigned int))));
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
200 hashTable[hv].locs = tmp;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
201 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
202 return sizeInc;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
203 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
204 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
205 void generateIHashTable(char *fileName, char *indexName)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
206 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
207 double startTime = getTime();
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
208 unsigned int hashTableSize = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
209 unsigned int hashTableMaxSize = pow(4, WINDOW_SIZE);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
210 IHashTable *hashTable = getMem(sizeof(IHashTable)*hashTableMaxSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
211 char *refGenName;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
212 char *refGen;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
213 int refGenOff = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
214 int i, hv, l, flag;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
215
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
216
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
217 for ( i = 0; i < hashTableMaxSize; i++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
218 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
219 hashTable[i].locs = NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
220 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
221
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
222 //Loading Fasta File
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
223 if (!initLoadingRefGenome(fileName))
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
224 return;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
225 initSavingIHashTable(indexName);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
226
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
227 fprintf(stdout, "Generating Index from %s", fileName);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
228 fflush(stdout);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
229
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
230 char *prev = getMem (CONTIG_NAME_SIZE);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
231 prev[0]='\0';
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
232
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
233 do
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
234 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
235 flag = loadRefGenome (&refGen, &refGenName, &refGenOff);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
236
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
237 if ( strcmp(prev, refGenName) != 0)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
238 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
239 fprintf(stdout, "\n - %s ", refGenName);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
240 fflush(stdout);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
241 sprintf(prev, "%s", refGenName);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
242 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
243 else
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
244 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
245 fprintf(stdout, ".");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
246 fflush(stdout);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
247 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
248
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
249 l = strlen(refGen) - WINDOW_SIZE;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
250
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
251 for (i=0; i < l; i++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
252 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
253 hv = hashVal(refGen + i);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
254 if (hv != -1)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
255 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
256 hashTableSize += addIHashTableLocation (hashTable, hv, i+1);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
257 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
258 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
259
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
260 saveIHashTable(hashTable, hashTableSize, hashTableMaxSize, refGen, refGenName, refGenOff);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
261 freeIHashTableContent(hashTable, hashTableMaxSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
262 hashTableSize = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
263 } while (flag);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
264
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
265 freeMem(prev, CONTIG_NAME_SIZE);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
266 freeMem(hashTable, sizeof(IHashTable)*hashTableMaxSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
267
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
268 finalizeLoadingRefGenome();
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
269 finalizeSavingIHashTable();
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
270
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
271 fprintf(stdout, "\nDONE in %0.2fs!\n", (getTime()-startTime));
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
272 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
273
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
274 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
275 void finalizeLoadingIHashTable()
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
276 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
277 freeIHashTableContent(_ih_hashTable, _ih_maxHashTableSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
278 freeMem(_ih_hashTable, sizeof(IHashTable)* _ih_maxHashTableSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
279 freeMem(_ih_refGen, strlen(_ih_refGen)+1) ;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
280 freeMem(_ih_refGenName, strlen(_ih_refGenName)+1);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
281 fclose(_ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
282 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
283
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
284 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
285 int loadIHashTable(double *loadTime, int errThreshould)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
286 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
287 double startTime = getTime();
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
288 unsigned char extraInfo = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
289 short len;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
290 unsigned int refGenLength;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
291 unsigned int hashTableSize;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
292 unsigned int tmpSize;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
293 int tmp;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
294 int i=0,j=0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
295
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
296 if ( fread(&extraInfo, sizeof(extraInfo), 1, _ih_fp) != sizeof(extraInfo) )
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
297 return 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
298
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
299 freeIHashTableContent(_ih_hashTable, _ih_maxHashTableSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
300 freeMem(_ih_refGen, strlen(_ih_refGen)+1) ;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
301 freeMem(_ih_refGenName, strlen(_ih_refGenName)+1);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
302
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
303 // Reading Chr Name
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
304 tmp = fread(&len, sizeof(len), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
305 if (tmp == 0){
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
306 fprintf(stderr, "Read error while loading hash table.\n");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
307 exit(0);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
308 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
309
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
310 _ih_refGenName = getMem(sizeof(char)* (len+1));
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
311 tmp = fread(_ih_refGenName, sizeof(char), len, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
312 _ih_refGenName [len] ='\0';
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
313
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
314 tmp = fread(&_ih_refGenOff, sizeof (_ih_refGenOff), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
315
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
316 // Reading Size and Content of Ref Genome
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
317 tmp = fread(&refGenLength, sizeof(refGenLength), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
318 _ih_refGen = getMem(sizeof(char)*(refGenLength+1));
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
319 tmp = fread(_ih_refGen, sizeof(char), refGenLength, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
320 _ih_refGen[refGenLength]='\0';
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
321
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
322 //Reading Hashtable Size and Content
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
323 tmp = fread(&hashTableSize, sizeof(hashTableSize), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
324
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
325 unsigned int hv;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
326 unsigned char cnt=0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
327 unsigned int index = 1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
328 unsigned int tmpValue = 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
329 for (i=0; i<hashTableSize; i++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
330 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
331 index = 1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
332 tmp = fread(&hv, sizeof(hv), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
333 tmp = fread(&cnt, sizeof(cnt), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
334
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
335 if (cnt>0)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
336 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
337 tmpSize = cnt;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
338 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
339 else
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
340 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
341 tmp = fread(&tmpSize, sizeof(tmpSize), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
342 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
343
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
344 _ih_hashTable[hv].locs = getMem( sizeof(unsigned int)* (tmpSize+1) );
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
345 _ih_hashTable[hv].locs[0] = tmpSize;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
346
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
347 /* for (j=1; j<=tmpSize; j++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
348 tmp = fread(&(_ih_hashTable[hv].locs[j]), sizeof(_ih_hashTable[hv].locs[j]), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
349 */
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
350
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
351 if(tmpSize != 0)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
352 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
353 tmp = fread(&(_ih_hashTable[hv].locs[index]), sizeof(_ih_hashTable[hv].locs[index]), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
354 index++;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
355 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
356
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
357 for (j=2; j<=tmpSize; j++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
358 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
359 tmp = fread(&tmpValue, sizeof(_ih_hashTable[hv].locs[index-1]), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
360 if(abs(tmpValue-_ih_hashTable[hv].locs[index-1]) > errThreshould)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
361 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
362 _ih_hashTable[hv].locs[index] = tmpValue;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
363 index++;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
364 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
365 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
366 _ih_hashTable[hv].locs[0] = index-1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
367 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
368 *loadTime = getTime()-startTime;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
369 return 1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
370 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
371 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
372 unsigned int *getIHashTableCandidates(int hv)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
373 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
374 if ( hv != -1 )
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
375 return _ih_hashTable[hv].locs;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
376 else
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
377 return NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
378 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
379 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
380 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
381 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
382 void configHashTable()
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
383 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
384 if (WINDOW_SIZE <= 15)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
385 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
386 generateHashTable = &generateIHashTable;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
387 loadHashTable = &loadIHashTable;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
388 finalizeLoadingHashTable = &finalizeLoadingIHashTable;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
389 getCandidates = &getIHashTableCandidates;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
390 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
391 else
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
392 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
393
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
394
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
395 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
396 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
397 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
398 int initLoadingHashTable(char *fileName)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
399 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
400 int i;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
401 unsigned char bsIndex;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
402 int tmp;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
403
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
404 _ih_fp = fileOpen(fileName, "r");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
405
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
406 if (_ih_fp == NULL)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
407 return 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
408
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
409 tmp = fread(&bsIndex, sizeof(bsIndex), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
410
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
411 if (tmp == 0){
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
412 fprintf(stderr, "Read error while inilializing hash table loading.\n");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
413 exit(0);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
414 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
415
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
416 if (bsIndex)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
417 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
418 fprintf(stdout, "Error: Wrong Type of Index indicated");
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
419 return 0;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
420 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
421
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
422 tmp = fread(&WINDOW_SIZE, sizeof(WINDOW_SIZE), 1, _ih_fp);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
423
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
424 configHashTable();
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
425
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
426 if (_ih_maxHashTableSize != pow(4, WINDOW_SIZE))
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
427 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
428
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
429 if (_ih_hashTable != NULL)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
430 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
431 freeIHashTableContent(_ih_hashTable, _ih_maxHashTableSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
432 freeMem(_ih_hashTable, sizeof(IHashTable)* _ih_maxHashTableSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
433 freeMem(_ih_refGen, strlen(_ih_refGen)+1) ;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
434 freeMem(_ih_refGenName, strlen(_ih_refGenName)+1);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
435 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
436
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
437 _ih_maxHashTableSize = pow(4, WINDOW_SIZE);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
438
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
439 _ih_hashTable = getMem (sizeof(IHashTable) * _ih_maxHashTableSize);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
440 for (i=0; i<_ih_maxHashTableSize; i++)
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
441 _ih_hashTable[i].locs = NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
442 _ih_refGen = getMem(1);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
443 _ih_refGen[0]='\0';
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
444 _ih_refGenName = getMem(1);
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
445 _ih_refGenName[0] = '\0';
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
446 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
447
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
448 return 1;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
449 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
450 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
451 char *getRefGenome()
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
452 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
453 return _ih_refGen;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
454
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
455 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
456 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
457 char *getRefGenomeName()
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
458 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
459 return _ih_refGenName;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
460
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
461 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
462 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
463 int getRefGenomeOffset()
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
464 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
465 return _ih_refGenOff;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
466
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
467 }
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
468 /**********************************************/
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
469 HashTable *getHashTable()
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
470 {
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
471 return NULL;
7b3dc85dc7fd Uploaded mrfast source tarball
calkan
parents:
diff changeset
472 }