Skip to content

Commit

Permalink
Considering overlapped theoretical fragment ion multiple times.
Browse files Browse the repository at this point in the history
This is what Comet and Xolik do.
  • Loading branch information
fcyu committed Jan 30, 2018
1 parent 4f04394 commit 8040f53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 54 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>
</dependencies>

<repositories>
Expand Down
38 changes: 10 additions & 28 deletions src/main/java/proteomics/Types/SparseBooleanVector.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package proteomics.Types;

import java.util.HashSet;
import java.util.Map;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

import java.util.Set;

public class SparseBooleanVector {

private Set<Integer> sparse_vector = new HashSet<>();
private Multiset<Integer> sparse_vector = HashMultiset.create();

SparseBooleanVector(Set<Integer> sparse_vector) {
SparseBooleanVector(Multiset<Integer> sparse_vector) {
this.sparse_vector = sparse_vector;
}

Expand All @@ -18,43 +19,24 @@ public void put(int idx) {
sparse_vector.add(idx);
}

double norm2square() {
return sparse_vector.size();
}

public double dot(SparseVector other) { // caution: it will change the original Sparse Boolean Vector.
public double dot(SparseVector other) {
double output = 0;
sparse_vector.retainAll(other.getIdxSet());
for (int i : sparse_vector) {
for (Integer i : sparse_vector) {
output += other.get(i);
}
return output;
}

double dot(SparseBooleanVector other) {
Set<Integer> intersectedKeys = new HashSet<>(sparse_vector);
intersectedKeys.retainAll(other.sparse_vector);
return intersectedKeys.size();
}

public int size() {
return sparse_vector.size();
}

public boolean contains(int v) {
return sparse_vector.contains(v);
}

public Set<Integer> getIdxSet() {
return sparse_vector;
return sparse_vector.elementSet();
}

public boolean equals(Object other) {
if (other instanceof SparseBooleanVector) {
SparseBooleanVector temp = (SparseBooleanVector) other;
if (temp.size() == sparse_vector.size()) {
if (temp.sparse_vector.size() == sparse_vector.size()) {
for (int v : sparse_vector) {
if (!temp.contains(v)) {
if (!temp.sparse_vector.contains(v)) {
return false;
}
}
Expand Down
30 changes: 4 additions & 26 deletions src/test/java/proteomics/Types/SparseBooleanVectorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package proteomics.Types;

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -14,7 +16,7 @@ public class SparseBooleanVectorTest {

@Before
public void setUp() throws Exception {
Set<Integer> temp = new HashSet<>();
Multiset<Integer> temp = HashMultiset.create();
temp.add(1);
temp.add(3);
temp.add(23);
Expand All @@ -23,7 +25,7 @@ public void setUp() throws Exception {

@Test
public void put() throws Exception {
Set<Integer> temp = new HashSet<>();
Multiset<Integer> temp = HashMultiset.create();
temp.add(1);
temp.add(3);
temp.add(23);
Expand All @@ -34,11 +36,6 @@ public void put() throws Exception {
assertEquals(ground_truth, vector);
}

@Test
public void norm2square() throws Exception {
assertEquals(3, vector.norm2square(), 0);
}

@Test
public void dot() throws Exception {
SparseVector other = new SparseVector();
Expand All @@ -47,25 +44,6 @@ public void dot() throws Exception {
assertEquals(1.5f, vector.dot(other), 0);
}

@Test
public void dot1() throws Exception {
SparseBooleanVector other = new SparseBooleanVector();
other.put(1);
other.put(2);
assertEquals(1, vector.dot(other), 0);
}

@Test
public void size() throws Exception {
assertEquals(3, vector.size());
}

@Test
public void contains() throws Exception {
assertTrue(vector.contains(1));
assertFalse(vector.contains(2));
}

@Test
public void equals() throws Exception {
SparseBooleanVector other_1 = new SparseBooleanVector();
Expand Down

0 comments on commit 8040f53

Please sign in to comment.