PedigreeSampleValidator { public static Pedigree validate(Pedigree pedigree, SampleIdentifier proband, List<String> sampleNames) { Objects.requireNonNull(pedigree); Objects.requireNonNull(proband); Objects.requireNonNull(sampleNames); if (pedigree.isEmpty()) { return createAndValidateSingleSamplePedigree(proband, sampleNames); } return validatePedigree(pedigree, proband, sampleNames); } private  PedigreeSampleValidator(); static Pedigree validate(Pedigree pedigree, SampleIdentifier proband, List<String> sampleNames);  }
@Test public void pedigreeNotNullInConstructor() { assertThrows(NullPointerException.class, () -> PedigreeSampleValidator.validate(null, SampleIdentifier.of("sample", 0), Collections.emptyList()) ); }
@Test public void probandNotNullInConstructor() { assertThrows(NullPointerException.class, () -> PedigreeSampleValidator.validate(Pedigree.empty(), null, Collections.emptyList()) ); }
@Test public void sampleNamesNotNullInConstructor() { assertThrows(NullPointerException.class, () -> PedigreeSampleValidator.validate(Pedigree.empty(), SampleIdentifier.of("sample", 0), null) ); }
@Test public void createsSingleSamplePedigreeWithDefaultNameWhenSampleHasNoNameOrPedFile() { Pedigree result = PedigreeSampleValidator.validate(Pedigree.empty(), SampleIdentifier.defaultSample(), Collections .emptyList()); Pedigree expected = Pedigree.justProband(SampleIdentifier.defaultSample().getId()); assertThat(result, equalTo(expected)); }
@Test public void pedigreePresentAndSampleHasNoName() { Individual individual = Individual.builder().id("Nemo").build(); Pedigree input = Pedigree.of(individual); assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(input, SampleIdentifier.defaultSample(), Collections.emptyList()) ); }
@Test public void noPedigreeSampleIdentifierAndSampleNamesDoNotMatch() { assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(Pedigree.empty(), SampleIdentifier.of("Nemo", 0), ImmutableList.of("Adam")) ); }
@Test() public void singleSamplePedigreePresentAndAllIsWell() { Pedigree input = Pedigree.justProband("Adam"); Pedigree validated = PedigreeSampleValidator.validate(input, SampleIdentifier.of("Adam", 0), ImmutableList.of("Adam")); assertThat(input, equalTo(validated)); }
@Test public void createsSingleSamplePedigreeWhenSampleHasOnlyOneNamedMemberAndEmptyPedigree() { Pedigree result = PedigreeSampleValidator.validate(Pedigree.empty(), SampleIdentifier.of("Adam", 0), ImmutableList .of("Adam")); Pedigree expected = Pedigree.justProband("Adam"); assertThat(result, equalTo(expected)); }
@Test public void createsSingleSamplePedigreeWithSampleName() { Pedigree result = PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Seth", 0), ImmutableList .of("Seth")); assertThat(result, equalTo(VALID_PEDIGREE)); }
@Test public void throwsErrorWhenMultiSampleDataHasNoPedFile() { assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(Pedigree.empty(), SampleIdentifier.of("Cain", 2), ImmutableList.of("Adam", "Eve", "Cain", "Abel")) ); }
@Test public void createsPedigreeForNamedMultiSampleWithPedFile() { Pedigree result = PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Seth", 2), ImmutableList .of("Adam", "Eva", "Seth")); assertThat(result, equalTo(VALID_PEDIGREE)); }
@Test public void testCreatePedigreeWithMorePedigreeMembersThanSampleNames() { Pedigree result = PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Seth", 2), ImmutableList .of("Eva", "Seth")); assertThat(result, equalTo(VALID_PEDIGREE)); }
@Test public void testCreatePedigreeWithMoreSampleNamesThanPedigreeMembers() { assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Seth", 4), ImmutableList.of("Adam", "Eva", "Cain", "Abel", "Seth")) ); }
@Test public void testCreatePedigreeWithMoreSampleNamesThanPedigreeMembersAndMismatchedSample() { assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Seth", 3), ImmutableList.of("Adam", "Marge", "Abel", "Seth")) ); }
@Test public void testCreatePedigreeWithMismatchedSampleNameAndPedigreeMember() { assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Seth", 2), ImmutableList.of("Adam", "Marge", "Seth")) ); }
@Test public void testCreatePedigreeWithCompletelyMismatchedSampleNames() { assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Seth", 2), ImmutableList.of("Homer", "Marge", "Bart", "Lisa", "Maggie")) ); }
@Test public void testValidatePedigreeWithMisMatchedSampleIdentifier() { assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(VALID_PEDIGREE, SampleIdentifier.of("Homer", 2), ImmutableList.of("Adam", "Eva", "Seth")) ); }
@Test public void validatePedigreeWithUnaffectedProband() { Pedigree pedigree = Pedigree.of( Individual.builder() .id("Adam") .status(Individual.Status.UNAFFECTED) .build() ); assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(pedigree, SampleIdentifier.of("Adam", 0), ImmutableList.of("Adam")) ); }
@Test public void testCreatePedigreeWithMoreThanOneFamilyInFile() { Pedigree multiFamilyPed = Pedigree.of( Individual.builder() .familyId("Adams") .id("Adam") .sex(Individual.Sex.MALE) .status(Individual.Status.UNAFFECTED) .build(), Individual.builder() .familyId("Simpsons") .id("Homer") .sex(Individual.Sex.MALE) .status(Individual.Status.UNAFFECTED) .build() ); assertThrows(RuntimeException.class, () -> PedigreeSampleValidator.validate(multiFamilyPed, SampleIdentifier.of("Homer", 1), ImmutableList.of("Adam", "Homer")) ); }