Search in sources :

Example 56 with Predicate

use of java.util.function.Predicate in project hmftools by hartwigmedical.

the class BachelorEligibility method fromMap.

static BachelorEligibility fromMap(final Map<String, Program> input) {
    final BachelorEligibility result = new BachelorEligibility();
    for (final Program program : input.values()) {
        final Multimap<String, String> geneToEnsemblMap = HashMultimap.create();
        program.getPanel().stream().map(ProgramPanel::getGene).flatMap(Collection::stream).forEach(g -> geneToEnsemblMap.put(g.getName(), g.getEnsembl()));
        // NOTE: copy number and SVs are untested/unverified for now, but leave in support for them
        // process copy number sections
        final List<Predicate<GeneCopyNumber>> cnvPredicates = Lists.newArrayList();
        for (final ProgramPanel panel : program.getPanel()) {
            final List<GeneIdentifier> genes = panel.getGene();
            if (panel.getEffect().contains(OtherEffect.HOMOZYGOUS_DELETION)) {
                final Predicate<GeneCopyNumber> geneCopyNumberPredicate = cnv -> genes.stream().anyMatch(g -> g.getEnsembl().equals(cnv.transcriptID()));
                // TODO: we are matching on transcript ID here but we only have canonical transcripts in our panel file
                cnvPredicates.add(geneCopyNumberPredicate);
            }
        }
        // process structural variant disruptions
        final List<Predicate<HmfGenomeRegion>> disruptionPredicates = Lists.newArrayList();
        for (final ProgramPanel panel : program.getPanel()) {
            final List<GeneIdentifier> genes = panel.getGene();
            if (panel.getEffect().contains(OtherEffect.GENE_DISRUPTION)) {
                final Predicate<HmfGenomeRegion> disruptionPredicate = sv -> genes.stream().anyMatch(g -> g.getEnsembl().equals(sv.transcriptID()));
                // TODO: we are matching on transcript ID here but we only have canonical transcripts in our panel file
                disruptionPredicates.add(disruptionPredicate);
            }
        }
        // process variants from vcf
        final List<Predicate<VariantModel>> panelPredicates = Lists.newArrayList();
        List<String> requiredEffects = Lists.newArrayList();
        List<String> panelTranscripts = Lists.newArrayList();
        for (final ProgramPanel panel : program.getPanel()) {
            final List<GeneIdentifier> genes = panel.getGene();
            // take up a collection of the effects to search for
            requiredEffects = panel.getSnpEffect().stream().map(SnpEffect::value).collect(Collectors.toList());
            panelTranscripts = genes.stream().map(GeneIdentifier::getEnsembl).collect(Collectors.toList());
            final List<String> effects = requiredEffects;
            final Predicate<VariantModel> panelPredicate = v -> genes.stream().anyMatch(p -> v.sampleAnnotations().stream().anyMatch(a -> a.featureID().equals(p.getEnsembl()) && effects.stream().anyMatch(x -> a.effects().contains(x))));
            panelPredicates.add(panelPredicate);
            // update query targets
            for (final GeneIdentifier g : genes) {
                final HmfGenomeRegion region = allTranscriptsMap.get(g.getEnsembl());
                if (region == null) {
                    final HmfGenomeRegion namedRegion = allGenesMap.get(g.getName());
                    if (namedRegion == null) {
                        LOGGER.warn("Program {} gene {} non-canonical transcript {} couldn't find region, transcript will be skipped", program.getName(), g.getName(), g.getEnsembl());
                    // just skip this gene for now
                    } else {
                        result.variantLocationsToQuery.add(namedRegion);
                    }
                } else {
                    result.variantLocationsToQuery.add(region);
                }
            }
        }
        final Predicate<VariantModel> inPanel = v -> panelPredicates.stream().anyMatch(p -> p.test(v));
        final Predicate<VariantModel> inBlacklist = new BlacklistPredicate(geneToEnsemblMap.values(), program.getBlacklist());
        final Predicate<VariantModel> inWhitelist = new WhitelistPredicate(geneToEnsemblMap, program.getWhitelist());
        final Predicate<VariantModel> snvPredicate = v -> inPanel.test(v) ? !inBlacklist.test(v) : inWhitelist.test(v);
        final Predicate<GeneCopyNumber> copyNumberPredicate = cnv -> cnvPredicates.stream().anyMatch(p -> p.test(cnv)) && cnv.minCopyNumber() < MAX_COPY_NUMBER_FOR_LOSS;
        final Predicate<HmfGenomeRegion> disruptionPredicate = disruption -> disruptionPredicates.stream().anyMatch(p -> p.test(disruption));
        BachelorProgram bachelorProgram = new BachelorProgram(program.getName(), snvPredicate, copyNumberPredicate, disruptionPredicate, requiredEffects, panelTranscripts);
        result.programs.add(bachelorProgram);
    }
    return result;
}
Also used : GeneIdentifier(nl.hartwigmedicalfoundation.bachelor.GeneIdentifier) ProgramPanel(nl.hartwigmedicalfoundation.bachelor.ProgramPanel) Genotype(htsjdk.variant.variantcontext.Genotype) CloseableIterator(htsjdk.samtools.util.CloseableIterator) SOMATIC_DELETION(com.hartwig.hmftools.bachelor.EligibilityReport.ReportType.SOMATIC_DELETION) SOMATIC_DISRUPTION(com.hartwig.hmftools.bachelor.EligibilityReport.ReportType.SOMATIC_DISRUPTION) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) Multimap(com.google.common.collect.Multimap) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) HmfGenePanelSupplier(com.hartwig.hmftools.genepanel.HmfGenePanelSupplier) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) Map(java.util.Map) StructuralVariantType(com.hartwig.hmftools.common.variant.structural.StructuralVariantType) GenomePositions(com.hartwig.hmftools.common.position.GenomePositions) SnpEffect(nl.hartwigmedicalfoundation.bachelor.SnpEffect) GERMLINE_DELETION(com.hartwig.hmftools.bachelor.EligibilityReport.ReportType.GERMLINE_DELETION) SortedSetMultimap(com.google.common.collect.SortedSetMultimap) OtherEffect(nl.hartwigmedicalfoundation.bachelor.OtherEffect) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Program(nl.hartwigmedicalfoundation.bachelor.Program) Set(java.util.Set) WhitelistPredicate(com.hartwig.hmftools.bachelor.predicates.WhitelistPredicate) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) GeneIdentifier(nl.hartwigmedicalfoundation.bachelor.GeneIdentifier) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) VariantContext(htsjdk.variant.variantcontext.VariantContext) HmfExonRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfExonRegion) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) BlacklistPredicate(com.hartwig.hmftools.bachelor.predicates.BlacklistPredicate) BlacklistPredicate(com.hartwig.hmftools.bachelor.predicates.BlacklistPredicate) Program(nl.hartwigmedicalfoundation.bachelor.Program) WhitelistPredicate(com.hartwig.hmftools.bachelor.predicates.WhitelistPredicate) Predicate(java.util.function.Predicate) WhitelistPredicate(com.hartwig.hmftools.bachelor.predicates.WhitelistPredicate) BlacklistPredicate(com.hartwig.hmftools.bachelor.predicates.BlacklistPredicate) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) SnpEffect(nl.hartwigmedicalfoundation.bachelor.SnpEffect) ProgramPanel(nl.hartwigmedicalfoundation.bachelor.ProgramPanel) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion)

Example 57 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class DoublePredicateAssert_rejects_Test method should_fail_when_predicate_accepts_value_with_string_description.

@Test
public void should_fail_when_predicate_accepts_value_with_string_description() {
    DoublePredicate predicate = val -> val <= 2;
    Predicate<Double> wrapPredicate = predicate::test;
    double expectedValue = 2.0;
    thrown.expectAssertionError("[test] " + shouldNotAccept(wrapPredicate, expectedValue, PredicateDescription.GIVEN).create());
    assertThat(predicate).as("test").rejects(expectedValue);
}
Also used : DoublePredicateAssert(org.assertj.core.api.DoublePredicateAssert) NoElementsShouldMatch.noElementsShouldMatch(org.assertj.core.error.NoElementsShouldMatch.noElementsShouldMatch) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PredicateDescription(org.assertj.core.presentation.PredicateDescription) ShouldNotAccept.shouldNotAccept(org.assertj.core.error.ShouldNotAccept.shouldNotAccept) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest) DoublePredicate(java.util.function.DoublePredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) DoublePredicate(java.util.function.DoublePredicate) Test(org.junit.Test) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest)

Example 58 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class DoublePredicateAssert_rejects_Test method should_pass_when_predicate_accepts_no_value.

@Test
public void should_pass_when_predicate_accepts_no_value() {
    DoublePredicate predicate = num -> num <= 2;
    assertThat(predicate).rejects(3.0, 4.0, 5.0);
}
Also used : DoublePredicateAssert(org.assertj.core.api.DoublePredicateAssert) NoElementsShouldMatch.noElementsShouldMatch(org.assertj.core.error.NoElementsShouldMatch.noElementsShouldMatch) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PredicateDescription(org.assertj.core.presentation.PredicateDescription) ShouldNotAccept.shouldNotAccept(org.assertj.core.error.ShouldNotAccept.shouldNotAccept) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest) DoublePredicate(java.util.function.DoublePredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) DoublePredicate(java.util.function.DoublePredicate) Test(org.junit.Test) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest)

Example 59 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class IntPredicateAssert_accepts_Test method should_fail_when_predicate_does_not_accept_values.

@Test
public void should_fail_when_predicate_does_not_accept_values() {
    IntPredicate predicate = val -> val <= 2;
    int[] matchValues = new int[] { 1, 2, 3 };
    thrown.expectAssertionError(elementsShouldMatch(matchValues, 3, PredicateDescription.GIVEN).create());
    assertThat(predicate).accepts(matchValues);
}
Also used : IntPredicateAssert(org.assertj.core.api.IntPredicateAssert) Predicate(java.util.function.Predicate) IntPredicateAssertBaseTest(org.assertj.core.api.IntPredicateAssertBaseTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PredicateDescription(org.assertj.core.presentation.PredicateDescription) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) Test(org.junit.Test) ShouldAccept.shouldAccept(org.assertj.core.error.ShouldAccept.shouldAccept) IntPredicate(java.util.function.IntPredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) ElementsShouldMatch.elementsShouldMatch(org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch) Mockito.verify(org.mockito.Mockito.verify) IntPredicate(java.util.function.IntPredicate) IntPredicateAssertBaseTest(org.assertj.core.api.IntPredicateAssertBaseTest) Test(org.junit.Test)

Example 60 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class IntPredicateAssert_accepts_Test method should_pass_when_predicate_accepts_value.

@Test
public void should_pass_when_predicate_accepts_value() {
    IntPredicate predicate = val -> val <= 2;
    assertThat(predicate).accepts(1);
}
Also used : IntPredicateAssert(org.assertj.core.api.IntPredicateAssert) Predicate(java.util.function.Predicate) IntPredicateAssertBaseTest(org.assertj.core.api.IntPredicateAssertBaseTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PredicateDescription(org.assertj.core.presentation.PredicateDescription) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) Test(org.junit.Test) ShouldAccept.shouldAccept(org.assertj.core.error.ShouldAccept.shouldAccept) IntPredicate(java.util.function.IntPredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) ElementsShouldMatch.elementsShouldMatch(org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch) Mockito.verify(org.mockito.Mockito.verify) IntPredicate(java.util.function.IntPredicate) IntPredicateAssertBaseTest(org.assertj.core.api.IntPredicateAssertBaseTest) Test(org.junit.Test)

Aggregations

Predicate (java.util.function.Predicate)589 List (java.util.List)266 ArrayList (java.util.ArrayList)170 Collectors (java.util.stream.Collectors)167 Map (java.util.Map)164 Set (java.util.Set)137 Test (org.junit.Test)133 IOException (java.io.IOException)122 Collections (java.util.Collections)118 Arrays (java.util.Arrays)110 HashMap (java.util.HashMap)105 Collection (java.util.Collection)93 Optional (java.util.Optional)87 HashSet (java.util.HashSet)85 Stream (java.util.stream.Stream)69 Function (java.util.function.Function)61 File (java.io.File)60 Iterator (java.util.Iterator)55 Logger (org.slf4j.Logger)53 LoggerFactory (org.slf4j.LoggerFactory)52