File: AnnotationFetcher.cpp

package info (click to toggle)
ray 2.3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,264 kB
  • ctags: 6,335
  • sloc: cpp: 49,973; sh: 325; makefile: 278; python: 168
file content (154 lines) | stat: -rw-r--r-- 4,408 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
/*
 *  Ray -- Parallel genome assemblies for parallel DNA sequencing
 *  Copyright (C) 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 "AnnotationFetcher.h"

void AnnotationFetcher::initialize(Parameters*parameters, VirtualCommunicator*virtualCommunicator,
		WorkerHandle identifier, RingAllocator * outboxAllocator,
		MessageTag RAY_MPI_TAG_ASK_VERTEX_PATHS_SIZE,
		MessageTag RAY_MPI_TAG_ASK_VERTEX_PATH
		){

	m_virtualCommunicator = virtualCommunicator;
	m_parameters = parameters;
	m_identifier = identifier;
	m_outboxAllocator = outboxAllocator;
	m_rank = m_parameters->getRank();

	this->RAY_MPI_TAG_ASK_VERTEX_PATHS_SIZE = RAY_MPI_TAG_ASK_VERTEX_PATHS_SIZE;
	this->RAY_MPI_TAG_ASK_VERTEX_PATH = RAY_MPI_TAG_ASK_VERTEX_PATH;

	reset();
}

void AnnotationFetcher::reset(){
	m_initializedDirectionFetcher = false;
}

bool AnnotationFetcher::fetchDirections(Kmer*kmer){

	if(!m_initializedDirectionFetcher){

		m_initializedDirectionFetcher =  true;

		m_fetchedCount = false;
		m_queryWasSent = false;

		m_directions.clear();

	}else if(!m_fetchedCount){

		if(!m_queryWasSent){
			MessageTag tag = RAY_MPI_TAG_ASK_VERTEX_PATHS_SIZE;
			int elementsPerQuery=m_virtualCommunicator->getElementsPerQuery(tag);

#ifdef DEBUG_LEFT_EXPLORATION
			cout << "Sending message for count" << endl;
#endif

			Rank destination = m_parameters->vertexRank(kmer);
			MessageUnit*message=(MessageUnit*)m_outboxAllocator->allocate(elementsPerQuery*sizeof(MessageUnit));
			int bufferPosition=0;
			kmer->pack(message,&bufferPosition);
			Message aMessage(message, elementsPerQuery,
				destination, tag, m_rank);

			m_virtualCommunicator->pushMessage(m_identifier, &aMessage);

			m_queryWasSent = true;

		}else if(m_virtualCommunicator->isMessageProcessed(m_identifier)){
			vector<MessageUnit> elements;
			m_virtualCommunicator->getMessageResponseElements(m_identifier, &elements);

			m_numberOfPaths = elements[0];

			m_fetchedCount = true;

#ifdef DEBUG_LEFT_EXPLORATION
			cout<<"Paths: "<<m_numberOfPaths << endl;
#endif
			m_pathIndex = 0;

			m_queryWasSent = false;
			m_reverseStrand = false;
		}
	}else if(m_pathIndex < m_numberOfPaths){

		if(!m_queryWasSent){

			Kmer theKmer=*kmer;

			if(m_reverseStrand)
				theKmer = theKmer.complementVertex(m_parameters->getWordSize(),m_parameters->getColorSpaceMode());

			Rank destination = m_parameters->vertexRank(&theKmer);
			int elementsPerQuery=m_virtualCommunicator->getElementsPerQuery(RAY_MPI_TAG_ASK_VERTEX_PATH);
			MessageUnit*message=(MessageUnit*)m_outboxAllocator->allocate(elementsPerQuery);
			int outputPosition=0;
			theKmer.pack(message,&outputPosition);
			message[outputPosition++]=m_pathIndex;

			Message aMessage(message, elementsPerQuery, destination,
				RAY_MPI_TAG_ASK_VERTEX_PATH, m_parameters->getRank());

			m_virtualCommunicator->pushMessage(m_identifier, &aMessage);

			m_queryWasSent = true;

		}else if(m_virtualCommunicator->isMessageProcessed(m_identifier)){

			vector<MessageUnit> response;
			m_virtualCommunicator->getMessageResponseElements(m_identifier, &response);

			int bufferPosition=0;
			/* skip the k-mer because we don't need it */
			bufferPosition += kmer->getNumberOfU64();
			PathHandle otherPathIdentifier=response[bufferPosition++];
			int progression=response[bufferPosition++];

			Direction direction;

			direction.constructor(otherPathIdentifier, progression, m_reverseStrand);

			m_directions.push_back(direction);

			m_queryWasSent = false;
			m_pathIndex ++;
		}
/*
	}else if(!m_reverseStrand){

		// fetch also reverse-complement entries.
		m_reverseStrand = true;
		m_pathIndex = 0;
		m_queryWasSent = false;
*/
	}else{
		return true;
	}

	return false;
}

vector<Direction>* AnnotationFetcher::getDirections(){

	return &m_directions;
}