File: parallelAbyss.cpp

package info (click to toggle)
abyss 2.3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,284 kB
  • sloc: cpp: 78,182; ansic: 6,512; makefile: 2,252; perl: 672; sh: 509; haskell: 412; python: 4
file content (138 lines) | stat: -rw-r--r-- 3,321 bytes parent folder | download | duplicates (6)
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
#include "config.h"
#include "NetworkSequenceCollection.h"
#include "Assembly/Options.h"
#include "Common/Log.h"
#include "Common/Options.h"
#include "Common/Timer.h"
#include "Common/Uncompress.h"
#include "DataLayer/FastaReader.h"
#include <cerrno>
#include <climits> // for HOST_NAME_MAX
#include <cstdio> // for setvbuf
#include <cstdlib>
#include <cstring> // for strerror
#include <iostream>
#include <mpi.h>
#include <unistd.h> // for gethostname
#include <vector>
#include "DataBase/DB.h"

using namespace std;

static const char* FASTA_SUFFIX = ".fa";

#if PAIRED_DBG
// Define KmerPair::s_length
# include "PairedDBG/KmerPair.cc"
#endif

static void mergeFastaFiles(const string& outputPath, const string& inputPathPrefix, bool generateNewIds = false)
{
	cout << "Concatenating fasta files to " << outputPath << endl;

	// write merged FASTA file

	FastaWriter writer(outputPath.c_str());
	uint64_t seqid = 0;
	for(int i = 0; i < opt::numProc; i++) {
		ostringstream filename;
		filename << inputPathPrefix << i << FASTA_SUFFIX;
		assert(filename.good());
		string str(filename.str());
		FastaReader reader(str.c_str(), FastaReader::NO_FOLD_CASE);
		for (FastaRecord rec; reader >> rec;) {
			if (generateNewIds)
				writer.WriteSequence(rec.seq, seqid++, rec.comment);
			else
				writer.WriteSequence(rec.seq, rec.id, rec.comment);
		}
		assert(reader.eof());
	}

	// remove temp FASTA files

	bool die = false;
	for (int i = 0; i < opt::numProc; i++) {
		ostringstream s;
		s << inputPathPrefix << i << FASTA_SUFFIX;
		string str(s.str());
		const char* path = str.c_str();
		if (unlink(path) == -1) {
			cerr << "error: removing `" << path << "': "
				<< strerror(errno) << endl;
			die = true;
		}
	}
	if (die)
		exit(EXIT_FAILURE);
}

int main(int argc, char** argv)
{
	Timer timer("Total");

	// Set stdout to be line buffered.
	setvbuf(stdout, NULL, _IOLBF, 0);

	MPI_Init(&argc,&argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &opt::rank);
	MPI_Comm_size(MPI_COMM_WORLD, &opt::numProc);

	// OMPI-1.6.1 and later reset the SIGCHLD handler so we need to
	// reinitialize uncompress.
	uncompress_init();

#if PAIRED_DBG
	opt::singleKmerSize = -1;
#endif
	opt::parse(argc, argv);
	if (opt::rank == 0)
		cout << "Running on " << opt::numProc << " processors\n";

	MPI_Barrier(MPI_COMM_WORLD);
	char hostname[HOST_NAME_MAX];
	gethostname(hostname, sizeof hostname);
	logger(0) << "Running on host " << hostname << endl;
	MPI_Barrier(MPI_COMM_WORLD);

#if PAIRED_DBG
	Kmer::setLength(opt::singleKmerSize);
	KmerPair::setLength(opt::kmerSize);
#else
	Kmer::setLength(opt::kmerSize);
#endif

	if (opt::rank == 0) {
		NetworkSequenceCollection networkSeqs;
		networkSeqs.runControl();
	} else {
		NetworkSequenceCollection networkSeqs;
		networkSeqs.run();
	}

	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Finalize();

	if (opt::rank == 0) {
		mergeFastaFiles(opt::contigsPath, "contigs-", true);
		if (!opt::snpPath.empty())
			mergeFastaFiles(opt::snpPath, "snp-");
		cout << "Done." << endl;
		DB db;
		if (!opt::db.empty()) {
			init(db,
					opt::getUvalue(),
					opt::getVvalue(),
					"ABYSS-P",
					opt::getCommand(),
					opt::getMetaValue()
			);
			addToDb(db, "SS", opt::ss);
			addToDb(db, "K", opt::kmerSize);
			addToDb(db, "numProc", opt::numProc);
			addToDb(db, NSC::moveFromAaStatMap());
		}
	}

	return 0;
}