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
|
/*
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/>
*/
#ifndef _Scaffolder_h
#define _Scaffolder_h
#include "ScaffoldingLink.h"
#include "SummarizedLink.h"
#include <code/SeedExtender/ReadFetcher.h>
#include <code/Mock/Parameters.h>
#include <code/Mock/constants.h>
#include <code/SeedingData/GraphPath.h>
#include <RayPlatform/structures/StaticVector.h>
#include <RayPlatform/memory/RingAllocator.h>
#include <RayPlatform/communication/VirtualCommunicator.h>
#include <RayPlatform/scheduling/SwitchMan.h>
#include <RayPlatform/profiling/TimePrinter.h>
#include <RayPlatform/handlers/SlaveModeHandler.h>
#include <RayPlatform/handlers/MasterModeHandler.h>
#include <RayPlatform/plugins/CorePlugin.h>
#include <vector>
#include <sstream>
using namespace std;
__DeclarePlugin(Scaffolder);
__DeclareMasterModeAdapter(Scaffolder,RAY_MASTER_MODE_WRITE_SCAFFOLDS);
__DeclareSlaveModeAdapter(Scaffolder,RAY_SLAVE_MODE_SCAFFOLDER);
__DeclareMessageTagAdapter(Scaffolder,RAY_MPI_TAG_GET_CONTIG_CHUNK);
__DeclareMessageTagAdapter(Scaffolder,RAY_MPI_TAG_GET_CONTIG_PACKED_CHUNK);
/**
* Scaffolder class, it uses MPI through the virtual communicator.
*
* \author Sébastien Boisvert
*/
class Scaffolder : public CorePlugin{
__AddAdapter(Scaffolder,RAY_MASTER_MODE_WRITE_SCAFFOLDS);
__AddAdapter(Scaffolder,RAY_SLAVE_MODE_SCAFFOLDER);
__AddAdapter(Scaffolder,RAY_MPI_TAG_GET_CONTIG_CHUNK);
__AddAdapter(Scaffolder,RAY_MPI_TAG_GET_CONTIG_PACKED_CHUNK);
ostringstream m_operationBuffer;
MessageTag RAY_MPI_TAG_SCAFFOLDING_LINKS_REPLY;
MessageTag RAY_MPI_TAG_START_SCAFFOLDER;
MessageTag RAY_MPI_TAG_REQUEST_VERTEX_READS;
MessageTag RAY_MPI_TAG_CONTIG_INFO;
MessageTag RAY_MPI_TAG_GET_CONTIG_CHUNK;
MessageTag RAY_MPI_TAG_GET_CONTIG_CHUNK_REPLY;
MessageTag RAY_MPI_TAG_GET_CONTIG_PACKED_CHUNK;
MessageTag RAY_MPI_TAG_GET_CONTIG_PACKED_CHUNK_REPLY;
MessageTag RAY_MPI_TAG_GET_COVERAGE_AND_DIRECTION;
MessageTag RAY_MPI_TAG_GET_PATH_LENGTH;
MessageTag RAY_MPI_TAG_GET_READ_MARKERS;
MessageTag RAY_MPI_TAG_GET_READ_MATE;
MessageTag RAY_MPI_TAG_GET_VERTEX_EDGES_COMPACT;
MessageTag RAY_MPI_TAG_HAS_PAIRED_READ;
MessageTag RAY_MPI_TAG_I_FINISHED_SCAFFOLDING;
MessageTag RAY_MPI_TAG_SCAFFOLDING_LINKS;
MasterMode RAY_MASTER_MODE_WRITE_SCAFFOLDS;
MasterMode RAY_MASTER_MODE_CONTIG_BIOLOGICAL_ABUNDANCES;
MasterMode RAY_MASTER_MODE_COUNT_SEARCH_ELEMENTS;
SlaveMode RAY_SLAVE_MODE_DO_NOTHING;
SlaveMode RAY_SLAVE_MODE_SCAFFOLDER;
bool m_coverageWasComputedWithJustice;
int m_skippedRepeatedObjects;
SwitchMan*m_switchMan;
TimePrinter*m_timePrinter;
/**
* Added to skip scaffolding in case of unpaired reads
*/
bool m_skipScaffolding;
int m_rankIdForContig;
bool m_hasContigSequence_Initialised;
ofstream m_fp;
bool m_hasContigSequence;
string m_contigSequence;
map<PathHandle,int> m_contigLengths;
int m_position;
int m_theLength;
GraphPath m_contigPath;
bool m_requestedContigChunk;
vector<int> m_allScaffoldLengths;
vector<int> m_allContigLengths;
/* coverage values for the current path */
vector<int> m_vertexCoverageValues;
int m_scaffoldId;
int m_positionOnScaffold;
bool m_writeContigRequested;
vector<vector<PathHandle> > m_scaffoldContigs;
vector<vector<char> >m_scaffoldStrands;
vector<vector<int> >m_scaffoldGaps;
bool m_sentContigInfo;
bool m_sentContigMeta;
vector<PathHandle> m_masterContigs;
vector<int> m_masterLengths;
vector<SummarizedLink>m_masterLinks;
int m_summaryIterator;
bool m_summarySent;
vector<SummarizedLink>m_summary;
bool m_summaryPerformed;
bool m_entrySent;
map<PathHandle,map<char,map<PathHandle,map<char,vector<ScaffoldingLink> > > > > m_scaffoldingSummary;
bool m_reverseDirectionsReceived;
bool m_reverseDirectionLengthReceived;
PathHandle m_pairedReverseDirectionName;
int m_pairedReverseDirectionPosition;
CoverageDepth m_pairedReverseMarkerCoverage;
bool m_pairedReverseHasDirection;
bool m_reverseDirectionLengthRequested;
int m_pairedReverseDirectionLength;
// these are mostly flags for sends/receives
bool m_forwardDirectionLengthRequested;
bool m_forwardDirectionLengthReceived;
int m_pairedForwardDirectionLength;
bool m_forwardDirectionsRequested;
bool m_forwardDirectionsReceived;
CoverageDepth m_pairedForwardMarkerCoverage;
bool m_pairedForwardHasDirection;
PathHandle m_pairedForwardDirectionName;
int m_pairedForwardDirectionPosition;
bool m_reverseDirectionsRequested;
int m_readLength;
bool m_markersRequested;
bool m_markersReceived;
int m_pairedForwardOffset;
int m_pairedReverseOffset;
Kmer m_pairedForwardMarker;
Kmer m_pairedReverseMarker;
bool m_pairReceived;
int m_pairedReadRank;
int m_pairedReadIndex;
int m_pairedReadLibrary;
int m_pairedReadLength;
bool m_pairRequested;
bool m_hasPairReceived;
bool m_hasPairRequested;
bool m_hasPair;
bool m_initialisedFetcher;
int m_readAnnotationId;
ReadFetcher m_readFetcher;
vector<WorkerHandle> m_activeWorkers;
WorkerHandle m_workerId;
VirtualCommunicator*m_virtualCommunicator;
bool m_coverageRequested;
bool m_coverageReceived;
CoverageDepth m_receivedCoverage;
bool m_reverseDone;
bool m_forwardDone;
int m_contigId;
int m_positionOnContig;
vector<GraphPath>*m_contigs;
vector<PathHandle>*m_contigNames;
Parameters*m_parameters;
StaticVector*m_inbox;
StaticVector*m_outbox;
RingAllocator*m_outboxAllocator;
bool m_ready;
/**
* gets a contig sequence by receiving several MPI messages
*/
map<PathHandle,int>*m_contigNameIndex;
void getContigSequence(PathHandle id);
void getContigSequenceFromKmers(PathHandle id);
void getContigSequenceFromPackedObjects(PathHandle id);
void processContig();
void processContigPosition();
void processVertex(Kmer*vertex);
void processAnnotations();
void processAnnotation();
void performSummary();
void sendSummary();
void sendContigInfo();
void extractScaffolds(char state,map<PathHandle,int>*colors,PathHandle vertex,
map<PathHandle,map<char,vector<vector<PathHandle> > > >*parents,
map<PathHandle,map<char,vector<vector<PathHandle> > > >*children,set<int>*completedColours);
void computeStatistics(vector<int>*lengths,int minimumLength,ostream*outputStream);
void printInStream(ostream*outputStream);
void getCoverageOfBlockOfLife();
Rank m_rank;
/*
* Variables for fetching remote paths.
*/
int m_theLengthInNucleotides;
ostringstream m_contigPathBuffer;
public:
bool m_initialised;
/**
* Number of ranks that have finished scaffolding
*/
int m_numberOfRanksFinished;
/**
* Constructor of the scaffolder
*/
void constructor(StaticVector*outbox,StaticVector*inbox,RingAllocator*outboxAllocator,Parameters*parameters,
VirtualCommunicator*vc,SwitchMan*switchMan);
void setContigPaths(vector<PathHandle>*names,vector<GraphPath>*paths);
void addMasterLink(SummarizedLink*link);
void solve();
void addMasterContig(PathHandle name,int length);
void call_RAY_MASTER_MODE_WRITE_SCAFFOLDS();
void call_RAY_SLAVE_MODE_SCAFFOLDER();
void call_RAY_MPI_TAG_GET_CONTIG_CHUNK(Message*message);
void call_RAY_MPI_TAG_GET_CONTIG_PACKED_CHUNK(Message*message);
void printFinalMessage();
void setTimePrinter(TimePrinter*a);
void registerPlugin(ComputeCore*core);
void resolveSymbols(ComputeCore*core);
};
#endif
|