Skip to content

Commit

Permalink
fix a minor bug (exists()), and support output to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanxw committed Nov 13, 2012
1 parent 792fc98 commit 9284406
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 43 deletions.
38 changes: 19 additions & 19 deletions Argument.h
Expand Up @@ -418,7 +418,7 @@ class ParameterParser{
unsigned int idx = it - this->flagVec.begin();
void* data = this->flagInfoMap[idx].data;
if (this->flagInfoMap[idx].isParsed) {
fprintf(stdout, "WARNING: flag \"%s\" provided more than once, the previous value will be overwritten\n", argv[i]);
fprintf(stderr, "WARNING: flag \"%s\" provided more than once, the previous value will be overwritten\n", argv[i]);
}
this->flagInfoMap[idx].isParsed = true;
switch(this->flagInfoMap[idx].pt) {
Expand Down Expand Up @@ -447,9 +447,9 @@ class ParameterParser{
}
};
void Status() {
fprintf(stdout, "The following parameters are available. Ones with \"[]\" are in effect:\n");
fprintf(stdout, "\n");
fprintf(stdout, "Available Options\n");
fprintf(stderr, "The following parameters are available. Ones with \"[]\" are in effect:\n");
fprintf(stderr, "\n");
fprintf(stderr, "Available Options\n");
/*
Format illustration:
Individual Filter : --indvDepthMin [], --indvDepthMax [], --indvQualMin []
Expand All @@ -470,8 +470,8 @@ class ParameterParser{


// print group header
fprintf(stdout, "%*s", GROUP_WIDTH, k.c_str());
fprintf(stdout, "%s", SEP);
fprintf(stderr, "%*s", GROUP_WIDTH, k.c_str());
fprintf(stderr, "%s", SEP);

int availableFlagWidth = FLAG_WIDTH;
std::stringstream flagBuffer;
Expand Down Expand Up @@ -534,23 +534,23 @@ class ParameterParser{

// if there are not enough spaces and th, we will output a new line
if (availableFlagWidth < flagWidth && flagWidth < FLAG_WIDTH) {
fprintf(stdout, "\n");
fprintf(stdout, "%*s", GROUP_WIDTH, " ");
fprintf(stdout, "%s", EMPTY_SEP);
fprintf(stderr, "\n");
fprintf(stderr, "%*s", GROUP_WIDTH, " ");
fprintf(stderr, "%s", EMPTY_SEP);
availableFlagWidth = FLAG_WIDTH;
if (flagToPrint[0] == ',') {
flagToPrint = flagToPrint.substr(2, flagToPrint.size() - 2);
}
fprintf(stdout, "%s", flagToPrint.c_str()); // 2 is length of ", "
fprintf(stderr, "%s", flagToPrint.c_str()); // 2 is length of ", "
availableFlagWidth -= flagWidth;

firstFlagInLine = false;
} else {
fprintf(stdout, "%s", flagToPrint.c_str());
fprintf(stderr, "%s", flagToPrint.c_str());
availableFlagWidth -= flagWidth;
}
}
fprintf(stdout, "\n");
fprintf(stderr, "\n");
}
};
void Help() {
Expand All @@ -565,7 +565,7 @@ class ParameterParser{
this->groupNameFlagIndexMap.at(groupIndex, &k, &v);

// print group header
fprintf(stdout, "%s\n", k.c_str());
fprintf(stderr, "%s\n", k.c_str());

for (size_t i = 0; i < v.size(); i++) {
int idx = v[i];
Expand All @@ -575,19 +575,19 @@ class ParameterParser{
// int flagWidth = 0;

if (fi.isLongParam) {
fprintf(stdout, "%*s%s%s", (int)(FLAG_WIDTH - flag.size() ), "--", flag.c_str(), SEP);
fprintf(stderr, "%*s%s%s", (int)(FLAG_WIDTH - flag.size() ), "--", flag.c_str(), SEP);
} else {
fprintf(stdout, "%*s%s%s", (int)(FLAG_WIDTH - flag.size() ), "-", flag.c_str(), SEP);
fprintf(stderr, "%*s%s%s", (int)(FLAG_WIDTH - flag.size() ), "-", flag.c_str(), SEP);
}

for (size_t docIndex = 0; docIndex < fi.doc.size(); docIndex++) {
if (docIndex != 0 && docIndex % DOC_WIDTH == 0) {
fprintf(stdout, "\n");
fprintf(stdout, "%*s%s", FLAG_WIDTH, " ", EMPTY_SEP);
fprintf(stderr, "\n");
fprintf(stderr, "%*s%s", FLAG_WIDTH, " ", EMPTY_SEP);
}
fprintf(stdout, "%c", fi.doc[docIndex]);
fprintf(stderr, "%c", fi.doc[docIndex]);
}
fprintf(stdout, "\n");
fprintf(stderr, "\n");
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions Gene.h
Expand Up @@ -391,7 +391,7 @@ class Gene{
*/
bool isInRange(const int pos, const int beg, const int end) {
if (beg > end) {
fprintf(stdout, "in isInRange beg(%d) > end(%d).\n", beg, end);
fprintf(stderr, "in isInRange beg(%d) > end(%d).\n", beg, end);
}
if (beg <= pos && pos <= end)
return true;
Expand Down Expand Up @@ -424,7 +424,7 @@ class Gene{
*/
int length(int beg, int end) {
if (beg > end+1) {
fprintf(stdout, "In length beg(%d) > end(%d) + 1; please check gene file format.\n", beg, end);
fprintf(stderr, "In length beg(%d) > end(%d) + 1; please check gene file format.\n", beg, end);
}
return (end - beg + 1);
};
Expand Down
24 changes: 12 additions & 12 deletions GeneAnnotation.h
Expand Up @@ -45,7 +45,7 @@ class GeneAnnotation{
}

// read gene file
fprintf(stdout, "Load gene file %s...\n", geneFileName);
fprintf(stderr, "Load gene file %s...\n", geneFileName);
std::string line;
std::vector<std::string> fields;
LineReader lr(geneFileName);
Expand All @@ -60,26 +60,26 @@ class GeneAnnotation{
}
// make sure genes are ordered
this->sortGene();
fprintf(stdout, "DONE: %d gene loaded.\n", totalGene);
fprintf(stderr, "DONE: %d gene loaded.\n", totalGene);
LOG << "Gene file " << geneFileName << " loads succeed!\n";
return 0;
};
void openCodonFile(const char* codonFileName) {
fprintf(stdout, "Load codon file %s...\n", codonFileName);
fprintf(stderr, "Load codon file %s...\n", codonFileName);
this->codon.open(codonFileName);
fprintf(stdout, "DONE: codon file loaded.\n");
fprintf(stderr, "DONE: codon file loaded.\n");
LOG << "Codon file " << codonFileName << " loads succeed!\n";
return;
};
void openReferenceGenome(const char* referenceGenomeFileName) {
fprintf(stdout, "Load reference genome %s...\n", referenceGenomeFileName);
fprintf(stderr, "Load reference genome %s...\n", referenceGenomeFileName);
this->gs.open(referenceGenomeFileName);
fprintf(stdout, "DONE: %d chromosomes and %ld bases are loaded.\n", this->gs.size(), this->gs.getGenomeLength());
fprintf(stderr, "DONE: %d chromosomes and %ld bases are loaded.\n", this->gs.size(), this->gs.getGenomeLength());
LOG << "Reference genome file " << referenceGenomeFileName << " loads succeed!\n";
return;
};
void openPriorityFile(const char* fileName) {
fprintf(stdout, "Load priority file %s...\n", fileName);
fprintf(stderr, "Load priority file %s...\n", fileName);
int ret = this->priority.open(fileName);
fprintf(stderr, "DONE: %d priority annotation types loaded.\n", ret);
LOG << "Priority file " << fileName << " load succeed!\n";
Expand All @@ -96,31 +96,31 @@ class GeneAnnotation{
// output annotation frequency (all types of annotation)
std::string ofs = fn+".anno.frq";
this->printAnnotationFrequency(ofs.c_str());
fprintf(stdout, "DONE: Generated frequency of each annotype type in [ %s ].\n", ofs.c_str());
fprintf(stderr, "DONE: Generated frequency of each annotype type in [ %s ].\n", ofs.c_str());
LOG << "Generate frequency of each annotation type in " << ofs << " succeed!\n";

// output annotation frequency
ofs = fn+".top.anno.frq";
this->printTopPriorityAnnotationFrequency(ofs.c_str());
fprintf(stdout, "DONE: Generated frequency of each highest priority annotation type in [ %s ].\n", ofs.c_str());
fprintf(stderr, "DONE: Generated frequency of each highest priority annotation type in [ %s ].\n", ofs.c_str());
LOG << "Generate frequency of high priority for highest priority annotation type in " << ofs << " succeed!\n";

// output base change frequency
ofs = fn+".base.frq";
this->printBaseChangeFrequency(ofs.c_str());
fprintf(stdout, "DONE: Generated frequency of each base change in [ %s ].\n", ofs.c_str());
fprintf(stderr, "DONE: Generated frequency of each base change in [ %s ].\n", ofs.c_str());
LOG << "Generate frequency of each base change in " << ofs << " succeed!\n";

// output codon change frequency
ofs = fn+".codon.frq";
this->printCodonChangeFrequency(ofs.c_str());
fprintf(stdout, "DONE: Generated frequency of each codon change in [ %s ].\n", ofs.c_str());
fprintf(stderr, "DONE: Generated frequency of each codon change in [ %s ].\n", ofs.c_str());
LOG << "Generate frequency of each codon change in " << ofs << " succeed!\n";

// output indel length frequency
ofs = fn+".indel.frq";
this->printIndelLengthFrequency(ofs.c_str());
fprintf(stdout, "DONE: Generated frequency of indel length in [ %s ].\n", ofs.c_str());
fprintf(stderr, "DONE: Generated frequency of indel length in [ %s ].\n", ofs.c_str());
LOG << "Generate frequency of indel length in " << ofs << " succeed!\n";
};
public:
Expand Down
2 changes: 1 addition & 1 deletion GenomeScore.h
Expand Up @@ -27,7 +27,7 @@ class GenomeScore {
++lineNo;
}
if (lineNo % 1000000l == 0) {
fprintf(stdout, "\rFinished %s:%d ...", chrom, lineNo);
fprintf(stderr, "\rFinished %s:%d ...", chrom, lineNo);
};
};
};
Expand Down
2 changes: 2 additions & 0 deletions GenomeSequence.h
Expand Up @@ -189,6 +189,8 @@ GenomeSequence():fp(NULL){};
bool exists(const std::string& c){
if (this->data.find(c) != this->data.end())
return true;
if (faidx.getInfo(c) != NULL)
return true;
return false;
}
public:
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.h
@@ -1 +1 @@
const char *gitVersion = "20a7ac5f5ab48d955bf28c3ad3b44d87994c3f0a";
const char *gitVersion = "792fc983a293cac73c48f3da70ed10aa9083c689";
20 changes: 12 additions & 8 deletions Main.cpp
Expand Up @@ -260,7 +260,7 @@ class AnnotationInputFile{
if (this->checkReference) {
std::string refFromGenome = this->gs.getBase(*chrom, *pos, *pos + ref->size());
if ((*ref) != refFromGenome) {
fprintf(stdout, "ERROR: Reference allele does not match genome reference [ %s:%d %s]\n", chrom->c_str(), *pos, ref->c_str());
fprintf(stderr, "ERROR: Reference allele does not match genome reference [ %s:%d %s]\n", chrom->c_str(), *pos, ref->c_str());
LOG << "ERRROR: Reference allele [" << ref << "] does not match reference genome [" << refFromGenome << "] at " << *chrom << ":" << *pos << "\n";
};
}
Expand Down Expand Up @@ -292,18 +292,22 @@ class AnnotationInputFile{
class AnnotationOutputFile{
public:
AnnotationOutputFile(const char* out):headerOutputted(false), totalVariants(0),outputFileName(out) {
this->fout = fopen(out, "wt");
if (!this->fout) {
fprintf(stderr, "Cannot open otuput file %s for write.\n", out);
};
if (strncmp (out, "stdout", 6) ) {
this->fout = fopen(out, "wt");
if (!this->fout) {
fprintf(stderr, "Cannot open otuput file %s for write.\n", out);
}
} else {
this->fout = stdout;
}
};
~AnnotationOutputFile() {
this->close();
}
void close() {
if (this->fout) {
fprintf(stdout, "DONE: %d varaints are annotated.\n", totalVariants);
fprintf(stdout, "DONE: Generated annotation output in [ %s ].\n", outputFileName.c_str());
fprintf(stderr, "DONE: %d varaints are annotated.\n", totalVariants);
fprintf(stderr, "DONE: Generated annotation output in [ %s ].\n", outputFileName.c_str());
fclose(this->fout);
this->fout = NULL;
}
Expand Down Expand Up @@ -513,7 +517,7 @@ class AnnotationController{

int main(int argc, char *argv[])
{
banner(stdout);
banner(stderr);

BEGIN_PARAMETER_LIST(pl)
ADD_PARAMETER_GROUP(pl, "Required Parameters")
Expand Down

0 comments on commit 9284406

Please sign in to comment.