Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #73 from deflaux/master
Browse files Browse the repository at this point in the history
Add V1 version of call comparator.
  • Loading branch information
deflaux committed Dec 2, 2015
2 parents 70d6414 + 3f5527f commit b322082
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
*/
package com.google.cloud.genomics.utils.grpc;

import java.util.Comparator;
import java.util.List;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
import com.google.genomics.v1.Variant;
import com.google.genomics.v1.VariantCall;

public class VariantUtils {

Expand Down Expand Up @@ -93,5 +96,16 @@ public boolean apply(Variant variant) {
*/
public static final Predicate<Variant> IS_NON_VARIANT_SEGMENT = Predicates.or(
IS_NON_VARIANT_SEGMENT_WITH_MISSING_ALT, IS_NON_VARIANT_SEGMENT_WITH_GATK_ALT);

/**
* Comparator for sorting calls by call set name.
*/
public static final Comparator<VariantCall> CALL_COMPARATOR = Ordering.natural().onResultOf(
new Function<VariantCall, String>() {
@Override
public String apply(VariantCall call) {
return call.getCallSetName();
}
});

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.Test;

import com.google.genomics.v1.Variant;
import com.google.genomics.v1.VariantCall;

public class VariantUtilsTest {

Expand Down Expand Up @@ -82,4 +83,19 @@ public void testIsVariant() {
.setReferenceName("chr7").setStart(200000).setEnd(200001).setReferenceBases("A")
.addAlternateBases(VariantUtils.GATK_NON_VARIANT_SEGMENT_ALT).build()));
}

@Test
public void testCallComparator() {
assertTrue(0 == VariantUtils.CALL_COMPARATOR.compare(
VariantCall.newBuilder().setCallSetName("NA12883").build(),
VariantCall.newBuilder().setCallSetName("NA12883").build()));

assertTrue(0 > VariantUtils.CALL_COMPARATOR.compare(
VariantCall.newBuilder().setCallSetName("NA12883").build(),
VariantCall.newBuilder().setCallSetName("NA12884").build()));

assertTrue(0 < VariantUtils.CALL_COMPARATOR.compare(
VariantCall.newBuilder().setCallSetName("NA12884").build(),
VariantCall.newBuilder().setCallSetName("NA12883").build()));
}
}

0 comments on commit b322082

Please sign in to comment.