-
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.
Support reading VCF files from Hadoop.
- Loading branch information
Showing
5 changed files
with
97 additions
and
7 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
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
59 changes: 59 additions & 0 deletions
59
.../java/org/broadinstitute/hellbender/engine/dataflow/datasources/VariantsHadoopSource.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,59 @@ | ||
package org.broadinstitute.hellbender.engine.dataflow.datasources; | ||
|
||
import com.cloudera.dataflow.hadoop.HadoopIO; | ||
import com.cloudera.dataflow.hadoop.WritableCoder; | ||
import com.google.cloud.dataflow.sdk.Pipeline; | ||
import com.google.cloud.dataflow.sdk.coders.KvCoder; | ||
import com.google.cloud.dataflow.sdk.transforms.DoFn; | ||
import com.google.cloud.dataflow.sdk.transforms.ParDo; | ||
import com.google.cloud.dataflow.sdk.values.KV; | ||
import com.google.cloud.dataflow.sdk.values.PCollection; | ||
import com.google.common.base.Joiner; | ||
import htsjdk.variant.variantcontext.VariantContext; | ||
import org.apache.hadoop.io.LongWritable; | ||
import org.broadinstitute.hellbender.utils.variant.Variant; | ||
import org.broadinstitute.hellbender.utils.variant.VariantContextVariantAdapter; | ||
import org.seqdoop.hadoop_bam.VCFInputFormat; | ||
import org.seqdoop.hadoop_bam.VariantContextWritable; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* Loads variants into PCollections using a Hadoop filesystem. | ||
*/ | ||
public final class VariantsHadoopSource implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Reads variants from the specified files. | ||
* @param commaSeparatedPaths one or more Hadoop filesystem paths, separated by commas | ||
* @param pipeline the pipeline | ||
* @return a PCollection of variants found in the file. | ||
*/ | ||
public static PCollection<Variant> getAllVariants(String commaSeparatedPaths, Pipeline pipeline) { | ||
PCollection<KV<LongWritable, VariantContextWritable>> input = pipeline.apply( | ||
HadoopIO.Read.from(commaSeparatedPaths, VCFInputFormat.class, LongWritable.class, VariantContextWritable.class)); | ||
input.setCoder(KvCoder.of(WritableCoder.of(LongWritable.class), WritableCoder.of(VariantContextWritable.class))); | ||
return input.apply(ParDo.of(new ConvertToVariant())); | ||
} | ||
|
||
/** | ||
* Reads variants from the specified files. | ||
* @param paths one or more Hadoop filesystem paths | ||
* @param pipeline the pipeline | ||
* @return a PCollection of variants found in the file. | ||
*/ | ||
public static PCollection<Variant> getAllVariants(List<String> paths, Pipeline pipeline) { | ||
return getAllVariants(Joiner.on(",").join(paths), pipeline); | ||
} | ||
|
||
static class ConvertToVariant extends DoFn<KV<LongWritable, VariantContextWritable>, Variant> { | ||
private static final long serialVersionUID = 1L; | ||
@Override | ||
public void processElement(ProcessContext c) throws Exception { | ||
VariantContext variantContext = c.element().getValue().get(); | ||
c.output(new VariantContextVariantAdapter(variantContext)); | ||
} | ||
} | ||
} |
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