-
Notifications
You must be signed in to change notification settings - Fork 311
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
Remove StructuralVariant and StructuralVariantType, add names field to Variant #1131
Closed
heuermh
wants to merge
3
commits into
bigdatagenomics:upgrade-to-bdg-formats-0.10.0
from
heuermh:formats-issue-102
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ | |
*/ | ||
package org.bdgenomics.adam.converters | ||
|
||
import com.google.common.collect.ImmutableList | ||
import htsjdk.variant.variantcontext.{ | ||
Allele, | ||
GenotypesContext, | ||
GenotypeLikelihoods, | ||
VariantContext => HtsjdkVariantContext, | ||
VariantContextBuilder | ||
} | ||
import htsjdk.variant.vcf.VCFConstants | ||
import java.util.Collections | ||
import org.bdgenomics.utils.misc.Logging | ||
import org.bdgenomics.adam.models.{ | ||
|
@@ -72,10 +74,10 @@ private[adam] object VariantContextConverter { | |
* @return The Avro representation for this allele. | ||
*/ | ||
private def convertAllele(vc: HtsjdkVariantContext, allele: Allele): GenotypeAllele = { | ||
if (allele.isNoCall) GenotypeAllele.NoCall | ||
else if (allele.isReference) GenotypeAllele.Ref | ||
else if (allele == NON_REF_ALLELE || !vc.hasAlternateAllele(allele)) GenotypeAllele.OtherAlt | ||
else GenotypeAllele.Alt | ||
if (allele.isNoCall) GenotypeAllele.NO_CALL | ||
else if (allele.isReference) GenotypeAllele.REF | ||
else if (allele == NON_REF_ALLELE || !vc.hasAlternateAllele(allele)) GenotypeAllele.OTHER_ALT | ||
else GenotypeAllele.ALT | ||
} | ||
|
||
/** | ||
|
@@ -123,9 +125,9 @@ private[adam] object VariantContextConverter { | |
var alleles = g.getAlleles | ||
if (alleles == null) return Collections.emptyList[Allele] | ||
else g.getAlleles.map { | ||
case GenotypeAllele.NoCall => Allele.NO_CALL | ||
case GenotypeAllele.Ref | GenotypeAllele.OtherAlt => Allele.create(g.getVariant.getReferenceAllele, true) | ||
case GenotypeAllele.Alt => Allele.create(g.getVariant.getAlternateAllele) | ||
case GenotypeAllele.NO_CALL => Allele.NO_CALL | ||
case GenotypeAllele.REF | GenotypeAllele.OTHER_ALT => Allele.create(g.getVariant.getReferenceAllele, true) | ||
case GenotypeAllele.ALT => Allele.create(g.getVariant.getAlternateAllele) | ||
} | ||
} | ||
} | ||
|
@@ -312,6 +314,36 @@ private[adam] class VariantContextConverter(dict: Option[SequenceDictionary] = N | |
contigToRefSeq.getOrElse(vc.getChr, vc.getChr) | ||
} | ||
|
||
/** | ||
* Split the htsjdk variant context ID field into an array of names. | ||
* | ||
* @param vc htsjdk variant context | ||
* @return Returns an Option wrapping an array of names split from the htsjdk | ||
* variant context ID field | ||
*/ | ||
private def splitIds(vc: HtsjdkVariantContext): Option[java.util.List[String]] = { | ||
if (vc.hasID()) { | ||
Some(ImmutableList.copyOf(vc.getID().split(VCFConstants.ID_FIELD_SEPARATOR))) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/** | ||
* Join the array of variant names into a string for the htsjdk variant context ID field. | ||
* | ||
* @param variant variant | ||
* @return Returns an Option wrapping a string for the htsjdk variant context ID field joined | ||
* from the array of variant names | ||
*/ | ||
private def joinNames(variant: Variant): Option[String] = { | ||
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. Ditto for this function RE: unit tests. |
||
if (variant.getNames != null && variant.getNames.length > 0) { | ||
Some(variant.getNames.mkString(VCFConstants.ID_FIELD_SEPARATOR)) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/** | ||
* Builds an avro Variant for a site with a defined alt allele. | ||
* | ||
|
@@ -321,16 +353,14 @@ private[adam] class VariantContextConverter(dict: Option[SequenceDictionary] = N | |
* @return Returns an Avro description of the genotyped site. | ||
*/ | ||
private def createADAMVariant(vc: HtsjdkVariantContext, alt: Option[String]): Variant = { | ||
// VCF CHROM, POS, REF and ALT | ||
// VCF CHROM, POS, ID, REF and ALT | ||
val builder = Variant.newBuilder | ||
.setContigName(createContig(vc)) | ||
.setStart(vc.getStart - 1 /* ADAM is 0-indexed */ ) | ||
.setEnd(vc.getEnd /* ADAM is 0-indexed, so the 1-indexed inclusive end becomes exclusive */ ) | ||
.setReferenceAllele(vc.getReference.getBaseString) | ||
if (vc.hasLog10PError) { | ||
builder.setVariantErrorProbability(vc.getPhredScaledQual.intValue()) | ||
} | ||
alt.foreach(builder.setAlternateAllele(_)) | ||
splitIds(vc).foreach(builder.setNames(_)) | ||
builder.build | ||
} | ||
|
||
|
@@ -392,7 +422,7 @@ private[adam] class VariantContextConverter(dict: Option[SequenceDictionary] = N | |
.setVariantCallingAnnotations(annotations) | ||
.setSampleId(g.getSampleName) | ||
.setAlleles(g.getAlleles.map(VariantContextConverter.convertAllele(vc, _))) | ||
.setIsPhased(g.isPhased) | ||
.setPhased(g.isPhased) | ||
|
||
if (g.hasGQ) genotype.setGenotypeQuality(g.getGQ) | ||
if (g.hasDP) genotype.setReadDepth(g.getDP) | ||
|
@@ -538,7 +568,10 @@ private[adam] class VariantContextConverter(dict: Option[SequenceDictionary] = N | |
.stop(variant.getStart + variant.getReferenceAllele.length) | ||
.alleles(VariantContextConverter.convertAlleles(variant)) | ||
|
||
vc.databases.flatMap(d => Option(d.getDbSnpId)).foreach(d => vcb.id("rs" + d)) | ||
joinNames(variant) match { | ||
case None => vcb.noID() | ||
case Some(s) => vcb.id(s) | ||
} | ||
|
||
// TODO: Extract provenance INFO fields | ||
try { | ||
|
@@ -547,7 +580,7 @@ private[adam] class VariantContextConverter(dict: Option[SequenceDictionary] = N | |
g.getSampleId, VariantContextConverter.convertAlleles(g) | ||
) | ||
|
||
Option(g.getIsPhased).foreach(gb.phased(_)) | ||
Option(g.getPhased).foreach(gb.phased(_)) | ||
Option(g.getGenotypeQuality).foreach(gb.GQ(_)) | ||
Option(g.getReadDepth).foreach(gb.DP(_)) | ||
|
||
|
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you write some unit tests for this? Ideally, we'd have tests for just this function with a VC with no ID, one ID, more than one ID, and an end-to-end VCF-with-IDs test.
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.
As in me Justin? I'd be happy to work on the unit tests - would be good for me. But if @heuermh wants to as his PR he can have first dibs. Just let me know what you prefer Michael - and if you want me to do it, should it be a separate PR or do you want me to PR against your PR Michael?
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.
Oh, sorry for the confusion! My comment was directed at @heuermh, unless he'd like you to work on it, of course!
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.
No worries, I got it!