-
Notifications
You must be signed in to change notification settings - Fork 4
/
CentrifugerQuant.cpp
128 lines (111 loc) · 3.24 KB
/
CentrifugerQuant.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
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
#include <stdio.h>
#include <time.h>
#include <getopt.h>
#include "argvdefs.h"
#include "Taxonomy.hpp"
#include "Quantifier.hpp"
char usage[] = "./centrifuger-quant [OPTIONS]:\n"
"Required:\n"
"\t-c FILE: classification result file\n"
"\t-x FILE: index prefix\n"
"\tWhen not giving -x\n"
"\t\t--taxonomy-tree FILE: taxonomy tree, i.e., nodes.dmp file\n"
"\t\t--name-table FILE: name table, i.e., names.dmp file\n"
"\t\t--size-table FILE: size table (optional), table of contig (or genome) sizes.\n"
"Optional:\n"
"\t--min-score INT: only consider reads with score at least <int> \n"
"\t--min-length INT: only consider reads with classified length at least <int>\n"
""
;
static const char *short_options = "x:c:" ;
static struct option long_options[] = {
{ "taxonomy-tree", required_argument, 0, ARGV_TAXONOMY_TREE},
{ "name-table", required_argument, 0, ARGV_NAME_TABLE},
{ "size-table", required_argument, 0, ARGV_SIZE_TABLE},
{ "min-score", required_argument, 0, ARGV_QUANT_MINSCORE},
{ "min-length", required_argument, 0, ARGV_QUANT_MINLENGTH},
{ (char *)0, 0, 0, 0}
} ;
int main(int argc, char *argv[])
{
if ( argc <= 1 )
{
fprintf( stderr, "%s", usage ) ;
return 0 ;
}
int c, option_index ;
option_index = 0 ;
char *idxPrefix = NULL ;
char *classificationFile = NULL ;
size_t classificationMinScore = 0 ;
int classificationMinLength = 0 ;
char *taxonomyFile = NULL ; // taxonomy tree file
char *nameTable = NULL ;
char *sizeTable = NULL ;
while (1)
{
c = getopt_long( argc, argv, short_options, long_options, &option_index ) ;
if (c == -1)
break ;
if (c == 'x')
{
idxPrefix = strdup(optarg) ;
}
else if (c == 'c')
{
classificationFile = strdup(optarg) ;
}
else if (c == ARGV_QUANT_MINSCORE)
{
classificationMinScore = atoi(optarg) ;
}
else if (c == ARGV_QUANT_MINLENGTH)
{
classificationMinLength = atoi(optarg) ;
}
else if (c == ARGV_TAXONOMY_TREE)
{
taxonomyFile = strdup(optarg) ;
}
else if (c == ARGV_NAME_TABLE)
{
nameTable = strdup(optarg) ;
}
else if (c == ARGV_SIZE_TABLE)
{
sizeTable = strdup(optarg) ;
}
else
{
fprintf(stderr, "Unknown parameter found.\n%s", usage) ;
return EXIT_FAILURE ;
}
}
Utils::PrintLog("Centrifuger-quant v" CENTRIFUGER_VERSION " starts." ) ;
if (idxPrefix == NULL &&
(taxonomyFile == NULL || nameTable == NULL))
{
Utils::PrintLog("Need to use -x to specify index prefix, or --taxonomy-tree/--name-table/(--size-table) to specify the taxonomy structure.") ;
return EXIT_FAILURE ;
}
Quantifier quantifier ;
if (idxPrefix)
quantifier.Init(idxPrefix) ;
else
quantifier.Init(taxonomyFile, nameTable, sizeTable) ;
quantifier.LoadReadAssignments(classificationFile, classificationMinScore, classificationMinLength, 0) ;
Utils::PrintLog("Finish loading the read classification result.") ;
quantifier.Quantification() ;
quantifier.Output(stdout, 0) ;
free(classificationFile) ;
if (idxPrefix != NULL)
free(idxPrefix) ;
else
{
free(taxonomyFile) ;
free(nameTable) ;
free(sizeTable) ;
}
Utils::PrintLog("Centrifuger-quant finishes." ) ;
return 0 ;
}