53{
54
56
58
59
60 if(indexFile == NULL)
61 {
63 }
64
65
66
67
68 char magic[4];
69 if(
ifread(indexFile, magic, 4) != 4)
70 {
71
73 }
74
75
76 if (magic[0] != 'T' || magic[1] != 'B' || magic[2] != 'I' || magic[3] != 1)
77 {
78
80 }
81
82
83
84 if(
ifread(indexFile, &n_ref, 4) != 4)
85 {
86
88 }
89
90
91 myRefs.resize(n_ref);
92
93
94 if(
ifread(indexFile, &myFormat,
sizeof(myFormat)) !=
sizeof(myFormat))
95 {
96
98 }
99
100
101 uint32_t l_nm;
102
103 if(
ifread(indexFile, &l_nm,
sizeof(l_nm)) !=
sizeof(l_nm))
104 {
105
107 }
108
109
110 myChromNamesBuffer = new char[l_nm];
111 if(
ifread(indexFile, myChromNamesBuffer, l_nm) != l_nm)
112 {
114 }
115 myChromNamesVector.resize(n_ref);
116
117
118 bool prevNull = true;
119 int chromIndex = 0;
120 for(uint32_t i = 0; i < l_nm; i++)
121 {
122 if(chromIndex >= n_ref)
123 {
124
125
126 break;
127 }
128 if(prevNull == true)
129 {
130 myChromNamesVector[chromIndex++] = myChromNamesBuffer + i;
131 prevNull = false;
132 }
133 if(myChromNamesBuffer[i] == '\0')
134 {
135 prevNull = true;
136 }
137 }
138
139 for(int refIndex = 0; refIndex < n_ref; refIndex++)
140 {
141
142 Reference* ref = &(myRefs[refIndex]);
143
144
145 if(
ifread(indexFile, &(ref->n_bin), 4) != 4)
146 {
147
148
150 }
151
152
153 ref->bins.resize(ref->n_bin + 1);
154
155
156 for(int binIndex = 0; binIndex < ref->n_bin; binIndex++)
157 {
158 uint32_t binNumber;
159
160
161 if(
ifread(indexFile, &(binNumber), 4) != 4)
162 {
163
164
166 }
167
168
169
170 Bin* binPtr = &(ref->bins[binIndex]);
171 binPtr->bin = binNumber;
172
173
174 if(
ifread(indexFile, &(binPtr->n_chunk), 4) != 4)
175 {
176
177
179 }
180
181
182
183 uint32_t sizeOfChunkList = binPtr->n_chunk *
sizeof(
Chunk);
184 binPtr->chunks = (
Chunk*)malloc(sizeOfChunkList);
185 if(
ifread(indexFile, binPtr->chunks, sizeOfChunkList) != sizeOfChunkList)
186 {
187
188
190 }
191 }
192
193
194 if(
ifread(indexFile, &(ref->n_intv), 4) != 4)
195 {
196
197 ref->n_intv = 0;
198
200 }
201
202
203 uint32_t linearIndexSize = ref->n_intv * sizeof(uint64_t);
204 ref->ioffsets = (uint64_t*)malloc(linearIndexSize);
205 if(
ifread(indexFile, ref->ioffsets, linearIndexSize) != linearIndexSize)
206 {
207
208
210 }
211 }
212
213
215}
@ SUCCESS
method completed successfully.
@ FAIL_IO
method failed due to an I/O issue.
@ FAIL_PARSE
failed to parse a record/header - invalid format.
void resetIndex()
Reset the member data for a new index file.