-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Spark Kryo serializer for SAMRecords.
This improves the serialized size considerably, which has a very big effect on the amount of data going through the shuffle.
- Loading branch information
Showing
4 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...java/org/broadinstitute/hellbender/engine/spark/SAMRecordToGATKReadAdapterSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.broadinstitute.hellbender.engine.spark; | ||
|
||
import com.esotericsoftware.kryo.Kryo; | ||
import com.esotericsoftware.kryo.Serializer; | ||
import com.esotericsoftware.kryo.io.Input; | ||
import com.esotericsoftware.kryo.io.Output; | ||
import htsjdk.samtools.BAMRecordCodec; | ||
import htsjdk.samtools.DefaultSAMRecordFactory; | ||
import org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter; | ||
import org.seqdoop.hadoop_bam.LazyBAMRecordFactory; | ||
|
||
public class SAMRecordToGATKReadAdapterSerializer extends Serializer<SAMRecordToGATKReadAdapter> { | ||
|
||
private BAMRecordCodec lazyCodec = new BAMRecordCodec(null, new LazyBAMRecordFactory()); | ||
|
||
@Override | ||
public void write(Kryo kryo, Output output, SAMRecordToGATKReadAdapter adapter) { | ||
final BAMRecordCodec codec = new BAMRecordCodec(adapter.getSamRecord().getHeader(), | ||
DefaultSAMRecordFactory.getInstance()); | ||
codec.setOutputStream(output); | ||
codec.encode(adapter.getSamRecord()); | ||
} | ||
|
||
@Override | ||
public SAMRecordToGATKReadAdapter read(Kryo kryo, Input input, Class<SAMRecordToGATKReadAdapter> type) { | ||
lazyCodec.setInputStream(input); | ||
return (SAMRecordToGATKReadAdapter) SAMRecordToGATKReadAdapter.sparkReadAdapter(lazyCodec.decode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters