### Question:
IdentityByStateClustering { public void write(OutputStream outputStream, List<IdentityByState> ibsList, List<String> samples) throws IOException { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); outputStreamWriter.write("IID1\tIID2\tDST\tZ0\tZ1\tZ2\n"); forEachPair(samples, (int firstSampleIndex, int secondSampleIndex, int compoundIndex) -> { outputStreamWriter.write(samples.get(firstSampleIndex)); outputStreamWriter.write("\t"); outputStreamWriter.write(samples.get(secondSampleIndex)); outputStreamWriter.write("\t"); outputStreamWriter.write(String.valueOf(ibsList.get(compoundIndex).getDistance())); for (int i = 0; i < 3; i++) { outputStreamWriter.write("\t"); outputStreamWriter.write(String.valueOf(ibsList.get(compoundIndex).ibs[i])); } outputStreamWriter.write("\n"); }); outputStreamWriter.flush(); }  List<IdentityByState> countIBS(List<Variant> variants, List<String> samples); List<IdentityByState> countIBS(List<Variant> variants, List<String> samples,
                                          IBDExpectedFrequencies expectedFreqs); List<IdentityByState> countIBS(Variant variant, List<String> samples); List<IdentityByState> countIBS(Variant variant, List<String> samples, IBDExpectedFrequencies expectedFreqs); List<IdentityByState> countIBS(Iterator<Variant> iterator, List<String> samples); List<IdentityByState> countIBS(Iterator<Variant> iterator, List<String> samples,
                                          IBDExpectedFrequencies expectedFreqs); List<IdentityByState> initCounts(List<String> samples); void countIBS(Variant variant, List<String> samples, List<IdentityByState> counts); int countSharedAlleles(int allelesCount, Genotype genotypeFirst, Genotype genotypeSecond); int getAmountOfPairs(int samplesCount); int getCompoundIndex(int first, int second); int getSecondSampleIndex(int compoundIndex); int getFirstSampleIndex(int compoundIndex, int secondSampleIndex); void forEachPair(List<String> samples, SamplePairConsumer<E> loopBody); void write(OutputStream outputStream, List<IdentityByState> ibsList, List<String> samples); static final int MAX_SAMPLES_ALLOWED; }### Answer:
@Test public void testWrite() throws Exception { String fileName = "ibs.vcf"; VariantFileMetadata fileMetadata = new VariantFileMetadata(fileName, "fid"); VariantStudyMetadata metadata = fileMetadata.toVariantStudyMetadata("sid"); String line; VariantVcfReader variantReader = new VariantVcfReader(metadata, IdentityByStateClusteringTest.class.getClassLoader().getResource(fileName).getPath()); variantReader.open(); variantReader.pre(); List<Variant> variants = variantReader.read(50); variantReader.post(); variantReader.close(); IdentityByStateClustering ibsc = new IdentityByStateClustering(); List<String> samples = new ArrayList<>(variants.get(0).getStudy(metadata.getId()).getSamplesName()); List<IdentityByState> ibses = ibsc.countIBS(variants, samples); OutputStream outputStream = new ByteArrayOutputStream(); ibsc.write(outputStream, ibses, samples); outputStream.close(); System.out.print(outputStream.toString()); }