Skip to content

Commit

Permalink
add computing auc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingfu Shao committed Sep 11, 2017
1 parent 534e6fd commit 6545373
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
37 changes: 36 additions & 1 deletion gtfcuff/gtfcuff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ int gtfcuff::match_correct(int refsize, int mcorrect)
return 0;
}


int gtfcuff::match_sensitivity(int refsize, double sensitivity)
{
if(items.size() == 0) return 0;
Expand Down Expand Up @@ -376,6 +375,42 @@ int gtfcuff::roc_quant(const string &qfile, double min_tpm, double max_tpm)
return 0;
}

int gtfcuff::auc(int refsize)
{
if(items.size() == 0) return 0;

sort(items.begin(), items.end(), cuffitem_cmp_coverage);

int correct = 0;
for(int i = 0; i < items.size(); i++) if(items[i].code == '=') correct++;

int correct0 = correct;
double sen0 = correct * 100.0 / refsize;
double pre0 = correct * 100.0 / items.size();
double auc = sen0 * pre0;
for(int i = 0; i < items.size() - 1; i++)
{
if(items[i].code == '=') correct--;

double sen = correct * 100.0 / refsize;
double pre = correct * 100.0 / (items.size() - i - 1);

double area = (sen + sen0) * 0.5 * (pre - pre0);
auc += area;

pre0 = pre;
sen0 = sen;

//printf("reference = %d prediction = %lu correct = %d sensitivity = %.2lf precision = %.2lf | area = %.5lf, auc = %.5lf | coverage = %.3lf, length = %d\n",
// refsize, items.size() - i, correct, sen, pre, area, auc, items[i].coverage, items[i].length);
}

printf("reference = %d prediction = %lu correct = %d sensitivity = %.2lf precision = %.2lf auc = %.3lf\n",
refsize, items.size(), correct0, correct0 * 100.0 / refsize, correct0 * 100.0 / items.size(), auc);

return 0;
}

int gtfcuff::acc(int refsize)
{
if(items.size() == 0) return 0;
Expand Down
1 change: 1 addition & 0 deletions gtfcuff/gtfcuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class gtfcuff
int build_quant_index();

int roc(int refsize);
int auc(int refsize);
int acc(int refsize);
int compute_single_accuracy();
int match_precision(int refsize, double precision);
Expand Down
8 changes: 8 additions & 0 deletions gtfcuff/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ int main(int argc, const char **argv)
{
cout<<"usage: " <<endl;
cout<<" " <<argv[0] << " roc <cuff.tmap> <ref-size>"<<endl;
cout<<" " <<argv[0] << " auc <cuff.tmap> <ref-size>"<<endl;
cout<<" " <<argv[0] << " acc <cuff.tmap> <ref-size>"<<endl;
cout<<" " <<argv[0] << " acc-single <cuff.tmap>"<<endl;
cout<<" " <<argv[0] << " roc-trunc <cuff.tmap> <ref-size> <min-coverage> <max-coverage>"<<endl;
Expand All @@ -32,6 +33,13 @@ int main(int argc, const char **argv)
return 0;
}

if(string(argv[1]) == "auc")
{
assert(argc == 4);
gtfcuff cuff(argv[2]);
cuff.auc(atoi(argv[3]));
}

if(string(argv[1]) == "roc")
{
assert(argc == 4);
Expand Down

0 comments on commit 6545373

Please sign in to comment.