SampleIdentifierUtil { public static SampleIdentifier createProbandIdentifier(String probandSampleName, List<String> sampleNames) { logger.debug("Creating sample identifier for proband '{}'", probandSampleName); int numSamples = sampleNames.size(); if (probandSampleName.isEmpty() && numSamples > 1) { String message = String.format("Proband sample name not specified. Expected single sample VCF but got %d sample names - %s. Please check your sample and analysis files match.", numSamples, sampleNames); logger.error(message); throw new SampleMismatchException(message); } if (probandSampleName.isEmpty() && numSamples == 1) { String vcfSampleName = sampleNames.get(0); logger.info("Proband sample name not specified - using sample name '{}' from VCF", vcfSampleName); return SampleIdentifier.of(vcfSampleName, 0); } if (probandSampleName.isEmpty() && numSamples == 0) { SampleIdentifier defaultSampleIdentifier = SampleIdentifier.defaultSample(); logger.info("Proband sample name not specified and none found in sample names - using default sample name '{}'", defaultSampleIdentifier .getId()); return defaultSampleIdentifier; } return getMultiSampleProbandSampleIdentifier(probandSampleName, sampleNames); } private  SampleIdentifierUtil(); static SampleIdentifier createProbandIdentifier(String probandSampleName, List<String> sampleNames);  }
@Test public void testGetProbandSampleIdWithEmptyProbandNameAndEmptySampleNames() { SampleIdentifier sampleId = SampleIdentifierUtil.createProbandIdentifier("", Collections.emptyList()); assertThat(sampleId, equalTo(SampleIdentifier.defaultSample())); }
@Test public void testGetProbandSampleIdWithProbandNameAndSampleNameMatch() { SampleIdentifier sampleId = SampleIdentifierUtil.createProbandIdentifier("David", Collections.singletonList("David")); assertThat(sampleId, equalTo(SampleIdentifier.of("David", 0))); }
@Test public void testGetProbandSampleIdWithProbandNameAndEmptySampleNames() { assertThrows(SampleMismatchException.class, () -> SampleIdentifierUtil.createProbandIdentifier("David", Collections.emptyList()) ); }
@Test public void testGetProbandSampleIdWithProbandNameAndSampleNameMisMatch() { assertThrows(SampleMismatchException.class, () -> SampleIdentifierUtil.createProbandIdentifier("David", Collections.singletonList("Slartibartfast")) ); }
@Test public void testGetProbandSampleIdWithProbandNameAndSampleNamesMisMatch() { assertThrows(SampleMismatchException.class, () -> SampleIdentifierUtil.createProbandIdentifier("David", Arrays.asList("Slartibartfast", "Homer")) ); }
@Test public void testGetProbandSampleIdWithEmptyProbandNameAndSampleNamesMisMatch() { assertThrows(SampleMismatchException.class, () -> SampleIdentifierUtil.createProbandIdentifier("", Arrays.asList("Slartibartfast", "Homer")) ); }
@Test public void testGetProbandSampleIdWithProbandNameAndSampleNamesMatchFirstInList() { SampleIdentifier sampleId = SampleIdentifierUtil.createProbandIdentifier("David", Arrays.asList("David", "Slartibartfast")); assertThat(sampleId, equalTo(SampleIdentifier.of("David", 0))); }
@Test public void testGetProbandSampleIdWithProbandNameAndSampleNamesMatchNotFirstInList() { SampleIdentifier sampleId = SampleIdentifierUtil.createProbandIdentifier("David", Arrays.asList("Slartibartfast", "David")); assertThat(sampleId, equalTo(SampleIdentifier.of("David", 1))); }
@Test public void testGetProbandSampleNameWithEmptyProbandNameAndOneSampleNameInList() { SampleIdentifier sampleId = SampleIdentifierUtil.createProbandIdentifier("", Collections.singletonList("David")); assertThat(sampleId, equalTo(SampleIdentifier.of("David", 0))); }
@Test public void testGetProbandSampleNameWithEmptyProbandNameAndMultipleSampleNamesInList() { assertThrows(SampleMismatchException.class, () -> SampleIdentifierUtil.createProbandIdentifier("", Arrays.asList("Slartibartfast", "David")) ); }