File: ExtensionData.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 (159 lines) | stat: -rw-r--r-- 4,077 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
/*
 	Ray
    Copyright (C) 2011, 2012 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 "ExtensionData.h"

#include <RayPlatform/structures/SplayTreeIterator.h>
#include <RayPlatform/cryptography/crypto.h>

#include <string.h>
#include <sstream>
using namespace std;

void ExtensionData::constructor(Parameters*parameters){
	m_parameters=parameters;
	m_numberOfBins=1;
	m_database=(SplayTree<ReadHandle,ExtensionElement>*)__Malloc(m_numberOfBins*sizeof(SplayTree<ReadHandle,ExtensionElement>),
		"RAY_MALLOC_TYPE_EXTENSION_DATA_TREES",m_parameters->showMemoryAllocations());
	createStructures();

	ostringstream prefixFull;
	prefixFull<<m_parameters->getMemoryPrefix()<<"_ExtensionData";
	m_allocator.constructor(4194304,"RAY_MALLOC_TYPE_EXTENSION_DATA_ALLOCATOR",m_parameters->showMemoryAllocations());
}

void ExtensionData::createStructures(){
	m_EXTENSION_extension.clear();
	m_repeatedValues.clear();
	m_extensionCoverageValues.clear();
	m_EXTENSION_coverages.clear();
	m_EXTENSION_readsInRange.clear();
	m_expirations.clear();
	m_pairedReadsWithoutMate.clear();

	for(int i=0;i<m_numberOfBins;i++){
		m_database[i].constructor();
	}
}

void ExtensionData::destroyStructures(Profiler*m_profiler){

	MACRO_COLLECT_PROFILING_INFORMATION();

	m_EXTENSION_extension.clear();
	m_extensionCoverageValues.clear();
	m_repeatedValues.clear();

	MACRO_COLLECT_PROFILING_INFORMATION();

	m_EXTENSION_coverages.clear();
	m_EXTENSION_readsInRange.clear();

	MACRO_COLLECT_PROFILING_INFORMATION();

	m_pairedReadsWithoutMate.clear();

	MACRO_COLLECT_PROFILING_INFORMATION();

	m_expirations.clear();

	MACRO_COLLECT_PROFILING_INFORMATION();

	for(int i=0;i<m_numberOfBins;i++){
		m_database[i].clear();
	}

	MACRO_COLLECT_PROFILING_INFORMATION();
}

void ExtensionData::resetStructures(Profiler*m_profiler){
	MACRO_COLLECT_PROFILING_INFORMATION();

	m_allocator.reset();

	MACRO_COLLECT_PROFILING_INFORMATION();

	destroyStructures(m_profiler);

	MACRO_COLLECT_PROFILING_INFORMATION();
}

void ExtensionData::destructor(){
	destroyStructures(NULL);
	__Free(m_database,"RAY_MALLOC_TYPE_EXTENSION_DATA_TREES",m_parameters->showMemoryAllocations());
}

ExtensionElement*ExtensionData::getUsedRead(ReadHandle a){
	int bin=0;
	SplayNode<ReadHandle,ExtensionElement>*node=m_database[bin].find(a,false);
	if(node!=NULL && node->getValue()->isActive()){
		return node->getValue();
	}
	return NULL;
}

ExtensionElement*ExtensionData::addUsedRead(ReadHandle a){
	bool val;
	int bin=0;

	SplayNode<ReadHandle,ExtensionElement>*node=m_database[bin].find(a,false);

	if(node!=NULL){
		ExtensionElement*element=node->getValue();
		element->activate();
		element->increaseNumberOfTries();

		return element;
	}

	ExtensionElement*element=m_database[bin].insert(a,&m_allocator,&val)->getValue();
	element->constructor();
	element->activate();
	element->increaseNumberOfTries();
	return element;
}

void ExtensionData::removeSequence(ReadHandle a){
	int bin=0;

	SplayNode<ReadHandle,ExtensionElement>*node=m_database[bin].find(a,false);

	if(node!=NULL){
		node->getValue()->deactivate();
		return;
	}

// the line below is useless
	m_database[bin].remove(a,false,&m_allocator);
}

MyAllocator*ExtensionData::getAllocator(){
	return &m_allocator;
}

void ExtensionData::lazyDestructor(){
	SplayTreeIterator<ReadHandle,ExtensionElement> i;
	i.constructor(&(m_database[0]));
	while(i.hasNext()){
		ExtensionElement*element=i.next()->getValue();
		element->deactivate();
	}
}