File: GridTable.cpp

package info (click to toggle)
ray 2.3.1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,008 kB
  • sloc: cpp: 49,973; sh: 339; makefile: 281; python: 168
file content (267 lines) | stat: -rw-r--r-- 5,371 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
    Ray -- Parallel genome assemblies for parallel DNA sequencing
    Copyright (C) 2011, 2012, 2013 Sébastien Boisvert

	http://DeNovoAssembler.SourceForge.Net/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You have received a copy of the GNU General Public License
    along with this program (gpl-3.0.txt).  
	see <http://www.gnu.org/licenses/>

*/

#include "GridTable.h"

#include <code/KmerAcademyBuilder/Kmer.h>
#include <code/Mock/common_functions.h>

#include <RayPlatform/core/OperatingSystem.h>
#include <RayPlatform/cryptography/crypto.h>

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>

void GridTable::constructor(int rank,Parameters*parameters){

	#ifdef CONFIG_ASSERT
	assert(parameters!=NULL);
	#endif

	m_parameters=parameters;
	m_size=0;

	showMemoryUsage(rank);

	uint64_t buckets=m_parameters->getNumberOfBuckets();
	int bucketsPerGroup=m_parameters->getNumberOfBucketsPerGroup();
	double loadFactorThreshold=m_parameters->getLoadFactorThreshold();

	m_hashTable.constructor(buckets,"RAY_MALLOC_TYPE_GRID_TABLE",
		m_parameters->showMemoryAllocations(),m_parameters->getRank(),
		bucketsPerGroup,loadFactorThreshold
		);

	if(m_parameters->hasOption("-hash-table-verbosity"))
		m_hashTable.toggleVerbosity();

	m_inserted=false;

	if(m_parameters->showMemoryUsage()){
		showMemoryUsage(rank);
	}

	m_findOperations=0;

	m_verbose=false;
}

void GridTable::printStatus(){

	uint64_t buckets=m_parameters->getNumberOfBuckets();
	int bucketsPerGroup=m_parameters->getNumberOfBucketsPerGroup();
	double loadFactorThreshold=m_parameters->getLoadFactorThreshold();

	if(m_parameters->hasOption("-hash-table-verbosity")){
		cout<<"[GridTable] buckets="<<buckets<<" bucketsPerGroup="<<bucketsPerGroup;
		cout<<" loadFactorThreshold="<<loadFactorThreshold<<endl;
	}
}

LargeCount GridTable::size(){
	return m_size;
}

Vertex*GridTable::find(Kmer*key){
	#ifdef CONFIG_ASSERT
	assert(key!=NULL);
	#endif

	Kmer lowerKey=key->complementVertex(m_parameters->getWordSize(),m_parameters->getColorSpaceMode());
	if(key->isLower(&lowerKey)){
		lowerKey=*key;
	}

	m_findOperations++;

	// show some love on screen
	if(m_verbose && m_findOperations%100000==0){
		m_hashTable.toggleVerbosity();
	}

	Vertex*vertex= m_hashTable.find(&lowerKey);

	// turns off verbosity
	if(m_verbose && m_findOperations%100000==0){
		m_hashTable.toggleVerbosity();
	}

	return vertex;
}

Vertex*GridTable::insert(Kmer*key){
	#ifdef CONFIG_ASSERT
	assert(key!=NULL);
	#endif

	#ifdef CONFIG_ASSERT
	assert(m_parameters!=NULL);
	#endif

	Kmer lowerKey=key->complementVertex(m_parameters->getWordSize(),m_parameters->getColorSpaceMode());
	if(key->isLower(&lowerKey)){
		lowerKey=*key;
	}

	LargeCount sizeBefore=m_hashTable.size();
	Vertex*entry=m_hashTable.insert(&lowerKey);
	m_inserted=m_hashTable.size()>sizeBefore;

	if(m_inserted){
		m_size+=2;
	}

	return entry;
}

bool GridTable::inserted(){
	return m_inserted;
}

bool GridTable::isAssembledByGreaterRank(Kmer*a,Rank origin){
	#ifdef CONFIG_ASSERT
	assert(a!=NULL);
	#endif

	Vertex*entry=find(a);
	
	#ifdef CONFIG_ASSERT
	assert(entry!=NULL);
	#endif

	return entry->isAssembledByGreaterRank(origin);
}

bool GridTable::isAssembled(Kmer*a){
	#ifdef CONFIG_ASSERT
	assert(a!=NULL);
	#endif

	Vertex*entry=find(a);
	
	#ifdef CONFIG_ASSERT
	assert(entry!=NULL);
	#endif

	return entry->isAssembled();
}

void GridTable::addRead(Kmer*a,ReadAnnotation*e){

	#ifdef CONFIG_ASSERT
	assert(a!=NULL);
	assert(e!=NULL);
	#endif

	Vertex*i=find(a);
	i->addRead(a,e);

	#ifdef CONFIG_ASSERT
	ReadAnnotation*reads=i->getReads(a);
	assert(reads!=NULL);
	#endif
}

ReadAnnotation*GridTable::getReads(Kmer*a){

	#ifdef CONFIG_ASSERT
	assert(a!=NULL);
	#endif

	Vertex*i=find(a);
	if(i==NULL){
		return NULL;
	}

	ReadAnnotation*reads=i->getReads(a);
	return reads;
}

void GridTable::addDirection(Kmer*a,Direction*d){
	#ifdef CONFIG_ASSERT
	assert(a!=NULL);
	assert(d!=NULL);

	// the commented code was used when non-NULL pointers were invalid
	// according to /proc/self/maps
	//
	//Kmer copy1=*a;
	//Direction copy2=*d;
	#endif

	Vertex*i=find(a);

	#ifdef CONFIG_ASSERT
	assert(i!=NULL);
	#endif

	i->addDirection(a,d);
}

vector<Direction> GridTable::getDirections(Kmer*a){
	#ifdef CONFIG_ASSERT
	assert(a!=NULL);
	#endif

	Vertex*i=find(a);

	if(i==NULL){
		vector<Direction> p;
		return p;
	}

	#ifdef CONFIG_ASSERT
	assert(i!=NULL);

	/* do a copy to track to check for a segmentation fault */
	Vertex copy=*i;
	assert(copy.getVertexCoverage() >= 1);
	#endif

	return i->getDirections(a);
}

void GridTable::clearDirections(Kmer*a){
	#ifdef CONFIG_ASSERT
	assert(a!=NULL);
	#endif

	Vertex*i=find(a);

	#ifdef CONFIG_ASSERT
	assert(i!=NULL);
	#endif
	
	i->clearDirections(a);
}

MyHashTable<Kmer,Vertex>*GridTable::getHashTable(){
	return &m_hashTable;
}

void GridTable::printStatistics(){
	m_hashTable.printProbeStatistics();
}

void GridTable::completeResizing(){
	m_hashTable.completeResizing();
}