Skip to content
Snippets Groups Projects
Commit 3b468dd3 authored by Brent Pedersen's avatar Brent Pedersen
Browse files

add n_intersections to jaccard output

parent a09c6556
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ Jaccard::~Jaccard(void) { ...@@ -53,7 +53,7 @@ Jaccard::~Jaccard(void) {
} }
unsigned long Jaccard::GetIntersection() { unsigned long Jaccard::GetIntersection(size_t &n_intersections) {
_bedA = new BedFile(_bedAFile); _bedA = new BedFile(_bedAFile);
_bedB = new BedFile(_bedBFile); _bedB = new BedFile(_bedBFile);
...@@ -70,13 +70,15 @@ unsigned long Jaccard::GetIntersection() { ...@@ -70,13 +70,15 @@ unsigned long Jaccard::GetIntersection() {
hit_set.second.reserve(10000); hit_set.second.reserve(10000);
while (sweep.Next(hit_set)) { while (sweep.Next(hit_set)) {
I += GetTotalIntersection(hit_set.first, hit_set.second); I += GetTotalIntersection(hit_set.first, hit_set.second);
n_intersections += hit_set.second.size();
} }
return I; return I;
} }
void Jaccard::CalculateJaccard() { void Jaccard::CalculateJaccard() {
unsigned long I = GetIntersection(); size_t n_intersections = 0;
unsigned long I = GetIntersection(n_intersections);
unsigned long U = _bedA->getTotalFlattenedLength() + \ unsigned long U = _bedA->getTotalFlattenedLength() + \
_bedB->getTotalFlattenedLength(); _bedB->getTotalFlattenedLength();
...@@ -84,13 +86,15 @@ void Jaccard::CalculateJaccard() { ...@@ -84,13 +86,15 @@ void Jaccard::CalculateJaccard() {
// header // header
cout << "intersection\t" cout << "intersection\t"
<< "union\t" << "union\t"
<< "jaccard" << "jaccard\t"
<< "n_intersections"
<< endl; << endl;
// result // result
cout << I << "\t" cout << I << "\t"
<< U - I << "\t" << U - I << "\t"
<< (float) I / ((float) U - (float) I) << (float) I / ((float) U - (float) I) << "\t"
<< n_intersections
<< endl; << endl;
} }
......
...@@ -57,7 +57,7 @@ private: ...@@ -57,7 +57,7 @@ private:
//------------------------------------------------ //------------------------------------------------
// private methods // private methods
//------------------------------------------------ //------------------------------------------------
unsigned long GetIntersection(); unsigned long GetIntersection(size_t &n_intersections);
unsigned long GetUnion(); unsigned long GetUnion();
void CalculateJaccard(); void CalculateJaccard();
......
...@@ -14,8 +14,8 @@ check() ...@@ -14,8 +14,8 @@ check()
########################################################### ###########################################################
echo " jaccard.t01...\c" echo " jaccard.t01...\c"
echo \ echo \
"intersection union jaccard "intersection union jaccard n_intersections
110 110 1" > exp 110 110 1 2" > exp
$BT jaccard -a a.bed -b a.bed > obs $BT jaccard -a a.bed -b a.bed > obs
check obs exp check obs exp
rm obs exp rm obs exp
...@@ -23,16 +23,16 @@ rm obs exp ...@@ -23,16 +23,16 @@ rm obs exp
echo " jaccard.t02...\c" echo " jaccard.t02...\c"
echo \ echo \
"intersection union jaccard "intersection union jaccard n_intersections
10 140 0.0714286" > exp 10 140 0.0714286 1" > exp
$BT jaccard -a a.bed -b b.bed > obs $BT jaccard -a a.bed -b b.bed > obs
check obs exp check obs exp
rm obs exp rm obs exp
echo " jaccard.t03...\c" echo " jaccard.t03...\c"
echo \ echo \
"intersection union jaccard "intersection union jaccard n_intersections
10 200 0.05" > exp 10 200 0.05 1" > exp
$BT jaccard -a a.bed -b c.bed > obs $BT jaccard -a a.bed -b c.bed > obs
check obs exp check obs exp
rm obs exp rm obs exp
...@@ -40,8 +40,8 @@ rm obs exp ...@@ -40,8 +40,8 @@ rm obs exp
echo " jaccard.t04...\c" echo " jaccard.t04...\c"
echo \ echo \
"intersection union jaccard "intersection union jaccard n_intersections
0 210 0" > exp 0 210 0 0" > exp
$BT jaccard -a a.bed -b d.bed > obs $BT jaccard -a a.bed -b d.bed > obs
check obs exp check obs exp
rm obs exp rm obs exp
...@@ -51,8 +51,8 @@ rm obs exp ...@@ -51,8 +51,8 @@ rm obs exp
########################################################### ###########################################################
echo " jaccard.t05...\c" echo " jaccard.t05...\c"
echo \ echo \
"intersection union jaccard "intersection union jaccard n_intersections
10 140 0.0714286" > exp 10 140 0.0714286 1" > exp
cat a.bed | $BT jaccard -a - -b b.bed > obs cat a.bed | $BT jaccard -a - -b b.bed > obs
check obs exp check obs exp
rm obs exp rm obs exp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment