Search in sources :

Example 51 with Input

use of com.esotericsoftware.kryo.io.Input in project gatk by broadinstitute.

the class ReadMetadataTest method serializationTest.

@Test(groups = "spark")
void serializationTest() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithGroups(1, 1, 10000000, 1);
    final ReadMetadata.ReadGroupFragmentStatistics statistics = new ReadMetadata.ReadGroupFragmentStatistics(400, 175, 20);
    final Set<Integer> crossContigIgnoreSet = new HashSet<>(3);
    crossContigIgnoreSet.add(0);
    final ReadMetadata readMetadata = new ReadMetadata(crossContigIgnoreSet, header, statistics, 1, 1L, 1L, 1);
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final Output out = new Output(bos);
    final Kryo kryo = new Kryo();
    kryo.writeClassAndObject(out, readMetadata);
    out.flush();
    final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    final Input in = new Input(bis);
    final ReadMetadata readMetadata2 = (ReadMetadata) kryo.readClassAndObject(in);
    Assert.assertEquals(readMetadata, readMetadata2);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Kryo(com.esotericsoftware.kryo.Kryo) HashSet(java.util.HashSet) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 52 with Input

use of com.esotericsoftware.kryo.io.Input in project gatk by broadinstitute.

the class NovelAdjacencyReferenceLocationsUnitTest method testKryoSerializer.

@Test(groups = "sv")
void testKryoSerializer() throws IOException {
    // uses inversion subclass for testing
    final NovelAdjacencyReferenceLocations novelAdjacencyReferenceLocations1 = getBreakpoints("asm00001:tig0001", "foo");
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final Output out = new Output(bos);
    final Kryo kryo = new Kryo();
    kryo.writeClassAndObject(out, novelAdjacencyReferenceLocations1);
    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, novelAdjacencyReferenceLocations1);
}
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) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 53 with Input

use of com.esotericsoftware.kryo.io.Input 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 54 with Input

use of com.esotericsoftware.kryo.io.Input 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 55 with Input

use of com.esotericsoftware.kryo.io.Input 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)

Aggregations

Input (com.esotericsoftware.kryo.io.Input)73 Kryo (com.esotericsoftware.kryo.Kryo)37 Output (com.esotericsoftware.kryo.io.Output)28 ByteArrayInputStream (java.io.ByteArrayInputStream)23 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 Test (org.junit.Test)19 Slice (com.datatorrent.netlet.util.Slice)9 Test (org.testng.annotations.Test)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Schema (co.cask.cdap.api.data.schema.Schema)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 ObjectInput (java.io.ObjectInput)2