Skip to content

Commit

Permalink
Merge pull request #23 from mourisl/centrifuger_quant
Browse files Browse the repository at this point in the history
Update to centrifuger-quant
  • Loading branch information
mourisl authored Dec 28, 2024
2 parents 8bf8730 + 9fcbaf8 commit f0dd19b
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 90 deletions.
4 changes: 2 additions & 2 deletions CentrifugerInspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static struct option long_options[] = {
{"conversion-table", no_argument, 0, ARGV_CONVERSION_TABLE},
{"taxonomy-tree", no_argument, 0, ARGV_TAXONOMY_TREE},
{"name-table", no_argument, 0, ARGV_NAME_TABLE},
{"size-table", no_argument, 0, ARGV_INSPECT_SIZE_TABLE},
{"size-table", no_argument, 0, ARGV_SIZE_TABLE},
{"index-size", no_argument, 0, ARGV_INSPECT_INDEXSIZE},
{ (char *)0, 0, 0, 0}
} ;
Expand Down Expand Up @@ -108,7 +108,7 @@ int main(int argc, char *argv[])
{
taxonomy.PrintNameTable(stdout) ;
}
else if (inspectItem == ARGV_INSPECT_SIZE_TABLE)
else if (inspectItem == ARGV_SIZE_TABLE)
{
size_t i ;
size_t n = taxonomy.GetNodeCount() ;
Expand Down
73 changes: 60 additions & 13 deletions CentrifugerQuant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@

char usage[] = "./centrifuger-quant [OPTIONS]:\n"
"Required:\n"
"\t-x FILE: index prefix\n"
"\t-c FILE: classification result file\n"
//"When not giving "-x"\n"
//"\t--taxonomy-tree FILE: taxonomy tree, i.e., nodes.dmp file\n"
//"\t--name-table FILE: name table, i.e., names.dmp file\n"
//"\t--size-table FILE: size table, table of contig (or genome) sizes\n"
//"\t--conversion-table FILE: a table that converts any id to a taxonomy id\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}
} ;

Expand All @@ -35,7 +43,13 @@ int main(int argc, char *argv[])

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 ) ;
Expand All @@ -51,6 +65,26 @@ int main(int argc, char *argv[])
{
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) ;
Expand All @@ -59,23 +93,36 @@ int main(int argc, char *argv[])
}

Utils::PrintLog("Centrifuger-quant v" CENTRIFUGER_VERSION " starts." ) ;
if (idxPrefix == NULL)
if (idxPrefix == NULL &&
(taxonomyFile == NULL || nameTable == NULL))
{
Utils::PrintLog("Need to use -x to specify index prefix.") ;
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 ;
quantifier.Init(idxPrefix) ;
quantifier.LoadReadAssignments(classificationFile, 0) ;
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(idxPrefix) ;
free(classificationFile) ;


if (idxPrefix != NULL)
free(idxPrefix) ;
else
{
free(taxonomyFile) ;
free(nameTable) ;
free(sizeTable) ;
}

Utils::PrintLog("Centrifuger-quant finishes." ) ;
return 0 ;
}
Loading

0 comments on commit f0dd19b

Please sign in to comment.