Search in sources :

Example 76 with Kryo

use of com.esotericsoftware.kryo.Kryo in project gatk by broadinstitute.

the class BreakpointEvidenceTest method serializationTest.

@Test(groups = "spark")
void serializationTest() {
    final List<BreakpointEvidence> evidenceList = new ArrayList<>(7);
    final SAMFileHeader samHeader = ArtificialReadUtils.createArtificialSamHeader();
    final ReadMetadata.ReadGroupFragmentStatistics groupStatistics = new ReadMetadata.ReadGroupFragmentStatistics(400, 175, 20);
    final ReadMetadata metadata = new ReadMetadata(Collections.emptySet(), samHeader, groupStatistics, 1, 2L, 2L, 1);
    final List<GATKRead> readPair = ArtificialReadUtils.createPair(samHeader, "firstReadPair", 101, 1010, 1382, false, false);
    final GATKRead read = readPair.get(0);
    evidenceList.add(new BreakpointEvidence.SplitRead(read, metadata, true));
    evidenceList.add(new BreakpointEvidence.LargeIndel(read, metadata, read.getStart() + 50));
    evidenceList.add(new BreakpointEvidence.MateUnmapped(read, metadata));
    evidenceList.add(new BreakpointEvidence.InterContigPair(read, metadata));
    evidenceList.add(new BreakpointEvidence.OutiesPair(read, metadata));
    evidenceList.add(new BreakpointEvidence.SameStrandPair(read, metadata));
    evidenceList.add(new BreakpointEvidence.WeirdTemplateSize(read, metadata));
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final Output out = new Output(bos);
    final Kryo kryo = new Kryo();
    kryo.writeClassAndObject(out, evidenceList);
    out.flush();
    final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    final Input in = new Input(bis);
    @SuppressWarnings("unchecked") final List<BreakpointEvidence> evidenceList2 = (List<BreakpointEvidence>) kryo.readClassAndObject(in);
    Assert.assertEquals(evidenceList.size(), evidenceList2.size());
    for (int idx = 0; idx != evidenceList.size(); ++idx) {
        Assert.assertEquals(evidenceList.get(idx).toString(), evidenceList2.get(idx).toString());
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ArrayList(java.util.ArrayList) List(java.util.List) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Kryo(com.esotericsoftware.kryo.Kryo) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 77 with Kryo

use of com.esotericsoftware.kryo.Kryo in project gatk by broadinstitute.

the class NovelAdjacencyReferenceLocationsUnitTest method seeIfItWorks.

private static void seeIfItWorks(final NovelAdjacencyReferenceLocations breakpoints, final NovelAdjacencyReferenceLocations.EndConnectionType expectedEndConnectionType, final SimpleInterval expectedLeftBreakpoint, final SimpleInterval expectedRightBreakpoint, final SimpleInterval expectedRepeatUnitRefSpan, final String expectedHomology, final String expectedInsertion, final int expectedRefDupNum, final int expectedCtgDupNum, final List<String> expectedTandupCigarStrings) {
    Assert.assertEquals(breakpoints.leftJustifiedLeftRefLoc, expectedLeftBreakpoint);
    Assert.assertEquals(breakpoints.leftJustifiedRightRefLoc, expectedRightBreakpoint);
    Assert.assertEquals(breakpoints.endConnectionType, expectedEndConnectionType);
    Assert.assertEquals(breakpoints.complication.getHomologyForwardStrandRep(), expectedHomology);
    Assert.assertEquals(breakpoints.complication.getInsertedSequenceForwardStrandRep(), expectedInsertion);
    Assert.assertEquals(breakpoints.complication.getDupSeqRepeatUnitRefSpan(), expectedRepeatUnitRefSpan);
    Assert.assertEquals(breakpoints.complication.getDupSeqRepeatNumOnRef(), expectedRefDupNum);
    Assert.assertEquals(breakpoints.complication.getDupSeqRepeatNumOnCtg(), expectedCtgDupNum);
    Assert.assertEquals(breakpoints.complication.getCigarStringsForDupSeqOnCtg(), expectedTandupCigarStrings);
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final Output out = new Output(bos);
    final Kryo kryo = new Kryo();
    kryo.writeClassAndObject(out, breakpoints);
    out.flush();
    final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    final Input in = new Input(bis);
    @SuppressWarnings("unchecked") final NovelAdjacencyReferenceLocations roundTrip = (NovelAdjacencyReferenceLocations) kryo.readClassAndObject(in);
    Assert.assertEquals(roundTrip, breakpoints);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 78 with Kryo

use of com.esotericsoftware.kryo.Kryo in project gatk by broadinstitute.

the class PathSeqFilterSpark method doKmerFiltering.

@SuppressWarnings("unchecked")
private JavaRDD<GATKRead> doKmerFiltering(final JavaSparkContext ctx, final JavaRDD<GATKRead> reads) {
    final PipelineOptions options = getAuthenticatedGCSOptions();
    Input input = new Input(BucketUtils.openFile(KMER_LIB_PATH));
    Kryo kryo = new Kryo();
    kryo.setReferences(false);
    Set<SVKmer> kmerLibSet = (HopscotchSet<SVKmer>) kryo.readClassAndObject(input);
    return reads.filter(new ContainsKmerReadFilterSpark(ctx.broadcast(kmerLibSet), KMER_SIZE));
}
Also used : ContainsKmerReadFilterSpark(org.broadinstitute.hellbender.tools.spark.sv.ContainsKmerReadFilterSpark) Input(com.esotericsoftware.kryo.io.Input) HopscotchSet(org.broadinstitute.hellbender.tools.spark.utils.HopscotchSet) SVKmer(org.broadinstitute.hellbender.tools.spark.sv.SVKmer) PipelineOptions(com.google.cloud.dataflow.sdk.options.PipelineOptions) Kryo(com.esotericsoftware.kryo.Kryo)

Example 79 with Kryo

use of com.esotericsoftware.kryo.Kryo in project gatk by broadinstitute.

the class PathSeqKmerSpark method runTool.

/** Get the list of distinct kmers in the reference, and write them to a file as a HopScotchSet. */
@Override
protected void runTool(final JavaSparkContext ctx) {
    final SAMFileHeader hdr = getHeaderForReads();
    SAMSequenceDictionary dict = null;
    if (hdr != null)
        dict = hdr.getSequenceDictionary();
    final PipelineOptions options = getAuthenticatedGCSOptions();
    final ReferenceMultiSource referenceMultiSource = getReference();
    final List<SVKmer> kmerList = findKmers(ctx, KMER_SIZE, referenceMultiSource, options, dict);
    final HopscotchSet<SVKmer> kmerSet = new HopscotchSet<>(kmerList);
    final Output output = new Output(BucketUtils.createFile(OUTPUT_FILE));
    final Kryo kryo = new Kryo();
    kryo.setReferences(false);
    kryo.writeClassAndObject(output, kmerSet);
    output.close();
}
Also used : HopscotchSet(org.broadinstitute.hellbender.tools.spark.utils.HopscotchSet) ReferenceMultiSource(org.broadinstitute.hellbender.engine.datasources.ReferenceMultiSource) PipelineOptions(com.google.cloud.dataflow.sdk.options.PipelineOptions) Output(com.esotericsoftware.kryo.io.Output) SAMFileHeader(htsjdk.samtools.SAMFileHeader) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Kryo(com.esotericsoftware.kryo.Kryo)

Example 80 with Kryo

use of com.esotericsoftware.kryo.Kryo in project gatk by broadinstitute.

the class PSUtilsTest method testWriteTwoKryo.

@Test(expectedExceptions = UserException.CouldNotCreateOutputFile.class)
@SuppressWarnings("unchecked")
public void testWriteTwoKryo() throws Exception {
    final File tempFile = createTempFile("test", ".dat");
    final Integer int_in = 29382;
    final String str_in = "test string";
    PSUtils.writeKryoTwo(tempFile.getPath(), int_in, str_in);
    final Kryo kryo = new Kryo();
    kryo.setReferences(false);
    final Input input = new Input(BucketUtils.openFile(tempFile.getPath()));
    final Integer int_out = (Integer) kryo.readClassAndObject(input);
    final String str_out = (String) kryo.readClassAndObject(input);
    input.close();
    Assert.assertEquals(int_in, int_out);
    Assert.assertEquals(str_in, str_out);
    // Point to a subdir that does not exist, so that we get a FNF excpetion
    PSUtils.writeKryoTwo(tempFile.getAbsolutePath() + "/bad_dir/bad_subdir/", int_out, str_out);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) File(java.io.File) Kryo(com.esotericsoftware.kryo.Kryo) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)94 Input (com.esotericsoftware.kryo.io.Input)37 Output (com.esotericsoftware.kryo.io.Output)34 Test (org.junit.Test)26 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 ByteArrayInputStream (java.io.ByteArrayInputStream)17 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)14 File (java.io.File)10 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)10 List (java.util.List)9 Map (java.util.Map)8 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)7 Path (org.apache.hadoop.fs.Path)7 BigIntegerSerializer (com.esotericsoftware.kryo.serializers.DefaultSerializers.BigIntegerSerializer)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 DefaultPartition (com.datatorrent.api.DefaultPartition)4 CountDownLatch (java.util.concurrent.CountDownLatch)4