-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.h
83 lines (67 loc) · 2.22 KB
/
workflow.h
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
#ifndef WORKFLOW_H_
#define WORKFLOW_H_
#include <seqan/sequence.h>
#include <seqan/bam_io.h>
#include "argparse.h"
#include "bamsubset.h"
#include <iostream>
using namespace seqan;
//Checking parameters given by user
int parseBCSubsetParams(Parameters & params, std::unordered_set<std::string> & wlBarcodes, int argc, char const * argv[])
{
if(parseCommandLine(params, argc, argv) != ArgumentParser::PARSE_OK)
{
std::cerr << "ERROR: Could not parse command line\n";
return 1;
}
if (params.bcWlFileName == "")
{
std::cerr << "ERROR: whitelist file not specified. Please use option -f\n";
return 1;
}
if (params.outBamFileName == "")
{
std::cerr << "ERROR: Output file not specified. Please use option -o\n";
return 1;
}
if(!readWhitelist(wlBarcodes, params.bcWlFileName))
{
std::cerr << "ERROR: Could not read " << params.bcWlFileName << "\n";
return 1;
}
return 0;
}
// Generate BAM subset of reads with whitelisted barcodes
int bamSubset(int argc, char const * argv[])
{
Stats stats;
Parameters params;
int res = checkParser(parseCommandLine(params, argc, argv));
if (res >= 0)
return res;
std::unordered_set<std::string> wlBarcodes;
readWhitelist(wlBarcodes, params.bcWlFileName);
// Open BamFileIn for reading
BamFileIn inFile;
if (!open(inFile, toCString(params.bamFileName)))
{
std::cerr << "ERROR: Could not open " << params.bamFileName << " for reading.\n";
return 1;
}
// Open output file BamFileOut
std::fstream outStream;
outStream.open(toCString(params.outBamFileName), std::ios::out);
if (!outStream.good())
SEQAN_THROW(FileOpenError(toCString(params.outBamFileName)));
BamFileOut bamFileOut(context(inFile), outStream, Bam());
// Access header
BamHeader header;
readHeader(header, inFile);
// Write header
processHeader(header, bamFileOut, argv);
processBam(inFile, bamFileOut, wlBarcodes, params.bctag, params.trimming, stats);
std::cout << "[bcsubset] Output file has been written to \'" << params.outBamFileName << "\'." << std::endl;
stats.report();
return 0;
}
#endif /* WORKFLOW_H_ */