Search in sources :

Example 6 with TableWriter

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

the class ReadCountCollectionUtils method writerWithIntervals.

/**
     * Creates a new table writer that will output the target intervals.
     * @param writer where to output the table formatted content.
     * @param countColumnNames list of count column names.
     * @return never {@code null}.
     * @throws IOException if there is some low level IO problem creating the writer.
     * @throws IllegalArgumentException if {@code countColumnNames} is {@code null}, contains
     *  {@code null} or a non valid count column name (e.g. a reserved word).
     */
public static TableWriter<ReadCountRecord> writerWithIntervals(final Writer writer, final List<String> countColumnNames) throws IOException {
    final List<String> columnNames = new ArrayList<>();
    columnNames.add(TargetTableColumn.CONTIG.toString());
    columnNames.add(TargetTableColumn.START.toString());
    columnNames.add(TargetTableColumn.END.toString());
    columnNames.add(TargetTableColumn.NAME.toString());
    columnNames.addAll(Utils.nonNull(countColumnNames));
    final TableColumnCollection columns = new TableColumnCollection(columnNames);
    return new TableWriter<ReadCountRecord>(writer, columns) {

        @Override
        protected void composeLine(final ReadCountRecord record, final DataLine dataLine) {
            final SimpleInterval interval = record.getTarget().getInterval();
            if (interval == null) {
                throw new IllegalStateException("invalid combination of targets with and without intervals defined");
            }
            dataLine.append(interval.getContig()).append(interval.getStart()).append(interval.getEnd()).append(record.getTarget().getName());
            record.appendCountsTo(dataLine);
        }
    };
}
Also used : TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Aggregations

DataLine (org.broadinstitute.hellbender.utils.tsv.DataLine)6 TableColumnCollection (org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)6 TableWriter (org.broadinstitute.hellbender.utils.tsv.TableWriter)6 File (java.io.File)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Random (java.util.Random)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)2 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)2 org.broadinstitute.hellbender.tools.exome (org.broadinstitute.hellbender.tools.exome)2 CopyNumberTriState (org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 DataProvider (org.testng.annotations.DataProvider)2 Test (org.testng.annotations.Test)2