File: VirtualKmerColor.cpp

package info (click to toggle)
ray 2.3.1-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,960 kB
  • sloc: cpp: 49,973; sh: 339; makefile: 278; python: 168
file content (164 lines) | stat: -rw-r--r-- 3,799 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
/*
 	Ray
    Copyright (C) 2010, 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 "VirtualKmerColor.h"

#include <iostream>
using namespace std;
#ifdef CONFIG_ASSERT
#include <assert.h>
#endif

VirtualKmerColor::VirtualKmerColor(){
	clear();
}

void VirtualKmerColor::clear(){
	
	m_references=0;
	m_colors.clear();
	m_hash=0;

	#ifdef CONFIG_ASSERT
	assert(getNumberOfReferences()==0);
	#endif

	#ifdef CONFIG_ASSERT
	assert(getNumberOfPhysicalColors()==0);
	#endif
}

void VirtualKmerColor::incrementReferences(){
	m_references++;
}

void VirtualKmerColor::decrementReferences(){
	m_references--;

	#ifdef CONFIG_ASSERT
	assert(m_references>=0);
	#endif
}

void VirtualKmerColor::addPhysicalColor(PhysicalKmerColor color){

	#ifdef CONFIG_ASSERT
	assert(!hasPhysicalColor(color));
	#endif

	m_colors.insert(color);
}

LargeCount VirtualKmerColor::getNumberOfReferences(){
	return m_references;
}

set<PhysicalKmerColor>*VirtualKmerColor::getPhysicalColors(){
	return & m_colors;
}

bool VirtualKmerColor::hasPhysicalColor(PhysicalKmerColor color){
	return m_colors.count(color)>0;
}

bool VirtualKmerColor::hasPhysicalColors(set<PhysicalKmerColor>*colors){

	// verify the colors
	for(set<PhysicalKmerColor>::iterator i=colors->begin();
		i!=colors->end();i++){

		PhysicalKmerColor physicalColor=*i;

		if(!hasPhysicalColor(physicalColor)){
			return false;
		}
	}

	return true;
}

void VirtualKmerColor::setHash(uint64_t hash){
	m_hash=hash;
}

uint64_t VirtualKmerColor::getCachedHashValue(){
	return m_hash;
}

int VirtualKmerColor::getNumberOfPhysicalColors(){
	return getPhysicalColors()->size();
}

bool VirtualKmerColor::virtualColorHasAllPhysicalColorsOf(VirtualKmerColor*a,PhysicalKmerColor color){
	
	// we are searching for a virtual color with only the physical color <color> and 
	// the physical colors of VirtualKmerColor <a>

	// this don't have the physical color <color>
	if(!hasPhysicalColor(color)){
		//cout<<"bah don't have color "<<color<<endl;
		//
		return false;
	}

	// this does not have the correct number of physical colors
	if((a->getNumberOfPhysicalColors()+1) != getNumberOfPhysicalColors()){
/*
		cout<<" mew wrong count"<<endl;
		cout<<"Expected: "<<(a->getNumberOfPhysicalColors()+1)<<" Actual: "<<getNumberOfPhysicalColors()<<endl;
		cout<<"a->getNumberOfPhysicalColors()-> "<<a->getNumberOfPhysicalColors()<<endl;
*/

		return false;
	}

	// we don't need to check the hash because it was done
	// upstream already, hopefully...
	// anyway, the class VirtualKmerColor does not have the methods 
	// to do hash checking
	
	// the current virtual color does not have all the required 
	// physical colors
	if(!hasPhysicalColors(a->getPhysicalColors())){
		//cout<<"ah don't have all physical colors"<<endl;
		//
		return false;
	}

	return true;
}

void VirtualKmerColor::copyPhysicalColors(VirtualKmerColor*a){
	set<PhysicalKmerColor>*colors=a->getPhysicalColors();

	addPhysicalColors(colors);
}

void VirtualKmerColor::addPhysicalColors(set<PhysicalKmerColor>*colors){

	for(set<PhysicalKmerColor>::iterator i=colors->begin();
		i!=colors->end();i++){

		PhysicalKmerColor color=*i;

		addPhysicalColor(color);
	}
}