forked from marbl/Mash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandPaste.cpp
91 lines (73 loc) · 2.11 KB
/
CommandPaste.cpp
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
// Copyright © 2015, Battelle National Biodefense Institute (BNBI);
// all rights reserved. Authored by: Brian Ondov, Todd Treangen,
// Sergey Koren, and Adam Phillippy
//
// See the LICENSE.txt file included with this software for license information.
#include "CommandPaste.h"
#include "Sketch.h"
#include <iostream>
#include "unistd.h"
using std::string;
using std::cerr;
using std::endl;
namespace mash {
CommandPaste::CommandPaste()
: Command()
{
name = "paste";
summary = "Create a single sketch file from multiple sketch files.";
description = "Create a single sketch file from multiple sketch files.";
argumentString = "<out_prefix> <sketch> [<sketch>] ...";
useOption("help");
addOption("list", Option(Option::Boolean, "l", "", "Input files are lists of file names.", ""));
}
int CommandPaste::run() const
{
if ( arguments.size() < 2 || options.at("help").active )
{
print();
return 0;
}
bool list = options.at("list").active;
std::vector<string> files;
for ( int i = 1; i < arguments.size(); i++ )
{
if ( list )
{
splitFile(arguments[i], files);
}
else
{
files.push_back(arguments[i]);
}
}
Sketch sketch;
std::vector<string> filesGood;
Sketch::Parameters parameters;
parameters.parallelism = 1;
for ( int i = 0; i < files.size(); i++ )
{
const string & file = files[i];
if ( ! hasSuffix(file, suffixSketch) )
{
cerr << "ERROR: The file \"" << file << "\" does not look like a sketch." << endl;
return 1;
}
filesGood.push_back(file);
}
sketch.initFromFiles(filesGood, parameters);
string out = arguments[0];
if ( ! hasSuffix(out, suffixSketch) )
{
out += suffixSketch;
}
if( access(out.c_str(), F_OK) != -1 )
{
cerr << "ERROR: \"" << out << "\" exists; remove to write." << endl;
exit(1);
}
cerr << "Writing " << out << "..." << endl;
sketch.writeToCapnp(out.c_str());
return 0;
}
} // namespace mash