Skip to content

Commit

Permalink
Fix for charite#519 - add support for HGVS repeats
Browse files Browse the repository at this point in the history
  • Loading branch information
markwoon committed Jun 18, 2021
1 parent d783373 commit e30060f
Show file tree
Hide file tree
Showing 12 changed files with 751 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ nt_change_inner
| nt_change_insertion
| nt_change_inversion
| nt_change_substitution
| nt_change_sequenced_repeat
| nt_change_not_sequenced_repeat
| nt_change_ssr
| nt_change_unchanged
| nt_change_misc
Expand Down Expand Up @@ -472,6 +474,40 @@ nt_change_ssr
) NT_PAREN_OPEN NT_NUMBER NT_UNDERSCORE NT_NUMBER NT_PAREN_CLOSE
;

/** DNA repeat (sequenced) */
nt_change_sequenced_repeat
:
(
nt_point_location
| nt_range
) nt_change_repeat_sequence*
;

nt_change_repeat_sequence
:
NT_STRING NT_SQUARE_PAREN_OPEN NT_NUMBER NT_SQUARE_PAREN_CLOSE
;

/** DNA repeat (not sequenced) */
nt_change_not_sequenced_repeat
:
(
nt_point_location
| nt_range
)
(
NT_INS
| NT_DEL
)
NT_PAREN_OPEN
(
NT_NUMBER
| NT_NUMBER NT_UNDERSCORE NT_NUMBER
)
NT_PAREN_CLOSE
;


/** nucleotide substitution */
nt_change_substitution
:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package de.charite.compbio.jannovar.hgvs.nts.change;

import java.util.Objects;
import de.charite.compbio.jannovar.hgvs.AminoAcidCode;
import de.charite.compbio.jannovar.hgvs.nts.NucleotideRange;


/**
* A repeat that is not completely sequenced (i.e. unknown bases).
*
* @author Mark Woon
*/
public class NucleotideNotSequencedRepeat extends NucleotideChange {
public enum InDelType { INS, DEL}
private final NucleotideRange range;
private final InDelType type;
/**
* The lower bound on the length of the repeat, inclusive.
*/
private final int minCount;
/**
* The upper bound on the length of the repeat, inclusive.
*/
private final int maxCount;


public NucleotideNotSequencedRepeat(boolean onlyPredicted, NucleotideRange range, InDelType type,
int minCount, int maxCount) {
super(onlyPredicted);
this.range = range;
this.type = type;
this.minCount = minCount;
this.maxCount = maxCount;
}


/**
* @return range of repeat
*/
public NucleotideRange getRange() {
return range;
}

public boolean isInsertion() {
return type == InDelType.INS;
}

public boolean isDeletion() {
return type == InDelType.DEL;
}

/**
* Gets the lower bound on the length of the repeat, inclusive.
*/
public int getMinCount() {
return minCount;
}

/**
* Gets the upper bound on the length of the repeat, inclusive.
*/
public int getMaxCount() {
return maxCount;
}


@Override
public NucleotideChange withOnlyPredicted(boolean flag) {
return new NucleotideNotSequencedRepeat(flag, range, type, minCount, maxCount);
}


@Override
public String toHGVSString() {
StringBuilder builder = new StringBuilder(range.toHGVSString())
.append(type.name().toLowerCase())
.append("(")
.append(minCount);
if (minCount != maxCount) {
builder.append("_")
.append(maxCount);
}
builder.append(")");
return wrapIfOnlyPredicted(builder.toString());
}

@Override
public String toHGVSString(AminoAcidCode code) {
return toHGVSString();
}

@Override
public String toString() {
return "NucleotideNotSequencedRepeat [range=" + range + "type=" + type.name() + ", minCount=" +
minCount + ", maxCount=" + maxCount + "]";
}

@Override
public int hashCode() {
return Objects.hash(range, type, minCount, maxCount);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final NucleotideNotSequencedRepeat other = (NucleotideNotSequencedRepeat)obj;
return Objects.equals(range, other.range) &&
Objects.equals(type, other.type) &&
Objects.equals(minCount, other.getMinCount()) &&
Objects.equals(maxCount, other.getMaxCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.charite.compbio.jannovar.hgvs.nts.change;

import java.util.Objects;
import de.charite.compbio.jannovar.hgvs.AminoAcidCode;
import de.charite.compbio.jannovar.hgvs.ConvertibleToHGVSString;


/**
* A repeated sequence.
*
* @author Mark Woon
*/
public class NucleotideRepeatSequence implements ConvertibleToHGVSString {
final String sequence;
final int copyNumber;


public NucleotideRepeatSequence(String sequence, int copyNumber) {
this.sequence = sequence;
this.copyNumber = copyNumber;
}


public String getSequence() {
return sequence;
}

public int getCopyNumber() {
return copyNumber;
}


@Override
public String toHGVSString() {
return sequence + "[" + copyNumber + "]";
}

@Override
public String toHGVSString(AminoAcidCode code) {
return toHGVSString();
}

@Override
public String toString() {
return "NucleotideRepeatSequence [sequence=" + sequence + ", copyNumber=" + copyNumber + "]";
}

@Override
public int hashCode() {
return Objects.hash(sequence, copyNumber);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final NucleotideRepeatSequence other = (NucleotideRepeatSequence)obj;
return Objects.equals(sequence, other.sequence) &&
Objects.equals(copyNumber, other.copyNumber);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package de.charite.compbio.jannovar.hgvs.nts.change;

import java.util.List;
import java.util.Objects;
import com.google.common.base.Joiner;
import de.charite.compbio.jannovar.hgvs.nts.NucleotideRange;


/**
* A repeat that has been sequenced.
*
* @author Mark Woon
*/
public class NucleotideSequencedRepeat extends NucleotideChange {
private final NucleotideRange range;
public List<NucleotideRepeatSequence> sequencedRepeats;
public NucleotideNotSequencedRepeat notSequencedRepeat;


public NucleotideSequencedRepeat(boolean onlyPredicted, NucleotideRange range,
List<NucleotideRepeatSequence> sequencedRepeats) {
super(onlyPredicted);
this.range = range;
this.sequencedRepeats = sequencedRepeats;
}


/**
* @return range of repeat
*/
public NucleotideRange getRange() {
return range;
}

/**
* Gets the sequenced repeats. Null if this repeat is not sequenced.
*/
public List<NucleotideRepeatSequence> getSequencedRepeats() {
return sequencedRepeats;
}

/**
* Gets the repeat if it was not sequenced. Null if this repeat is sequenced.
*/
public NucleotideNotSequencedRepeat getNotSequencedRepeat() {
return notSequencedRepeat;
}


@Override
public NucleotideChange withOnlyPredicted(boolean flag) {
return new NucleotideSequencedRepeat(flag, range, sequencedRepeats);
}


@Override
public String toHGVSString() {
StringBuilder builder = new StringBuilder(range.toHGVSString());
sequencedRepeats.stream()
.map(NucleotideRepeatSequence::toHGVSString)
.forEach(builder::append);
return wrapIfOnlyPredicted(builder.toString());
}

@Override
public String toString() {
return "NucleotideRepeat [range=" + range + ", sequences=(" +
Joiner.on(", ").join(sequencedRepeats) + ")]";
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), range, sequencedRepeats);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final NucleotideSequencedRepeat other = (NucleotideSequencedRepeat)obj;
return super.equals(obj) &&
Objects.equals(range, other.range) &&
Objects.equals(sequencedRepeats, other.sequencedRepeats);
}
}
Loading

0 comments on commit e30060f

Please sign in to comment.