-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to RDD utility files for new variant schema #114
Changes from 3 commits
2375b74
137253e
6abf6b1
7e0ed42
3d3d66e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2013. Mount Sinai School of Medicine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be updated to 2014 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package edu.berkeley.cs.amplab.adam.rdd.variation | ||
|
||
import org.apache.spark.rdd.RDD | ||
import edu.berkeley.cs.amplab.adam.models.ADAMVariantContext | ||
import org.apache.spark.{Logging, SparkContext} | ||
import org.apache.hadoop.mapreduce.Job | ||
import edu.berkeley.cs.amplab.adam.converters.VariantContextConverter | ||
import fi.tkk.ics.hadoop.bam.{VariantContextWritable, VCFInputFormat} | ||
import org.apache.hadoop.io.LongWritable | ||
import parquet.hadoop.util.ContextUtil | ||
|
||
|
||
object ADAMVariationContext { | ||
implicit def sparkContextToADAMVariationContext(sc: SparkContext): ADAMVariationContext = new ADAMVariationContext(sc) | ||
|
||
implicit def rddToADAMVariantContextRDD(rdd: RDD[ADAMVariantContext]) = new ADAMVariantContextRDDFunctions(rdd) | ||
} | ||
|
||
class ADAMVariationContext(sc: SparkContext) extends Serializable with Logging { | ||
|
||
/** | ||
* This method will create a new RDD of VariantContext objects | ||
* @param filePath: input VCF file to read | ||
* @return RDD of variants | ||
*/ | ||
def adamVCFLoad(filePath: String): RDD[ADAMVariantContext] = { | ||
log.info("Reading VCF file from %s".format(filePath)) | ||
val job = Job.getInstance(sc.hadoopConfiguration) | ||
val vcc = new VariantContextConverter | ||
val records = sc.newAPIHadoopFile( | ||
filePath, | ||
classOf[VCFInputFormat], classOf[LongWritable], classOf[VariantContextWritable], | ||
ContextUtil.getConfiguration(job) | ||
) | ||
log.info("Converted %d records".format(records.count())) | ||
records.flatMap(p => vcc.convert(p._2.get)) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2013. Mount Sinai School of Medicine | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package edu.berkeley.cs.amplab.adam.rdd.variation | ||
|
||
import org.apache.spark.Logging | ||
import org.apache.spark.rdd.RDD | ||
import edu.berkeley.cs.amplab.adam.models.ADAMVariantContext | ||
import edu.berkeley.cs.amplab.adam.avro.{ADAMGenotype, ADAMDatabaseVariantAnnotation} | ||
import org.apache.spark.SparkContext._ | ||
import edu.berkeley.cs.amplab.adam.rich.RichADAMVariant | ||
|
||
class ADAMVariantContextRDDFunctions(rdd: RDD[ADAMVariantContext]) extends Serializable with Logging { | ||
initLogging() | ||
|
||
/** | ||
* Left outer join database variant annotations | ||
* | ||
*/ | ||
def joinDatabaseVariantAnnotation(ann: RDD[ADAMDatabaseVariantAnnotation]): RDD[ADAMVariantContext] = { | ||
rdd.keyBy(_.variant) | ||
.leftOuterJoin(ann.keyBy(_.getVariant)) | ||
.values | ||
.map { case (v:ADAMVariantContext, a) => new ADAMVariantContext(v.variant, v.genotypes, databases = a) } | ||
} | ||
} | ||
|
||
class ADAMGenotypeRDDFunctions(rdd: RDD[ADAMGenotype]) extends Serializable with Logging { | ||
initLogging() | ||
|
||
def toADAMVariantContext(): RDD[ADAMVariantContext] = { | ||
rdd.keyBy({ g => RichADAMVariant.variantToRichVariant(g.getVariant) }) | ||
.groupByKey | ||
.map { case (v:RichADAMVariant, g) => new ADAMVariantContext(v, genotypes = g) } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2014. Mount Sinai School of Medicine | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package edu.berkeley.cs.amplab.adam.rich | ||
|
||
import edu.berkeley.cs.amplab.adam.avro.{ADAMContig, ADAMVariant} | ||
import java.util.Arrays | ||
|
||
object RichADAMVariant { | ||
implicit def variantToRichVariant(variant: ADAMVariant): RichADAMVariant = new RichADAMVariant(variant) | ||
implicit def richVariantToVariant(variant: RichADAMVariant): ADAMVariant = variant.variant | ||
} | ||
|
||
class RichADAMVariant(val variant: ADAMVariant) { | ||
// Only include the contigName in the hash | ||
val hashObjects = Array[Object](variant.getContig.getContigName, | ||
variant.getPosition, variant.getReferenceAllele, variant.getVariantAllele) | ||
override def hashCode = Arrays.hashCode(hashObjects) | ||
|
||
private def isSameContig(left: ADAMContig, right: ADAMContig): Boolean = { | ||
left.getContigName == right.getContigName && ( | ||
left.getReferenceMD5 == null || right.getReferenceMD5 == null || left.getReferenceMD5 == right.getReferenceMD5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be contigMD5? Or is there a change to the AVDL that's missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
) | ||
} | ||
|
||
override def equals(o: Any) = o match { | ||
case that: RichADAMVariant => { | ||
variant.getPosition == that.variant.getPosition && | ||
isSameContig(variant.getContig, that.variant.getContig) && | ||
variant.getReferenceAllele == that.variant.getReferenceAllele && | ||
variant.getVariantAllele == that.variant.getVariantAllele | ||
} | ||
case _ => false | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ class ParquetFileTraversable[T <: IndexedRecord](sc: SparkContext, file: Path) e | |
} | ||
val status = fs.getFileStatus(file) | ||
var paths = List[Path]() | ||
if (status.isDir) { | ||
if (status.isDirectory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just as a heads up, this is not reverse compatible with Hadoop 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be discussed in some detail. At the least, this change should also add some text into the POM saying that only 2.2 is supported (or equivalent). For us here, this won't affect us. However, I feel like we could get by with waiting until 0.7.0 for this change, or possibly even a 0.6.2 release. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It won't affect us here at Sinai, either. Do we have anyone using Hadoop 1.x? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd vote for removing the comment about pre-2.2 from the POM instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been running Hadoop 1.0.4. I'll see if we can move to Hadoop 2 for all our work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, we're fine with Hadoop 2. Let's just make the move then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait. Why would be break Hadoop 1 compatibility if we can easily avoid it? Can we just us "status.isDir" here and then open a discussion with the broader group on the mailing list? If everyone is ok with dropping Hadoop 1.x support, that's fine. We shouldn't decide that here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted this change. |
||
val files = fs.listStatus(file) | ||
files.foreach { | ||
file => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes intended? It looks like they revert to older code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; was that intentional? If not, this is the other cause of the build failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks!