Skip to content
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

Now correctly populates transcript position. #5380

Merged
merged 2 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class GencodeFuncotation implements Funcotation {
private String annotationTranscript; // TRIVIAL
private String transcriptStrand; // TRIVIAL
private Integer transcriptExon; // CDS / UTRs
private Integer transcriptPos; // TRIVIAL
private Integer transcriptStartPos; // TRIVIAL
private Integer transcriptEndPos; // TRIVIAL
private String cDnaChange; // CDS
private String codonChange; // CDS
private String proteinChange; // CDS
Expand Down Expand Up @@ -131,7 +132,8 @@ public class GencodeFuncotation implements Funcotation {
this.annotationTranscript = that.annotationTranscript;
this.transcriptStrand = that.transcriptStrand;
this.transcriptExon = that.transcriptExon;
this.transcriptPos = that.transcriptPos;
this.transcriptStartPos = that.transcriptStartPos;
this.transcriptEndPos = that.transcriptEndPos;
this.cDnaChange = that.cDnaChange;
this.codonChange = that.codonChange;
this.proteinChange = that.proteinChange;
Expand Down Expand Up @@ -294,7 +296,7 @@ public String getField(final String fieldName) {
case "transcriptExon":
return (transcriptExonSerializedOverride != null ? transcriptExonSerializedOverride : (transcriptExon != null ? String.valueOf(transcriptExon) : ""));
case "transcriptPos":
return (transcriptPosSerializedOverride != null ? transcriptPosSerializedOverride : (transcriptPos != null ? String.valueOf(transcriptPos) : ""));
return (transcriptPosSerializedOverride != null ? transcriptPosSerializedOverride : getTranscriptPosString());
case "cDnaChange":
return (cDnaChangeSerializedOverride != null ? cDnaChangeSerializedOverride : (cDnaChange != null ? cDnaChange : ""));
case "codonChange":
Expand Down Expand Up @@ -353,7 +355,9 @@ public boolean equals(final Object o) {
return false;
if (transcriptExon != null ? !transcriptExon.equals(that.transcriptExon) : that.transcriptExon != null)
return false;
if (transcriptPos != null ? !transcriptPos.equals(that.transcriptPos) : that.transcriptPos != null)
if (transcriptStartPos != null ? !transcriptStartPos.equals(that.transcriptStartPos) : that.transcriptStartPos != null)
return false;
if (transcriptEndPos != null ? !transcriptEndPos.equals(that.transcriptEndPos) : that.transcriptEndPos != null)
return false;
if (cDnaChange != null ? !cDnaChange.equals(that.cDnaChange) : that.cDnaChange != null) return false;
if (codonChange != null ? !codonChange.equals(that.codonChange) : that.codonChange != null) return false;
Expand Down Expand Up @@ -435,7 +439,8 @@ public int hashCode() {
result = 31 * result + (annotationTranscript != null ? annotationTranscript.hashCode() : 0);
result = 31 * result + (transcriptStrand != null ? transcriptStrand.hashCode() : 0);
result = 31 * result + (transcriptExon != null ? transcriptExon.hashCode() : 0);
result = 31 * result + (transcriptPos != null ? transcriptPos.hashCode() : 0);
result = 31 * result + (transcriptStartPos != null ? transcriptStartPos.hashCode() : 0);
result = 31 * result + (transcriptEndPos != null ? transcriptEndPos.hashCode() : 0);
result = 31 * result + (cDnaChange != null ? cDnaChange.hashCode() : 0);
result = 31 * result + (codonChange != null ? codonChange.hashCode() : 0);
result = 31 * result + (proteinChange != null ? proteinChange.hashCode() : 0);
Expand Down Expand Up @@ -474,61 +479,6 @@ public int hashCode() {
return result;
}

@Override
public String toString() {
return "GencodeFuncotation{" +
"hugoSymbol='" + hugoSymbol + '\'' +
", ncbiBuild='" + ncbiBuild + '\'' +
", chromosome='" + chromosome + '\'' +
", start=" + start +
", end=" + end +
", variantClassification=" + variantClassification +
", secondaryVariantClassification=" + secondaryVariantClassification +
", variantType=" + variantType +
", refAllele='" + refAllele + '\'' +
", tumorSeqAllele2='" + tumorSeqAllele2 + '\'' +
", genomeChange='" + genomeChange + '\'' +
", annotationTranscript='" + annotationTranscript + '\'' +
", transcriptStrand='" + transcriptStrand + '\'' +
", transcriptExon=" + transcriptExon +
", transcriptPos=" + transcriptPos +
", cDnaChange='" + cDnaChange + '\'' +
", codonChange='" + codonChange + '\'' +
", proteinChange='" + proteinChange + '\'' +
", gcContent=" + gcContent +
", referenceContext='" + referenceContext + '\'' +
", otherTranscripts=" + otherTranscripts +
", dataSourceName=" + dataSourceName +
", locusLevel=" + locusLevel +
", apprisRank=" + apprisRank +
", transcriptLength=" + transcriptLength +
", version='" + version + '\'' +
", geneTranscriptType=" + geneTranscriptType +
", hugoSymbolSerializedOverride='" + hugoSymbolSerializedOverride + '\'' +
", ncbiBuildSerializedOverride='" + ncbiBuildSerializedOverride + '\'' +
", chromosomeSerializedOverride='" + chromosomeSerializedOverride + '\'' +
", startSerializedOverride='" + startSerializedOverride + '\'' +
", endSerializedOverride='" + endSerializedOverride + '\'' +
", variantClassificationSerializedOverride='" + variantClassificationSerializedOverride + '\'' +
", secondaryVariantClassificationSerializedOverride='" + secondaryVariantClassificationSerializedOverride + '\'' +
", variantTypeSerializedOverride='" + variantTypeSerializedOverride + '\'' +
", refAlleleSerializedOverride='" + refAlleleSerializedOverride + '\'' +
", tumorSeqAllele1SerializedOverride='" + tumorSeqAllele1SerializedOverride + '\'' +
", tumorSeqAllele2SerializedOverride='" + tumorSeqAllele2SerializedOverride + '\'' +
", genomeChangeSerializedOverride='" + genomeChangeSerializedOverride + '\'' +
", annotationTranscriptSerializedOverride='" + annotationTranscriptSerializedOverride + '\'' +
", transcriptStrandSerializedOverride='" + transcriptStrandSerializedOverride + '\'' +
", transcriptExonSerializedOverride='" + transcriptExonSerializedOverride + '\'' +
", transcriptPosSerializedOverride='" + transcriptPosSerializedOverride + '\'' +
", cDnaChangeSerializedOverride='" + cDnaChangeSerializedOverride + '\'' +
", codonChangeSerializedOverride='" + codonChangeSerializedOverride + '\'' +
", proteinChangeSerializedOverride='" + proteinChangeSerializedOverride + '\'' +
", gcContentSerializedOverride='" + gcContentSerializedOverride + '\'' +
", referenceContextSerializedOverride='" + referenceContextSerializedOverride + '\'' +
", otherTranscriptsSerializedOverride='" + otherTranscriptsSerializedOverride + '\'' +
'}';
}

//==================================================================================================================

public String getHugoSymbol() {
Expand Down Expand Up @@ -643,12 +593,20 @@ public void setTranscriptExonNumber(final Integer transcriptExonNumber) {
this.transcriptExon = transcriptExonNumber;
}

public Integer getTranscriptPos() {
return transcriptPos;
public Integer getTranscriptStartPos() {
return transcriptStartPos;
}

public void setTranscriptStartPos(final Integer transcriptStartPos) {
this.transcriptStartPos = transcriptStartPos;
}

public Integer getTranscriptEndPos() {
return transcriptEndPos;
}

public void setTranscriptPos(final Integer transcriptPos) {
this.transcriptPos = transcriptPos;
public void setTranscriptEndPos(final Integer transcriptEndPos) {
this.transcriptEndPos = transcriptEndPos;
}

public String getcDnaChange() {
Expand Down Expand Up @@ -748,35 +706,19 @@ public void setDataSourceName(final String dataSourceName) {
public void setMetadata(final FuncotationMetadata metadata) {
this.metadata = metadata;
}
//==================================================================================================================

/**
* The names of the fields in this GencodeFuncotation.
* Used to access the field map.
*/
private enum FieldName {
hugoSymbol,
ncbiBuild,
chromosome,
start,
end,
variantClassification,
secondaryVariantClassification,
variantType,
refAllele,
tumorSeqAllele1,
tumorSeqAllele2,
genomeChange,
annotationTranscript,
transcriptStrand,
transcriptExon,
transcriptPos,
cDnaChange,
codonChange,
proteinChange,
gcContent,
referenceContext,
otherTranscripts;
//==================================================================================================================

private String getTranscriptPosString() {
if ( transcriptStartPos == null ) {
return "";
}

if ( transcriptStartPos.equals(transcriptEndPos) ) {
return String.valueOf(transcriptStartPos);
}

return transcriptStartPos + "_" + transcriptEndPos;
}

//==================================================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,22 @@ public GencodeFuncotationBuilder setAnnotationTranscript(final String transcript
}

/**
* Set the position (1-based, inclusive) relative to the start of the transcript of a the variant in the {@link GencodeFuncotation}.
* @param transcriptPos The position (1-based, inclusive) relative to the start of the transcript of a the variant in the {@link GencodeFuncotation}.
* Set the start position (1-based, inclusive) relative to the start of the transcript of a the variant in the {@link GencodeFuncotation}.
* @param transcriptStartPos The start position (1-based, inclusive) of the variant in the {@link GencodeFuncotation} relative to the start of the transcript.
* @return {@code this} {@link GencodeFuncotationBuilder}
*/
public GencodeFuncotationBuilder setTranscriptPos(final Integer transcriptPos) {
gencodeFuncotation.setTranscriptPos(transcriptPos);
public GencodeFuncotationBuilder setTranscriptStartPos(final Integer transcriptStartPos) {
gencodeFuncotation.setTranscriptStartPos(transcriptStartPos);
return this;
}

/**
* Set the end position (1-based, inclusive) relative to the start of the transcript of a the variant in the {@link GencodeFuncotation}.
* @param transcriptEndPos The end position (1-based, inclusive) of the variant in the {@link GencodeFuncotation} relative to the start of the transcript.
* @return {@code this} {@link GencodeFuncotationBuilder}
*/
public GencodeFuncotationBuilder setTranscriptEndPos(final Integer transcriptEndPos) {
gencodeFuncotation.setTranscriptEndPos(transcriptEndPos);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,21 +795,14 @@ private GencodeFuncotation createCodingRegionFuncotationForNonProteinCodingFeatu
// Setup the "trivial" fields of the gencodeFuncotation:
final GencodeFuncotationBuilder gencodeFuncotationBuilder = createGencodeFuncotationBuilderWithTrivialFieldsPopulated(variant, altAllele, gtfFeature, transcript);

// Set the transcript start position:
gencodeFuncotationBuilder.setTranscriptPos(
FuncotatorUtils.getTranscriptAlleleStartPosition(variant, transcript.getExons(), transcript.getGenomicStrand())
);

// Set the exon number:
gencodeFuncotationBuilder.setTranscriptExonNumber(exon.getExonNumber());

// Set our version:
gencodeFuncotationBuilder.setVersion(version);

// Set our transcript position to be the start point in the transcript of the variant:
gencodeFuncotationBuilder.setTranscriptPos(
FuncotatorUtils.getTranscriptAlleleStartPosition(variant, transcript.getExons(), exon.getGenomicStrand())
);
// Set our transcript positions:
setTranscriptPosition(variant, altAllele, transcript, gencodeFuncotationBuilder);

// Get the reference bases for our current variant:
final StrandCorrectedReferenceBases referenceBases = FuncotatorUtils.createReferenceSnippet(variant.getReference(), altAllele, reference, exon.getGenomicStrand(), referenceWindow);
Expand Down Expand Up @@ -853,6 +846,48 @@ private GencodeFuncotation createCodingRegionFuncotationForNonProteinCodingFeatu
return gencodeFuncotationBuilder.build();
}

/**
* Set the transcript start and end position in the given {@link GencodeFuncotationBuilder}.
* @param variant The {@link VariantContext} for which to set the position.
* @param altAllele The alternate {@link Allele} for which to set the position.
* @param transcript The {@link GencodeGtfTranscriptFeature} in which the {@code variant} occurs.
* @param gencodeFuncotationBuilder The {@link GencodeFuncotationBuilder} in which to set the transcript start and end positions.
*/
private void setTranscriptPosition(final VariantContext variant, final Allele altAllele, final GencodeGtfTranscriptFeature transcript, final GencodeFuncotationBuilder gencodeFuncotationBuilder) {
final int txStart = FuncotatorUtils.getTranscriptAlleleStartPosition(variant, transcript.getExons(), transcript.getGenomicStrand());
setTranscriptPosition(variant, altAllele, txStart, gencodeFuncotationBuilder);
}

/**
* Set the transcript start and end position in the given {@link GencodeFuncotationBuilder}.
* @param variant The {@link VariantContext} for which to set the position.
* @param altAllele The alternate {@link Allele} for which to set the position.
* @param txStart The start position of the {@code variant} in the transcript.
* @param gencodeFuncotationBuilder The {@link GencodeFuncotationBuilder} in which to set the transcript start and end positions.
*/
private void setTranscriptPosition(final VariantContext variant, final Allele altAllele, final int txStart, final GencodeFuncotationBuilder gencodeFuncotationBuilder) {

// Set the transcript start position:
gencodeFuncotationBuilder.setTranscriptStartPos(txStart);

// For SNPs, start == end:
if ( variant.getReference().length() == 1 ) {
gencodeFuncotationBuilder.setTranscriptEndPos( txStart );
}
else {
// For indels, we have to adjust by the leading placeholder base.
// For MNPs we can use the raw length.
int indelOffset = 0;
if ( GATKVariantContextUtils.isIndel(variant.getReference(), altAllele) ) {
// Account for the leading base in the variant:
indelOffset = 1;
}
// Subtract 1 here for the inclusive nature of the positions.
// NOTE: this is in addition to the indel offset.
gencodeFuncotationBuilder.setTranscriptEndPos(txStart + variant.getReference().length() - indelOffset -1);
}
}

/**
* Create a {@link GencodeFuncotation} for a {@code variant} that occurs in a coding region in a given {@code exon}.
* @param variant The {@link VariantContext} for which to create a {@link GencodeFuncotation}.
Expand Down Expand Up @@ -882,11 +917,6 @@ private GencodeFuncotation createCodingRegionFuncotationForProteinCodingFeature(
// Setup the "trivial" fields of the gencodeFuncotation:
final GencodeFuncotationBuilder gencodeFuncotationBuilder = createGencodeFuncotationBuilderWithTrivialFieldsPopulated(variant, altAllele, gtfFeature, transcript);

// Set the transcript start position:
gencodeFuncotationBuilder.setTranscriptPos(
FuncotatorUtils.getTranscriptAlleleStartPosition(variant, transcript.getExons(), transcript.getGenomicStrand())
);

// Set the exon number:
gencodeFuncotationBuilder.setTranscriptExonNumber(exon.getExonNumber());

Expand All @@ -897,10 +927,8 @@ private GencodeFuncotation createCodingRegionFuncotationForProteinCodingFeature(
// These fields can all be set without knowing the alternate allele:
final SequenceComparison sequenceComparison = createSequenceComparison(variant, altAllele, reference, transcript, exonPositionList, transcriptIdMap, transcriptFastaReferenceDataSource, true);

// Set our transcript position to be the start point in the transcript of the variant:
gencodeFuncotationBuilder.setTranscriptPos(
sequenceComparison.getTranscriptAlleleStart()
);
// Set our transcript positions:
setTranscriptPosition(variant, altAllele, sequenceComparison.getTranscriptAlleleStart(), gencodeFuncotationBuilder);

// Set the reference context with the bases from the sequence comparison
// NOTE: The reference context is ALWAYS from the + strand, so we need to reverse our bases back in the - case:
Expand Down
Loading