Search in sources :

Example 6 with TableColumnCollection

use of org.broadinstitute.hellbender.utils.tsv.TableColumnCollection in project gatk-protected by broadinstitute.

the class XHMMSegmentCallerBaseIntegrationTest method writeChainInTempFile.

public static File writeChainInTempFile(final XHMMData chain) {
    final File result = createTempFile("chain-", ".tab");
    //final File result = new File("/tmp/input");
    final List<String> sampleNames = IntStream.range(0, chain.data.size()).mapToObj(a -> "SAMPLE_" + a).collect(Collectors.toList());
    final List<String> columnNames = new ArrayList<>(sampleNames.size() + 4);
    columnNames.addAll(Arrays.asList(TargetTableColumn.CONTIG.toString(), TargetTableColumn.START.toString(), TargetTableColumn.END.toString(), TargetTableColumn.NAME.toString()));
    columnNames.addAll(sampleNames);
    try (final TableWriter<Integer> writer = new TableWriter<Integer>(result, new TableColumnCollection(columnNames)) {

        @Override
        protected void composeLine(final Integer record, final DataLine dataLine) {
            dataLine.append(chain.targets.get(record).getContig()).append(chain.targets.get(record).getStart()).append(chain.targets.get(record).getEnd()).append(chain.targets.get(record).getName());
            for (final List<Double> sampleData : chain.data) {
                dataLine.append(sampleData.get(record));
            }
        }
    }) {
        writer.writeAllRecords(IntStream.range(0, chain.targets.size()).boxed().collect(Collectors.toList()));
    } catch (final IOException ex) {
        throw new UncheckedIOException(ex);
    }
    return result;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DataProvider(org.testng.annotations.DataProvider) org.broadinstitute.hellbender.tools.exome(org.broadinstitute.hellbender.tools.exome) Test(org.testng.annotations.Test) IOException(java.io.IOException) Random(java.util.Random) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) Collectors(java.util.stream.Collectors) File(java.io.File) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) File(java.io.File) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Example 7 with TableColumnCollection

use of org.broadinstitute.hellbender.utils.tsv.TableColumnCollection in project gatk by broadinstitute.

the class SexGenotypeDataCollection method write.

/**
     * Write the collection to a writer. If extended genotyping inference data is available, they will
     * be also written as optional columns.
     *
     * @param dataWriter an instance of {@link Writer}
     */
public void write(@Nonnull final Writer dataWriter) {
    if (sexGenotypeDataList.isEmpty()) {
        throw new IllegalStateException("The sex genotype data collection is empty");
    }
    /* check if extended genotyping information is available; first, check for nulls */
    boolean extended = true;
    if (sexGenotypeDataList.stream().filter(dat -> !dat.hasExtendedGenotypingInfo()).count() > 0) {
        extended = false;
    }
    Set<String> commonGenotypes = new HashSet<>();
    /* check if there is a non-empty intersection */
    if (extended) {
        /* pool all genotypes */
        commonGenotypes = new HashSet<>(sexGenotypeDataList.get(0).getSexGenotypesSet());
        for (final SexGenotypeData dat : sexGenotypeDataList) {
            commonGenotypes = Sets.intersection(commonGenotypes, dat.getSexGenotypesSet());
        }
        if (commonGenotypes.isEmpty()) {
            extended = false;
        }
    }
    final TableColumnCollection columns;
    if (extended) {
        final List<String> columnNames = new ArrayList<>();
        columnNames.addAll(SexGenotypeTableColumn.MANDATORY_SEX_GENOTYPE_COLUMNS.names());
        columnNames.addAll(commonGenotypes);
        columns = new TableColumnCollection(columnNames);
    } else {
        columns = new TableColumnCollection(SexGenotypeTableColumn.MANDATORY_SEX_GENOTYPE_COLUMNS.names());
    }
    try (final SexGenotypeTableWriter writer = new SexGenotypeTableWriter(dataWriter, columns)) {
        writer.writeAllRecords(sexGenotypeDataList);
    } catch (final IOException e) {
        throw new UserException.CouldNotCreateOutputFile("Could not write sex genotype data", e);
    }
}
Also used : UserException(org.broadinstitute.hellbender.exceptions.UserException) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Example 8 with TableColumnCollection

use of org.broadinstitute.hellbender.utils.tsv.TableColumnCollection in project gatk by broadinstitute.

the class CombineReadCountsIntegrationTest method createCountFile.

private void createCountFile(final File output, List<Target> targets, final String sample, final double[] count, final boolean useName, final boolean useCoordinates) throws IOException {
    final List<String> columnNames = new ArrayList<>();
    if (useCoordinates) {
        columnNames.add(TargetTableColumn.CONTIG.toString());
        columnNames.add(TargetTableColumn.START.toString());
        columnNames.add(TargetTableColumn.END.toString());
    }
    if (useName) {
        columnNames.add(TargetTableColumn.NAME.toString());
    }
    columnNames.add(sample);
    final TableColumnCollection columns = new TableColumnCollection(columnNames);
    final TableWriter<Integer> writer = TableUtils.writer(output, columns, (i, d) -> {
        final Target target = targets.get(i);
        final SimpleInterval interval = target.getInterval();
        if (useCoordinates)
            d.append(interval.getContig()).append(interval.getStart()).append(interval.getEnd());
        if (useName)
            d.append(target.getName());
        d.append(count[i]);
    });
    for (int i = 0; i < targets.size(); i++) writer.writeRecord(i);
    writer.close();
}
Also used : ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Example 9 with TableColumnCollection

use of org.broadinstitute.hellbender.utils.tsv.TableColumnCollection in project gatk by broadinstitute.

the class CombineReadCountsIntegrationTest method createTargetFile.

private File createTargetFile(final List<Target> targets) throws IOException {
    final File result = BaseTest.createTempFile("targets", ".tab");
    final TableWriter<Target> writer = TableUtils.writer(result, new TableColumnCollection(TargetTableColumn.CONTIG, TargetTableColumn.START, TargetTableColumn.END, TargetTableColumn.NAME), (t, dataLine) -> {
        final SimpleInterval interval = t.getInterval();
        dataLine.append(interval.getContig()).append(interval.getStart()).append(interval.getEnd()).append(t.getName());
    });
    for (final Target target : targets) writer.writeRecord(target);
    writer.close();
    return result;
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Example 10 with TableColumnCollection

use of org.broadinstitute.hellbender.utils.tsv.TableColumnCollection in project gatk by broadinstitute.

the class XHMMSegmentCallerBaseIntegrationTest method writeChainInTempFile.

public static File writeChainInTempFile(final XHMMData chain) {
    final File result = createTempFile("chain-", ".tab");
    //final File result = new File("/tmp/input");
    final List<String> sampleNames = IntStream.range(0, chain.data.size()).mapToObj(a -> "SAMPLE_" + a).collect(Collectors.toList());
    final List<String> columnNames = new ArrayList<>(sampleNames.size() + 4);
    columnNames.addAll(Arrays.asList(TargetTableColumn.CONTIG.toString(), TargetTableColumn.START.toString(), TargetTableColumn.END.toString(), TargetTableColumn.NAME.toString()));
    columnNames.addAll(sampleNames);
    try (final TableWriter<Integer> writer = new TableWriter<Integer>(result, new TableColumnCollection(columnNames)) {

        @Override
        protected void composeLine(final Integer record, final DataLine dataLine) {
            dataLine.append(chain.targets.get(record).getContig()).append(chain.targets.get(record).getStart()).append(chain.targets.get(record).getEnd()).append(chain.targets.get(record).getName());
            for (final List<Double> sampleData : chain.data) {
                dataLine.append(sampleData.get(record));
            }
        }
    }) {
        writer.writeAllRecords(IntStream.range(0, chain.targets.size()).boxed().collect(Collectors.toList()));
    } catch (final IOException ex) {
        throw new UncheckedIOException(ex);
    }
    return result;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DataProvider(org.testng.annotations.DataProvider) org.broadinstitute.hellbender.tools.exome(org.broadinstitute.hellbender.tools.exome) Test(org.testng.annotations.Test) IOException(java.io.IOException) Random(java.util.Random) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) Collectors(java.util.stream.Collectors) File(java.io.File) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) File(java.io.File) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Aggregations

TableColumnCollection (org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)20 DataLine (org.broadinstitute.hellbender.utils.tsv.DataLine)12 ArrayList (java.util.ArrayList)10 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)8 Arrays (java.util.Arrays)6 List (java.util.List)6 Random (java.util.Random)6 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 Stream (java.util.stream.Stream)6 UserException (org.broadinstitute.hellbender.exceptions.UserException)6 TableWriter (org.broadinstitute.hellbender.utils.tsv.TableWriter)6 DataProvider (org.testng.annotations.DataProvider)6 Test (org.testng.annotations.Test)6 File (java.io.File)4 IOException (java.io.IOException)4 BiFunction (java.util.function.BiFunction)4 Assert (org.testng.Assert)4 UncheckedIOException (java.io.UncheckedIOException)2 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)2