From: gmungoc Date: Fri, 7 Jun 2019 16:09:44 +0000 (+0100) Subject: Merge branch 'feature/JAL-3187linkedFeatures' into feature/JAL-3251biotypedMappings X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ffeature%2FJAL-3251biotypedMappings;hp=524fef20446c13563943f41ca15389cd21ba3c35;p=jalview.git Merge branch 'feature/JAL-3187linkedFeatures' into feature/JAL-3251biotypedMappings --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 4b4e2a7..2220171 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -24,7 +24,6 @@ import static jalview.io.gff.GffConstants.CLINICAL_SIGNIFICANCE; import jalview.datamodel.AlignedCodon; import jalview.datamodel.AlignedCodonFrame; -import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; @@ -36,6 +35,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.datamodel.SequenceMapping; import jalview.datamodel.features.SequenceFeatures; import jalview.io.gff.Gff3Helper; import jalview.io.gff.SequenceOntologyI; @@ -1935,7 +1935,7 @@ public class AlignmentUtils .findMappingsForSequence(proteinProduct, mappings); for (AlignedCodonFrame acf : mappingsToPeptide) { - for (SequenceToSequenceMapping map : acf.getMappings()) + for (SequenceMapping map : acf.getMappings()) { Mapping mapping = map.getMapping(); if (mapping != aMapping diff --git a/src/jalview/datamodel/AlignedCodonFrame.java b/src/jalview/datamodel/AlignedCodonFrame.java index 26f6e2a..7845ddc 100644 --- a/src/jalview/datamodel/AlignedCodonFrame.java +++ b/src/jalview/datamodel/AlignedCodonFrame.java @@ -34,82 +34,7 @@ import java.util.List; public class AlignedCodonFrame { - /* - * Data bean to hold mappings from one sequence to another - */ - public class SequenceToSequenceMapping - { - private SequenceI fromSeq; - - private Mapping mapping; - - SequenceToSequenceMapping(SequenceI from, Mapping map) - { - this.fromSeq = from; - this.mapping = map; - } - - /** - * Readable representation for debugging only, not guaranteed not to change - */ - @Override - public String toString() - { - return String.format("From %s %s", fromSeq.getName(), - mapping.toString()); - } - - /** - * Returns a hashCode derived from the hashcodes of the mappings and fromSeq - * - * @see SequenceToSequenceMapping#hashCode() - */ - @Override - public int hashCode() - { - return (fromSeq == null ? 0 : fromSeq.hashCode() * 31) - + mapping.hashCode(); - } - - /** - * Answers true if the objects hold the same mapping between the same two - * sequences - * - * @see Mapping#equals - */ - @Override - public boolean equals(Object obj) - { - if (!(obj instanceof SequenceToSequenceMapping)) - { - return false; - } - SequenceToSequenceMapping that = (SequenceToSequenceMapping) obj; - if (this.mapping == null) - { - return that.mapping == null; - } - // TODO: can simplify by asserting fromSeq is a dataset sequence - return (this.fromSeq == that.fromSeq - || (this.fromSeq != null && that.fromSeq != null - && this.fromSeq.getDatasetSequence() != null - && this.fromSeq.getDatasetSequence() == that.fromSeq - .getDatasetSequence())) - && this.mapping.equals(that.mapping); - } - - public SequenceI getFromSeq() - { - return fromSeq; - } - - public Mapping getMapping() - { - return mapping; - } - } - - private List mappings; + private List mappings; /** * Constructor @@ -158,7 +83,7 @@ public class AlignedCodonFrame * note that 'adding' a duplicate map does nothing; this protects against * creating duplicate mappings in AlignedCodonFrame */ - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.fromSeq == fromSeq && ssm.mapping.to == toSeq) { @@ -172,7 +97,7 @@ public class AlignedCodonFrame */ Mapping mp = new Mapping(toSeq, map); mp.setMappedFromId(mapFromId); - mappings.add(new SequenceToSequenceMapping(fromSeq, mp)); + mappings.add(new SequenceMapping(fromSeq, mp)); } public SequenceI[] getdnaSeqs() @@ -180,7 +105,7 @@ public class AlignedCodonFrame // TODO return a list instead? // return dnaSeqs; List seqs = new ArrayList<>(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { seqs.add(ssm.fromSeq); } @@ -191,7 +116,7 @@ public class AlignedCodonFrame { // TODO not used - remove? List seqs = new ArrayList<>(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { seqs.add(ssm.mapping.to); } @@ -201,7 +126,7 @@ public class AlignedCodonFrame public MapList[] getdnaToProt() { List maps = new ArrayList<>(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { maps.add(ssm.mapping.map); } @@ -211,7 +136,7 @@ public class AlignedCodonFrame public Mapping[] getProtMappings() { List maps = new ArrayList<>(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { maps.add(ssm.mapping); } @@ -230,7 +155,7 @@ public class AlignedCodonFrame SequenceI seqDs = seq.getDatasetSequence(); seqDs = seqDs != null ? seqDs : seq; - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.fromSeq == seqDs || ssm.mapping.to == seqDs) { @@ -254,7 +179,7 @@ public class AlignedCodonFrame public SequenceI getAaForDnaSeq(SequenceI dnaSeqRef) { SequenceI dnads = dnaSeqRef.getDatasetSequence(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.fromSeq == dnaSeqRef || ssm.fromSeq == dnads) { @@ -272,7 +197,7 @@ public class AlignedCodonFrame public SequenceI getDnaForAaSeq(SequenceI aaSeqRef) { SequenceI aads = aaSeqRef.getDatasetSequence(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.mapping.to == aaSeqRef || ssm.mapping.to == aads) { @@ -310,7 +235,7 @@ public class AlignedCodonFrame { int[] codon; SequenceI ds = seq.getDatasetSequence(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.fromSeq == seq || ssm.fromSeq == ds) { @@ -361,7 +286,7 @@ public class AlignedCodonFrame */ MapList ml = null; int i = 0; - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.fromSeq == seq) { @@ -388,7 +313,7 @@ public class AlignedCodonFrame /* * Search mapped protein ('to') sequences first. */ - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.fromSeq == seq || ssm.fromSeq == seq.getDatasetSequence()) { @@ -406,7 +331,7 @@ public class AlignedCodonFrame /* * Then try mapped dna sequences. */ - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.mapping.to == seq || ssm.mapping.to == seq.getDatasetSequence()) @@ -445,7 +370,7 @@ public class AlignedCodonFrame { return null; } - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { /* * try mapping from target to query @@ -491,7 +416,7 @@ public class AlignedCodonFrame SequenceI dnaSeq = null; List result = new ArrayList<>(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { if (ssm.mapping.to == protein && ssm.mapping.getMap().getFromRatio() == 3) @@ -533,7 +458,7 @@ public class AlignedCodonFrame SequenceI seqDs = seq.getDatasetSequence(); seqDs = seqDs != null ? seqDs : seq; - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { final Mapping mapping = ssm.mapping; if (ssm.fromSeq == seqDs) @@ -593,7 +518,7 @@ public class AlignedCodonFrame /* * check for replaceable DNA ('map from') sequences */ - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) { SequenceI dna = ssm.fromSeq; if (dna instanceof SequenceDummy @@ -686,7 +611,7 @@ public class AlignedCodonFrame } SequenceI ds = seq.getDatasetSequence(); - for (SequenceToSequenceMapping ssm : mappings) + for (SequenceMapping ssm : mappings) /* * 'from' sequences */ @@ -742,7 +667,7 @@ public class AlignedCodonFrame SequenceI dssTo = toSeq.getDatasetSequence() == null ? toSeq : toSeq.getDatasetSequence(); - for (SequenceToSequenceMapping mapping : mappings) + for (SequenceMapping mapping : mappings) { SequenceI from = mapping.fromSeq; SequenceI to = mapping.mapping.to; @@ -758,7 +683,7 @@ public class AlignedCodonFrame /** * Returns a hashcode derived from the list of sequence mappings * - * @see SequenceToSequenceMapping#hashCode() + * @see SequenceMapping#hashCode() * @see AbstractList#hashCode() */ @Override @@ -783,7 +708,7 @@ public class AlignedCodonFrame return this.mappings.equals(((AlignedCodonFrame) obj).mappings); } - public List getMappings() + public List getMappings() { return mappings; } diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 3b0ca46..5ad8be1 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -21,7 +21,6 @@ package jalview.datamodel; import jalview.analysis.AlignmentUtils; -import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping; import jalview.io.FastaFile; import jalview.util.Comparison; import jalview.util.LinkedIdentityHashSet; @@ -1146,7 +1145,7 @@ public class Alignment implements AlignmentI, AutoCloseable // verify all mappings are in dataset for (AlignedCodonFrame cf : codonFrameList) { - for (SequenceToSequenceMapping ssm : cf.getMappings()) + for (SequenceMapping ssm : cf.getMappings()) { if (!seqs.contains(ssm.getFromSeq())) { diff --git a/src/jalview/datamodel/MappingType.java b/src/jalview/datamodel/MappingType.java index 551e5d8..dbd078d 100644 --- a/src/jalview/datamodel/MappingType.java +++ b/src/jalview/datamodel/MappingType.java @@ -22,42 +22,17 @@ package jalview.datamodel; /** * An enumeration of the kinds of mapping (from nucleotide or peptide, to - * nucleotide or peptide), and the corresponding word lengths + * nucleotide or peptide), and the corresponding word lengths. This is based on, + * but extends (and renames) the values used by Exonerate. + * + * @see https://www.ebi.ac.uk/about/vertebrate-genomics/software/exonerate-manual */ public enum MappingType { - NucleotideToPeptide(3, 1) - { - @Override - public MappingType getInverse() - { - return PeptideToNucleotide; - } - }, - PeptideToNucleotide(1, 3) - { - @Override - public MappingType getInverse() - { - return NucleotideToPeptide; - } - }, - NucleotideToNucleotide(1, 1) - { - @Override - public MappingType getInverse() - { - return NucleotideToNucleotide; - } - }, - PeptideToPeptide(1, 1) - { - @Override - public MappingType getInverse() - { - return PeptideToPeptide; - } - }; + GenomeToCdna(1, 1), CdnaToGenome(1, 1), GenomeToCds(1, 1), + CdsToGenome(1, 1), CdnaToCds(1, 1), CdsToCdna(1, 1), + GenomeToPeptide(3, 1), PeptideToGenome(1, 3), CdnaToPeptide(3, 1), + PeptideToCdna(1, 3), CdsToPeptide(3, 1), PeptideToCds(1, 3); private int fromRatio; @@ -69,15 +44,49 @@ public enum MappingType toRatio = toSize; } - public abstract MappingType getInverse(); - + /** + * Answers the number of positions each 'word' maps from (e.g. 3 when mapping + * from codons in nucleotide to peptide residues) + * + * @return + */ public int getFromRatio() { return fromRatio; } + /** + * Answers the number of positions each 'word' maps to (e.g. 3 when mapping + * from peptide residues to codons in nucleotide) + * + * @return + */ public int getToRatio() { return toRatio; } + + /** + * Answers true if the mapping is from nucleotide to peptide, else false + * + * @param type + * @return + */ + public static boolean isDnaToPeptide(MappingType type) + { + return type != null && type.getFromRatio() == 3 + && type.getToRatio() == 1; + } + + /** + * Answers true if the mapping is from peptide to nucleotide, else false + * + * @param type + * @return + */ + public static boolean isPeptideToDna(MappingType type) + { + return type != null && type.getFromRatio() == 1 + && type.getToRatio() == 3; + } } diff --git a/src/jalview/datamodel/SequenceMapping.java b/src/jalview/datamodel/SequenceMapping.java new file mode 100644 index 0000000..ade5673 --- /dev/null +++ b/src/jalview/datamodel/SequenceMapping.java @@ -0,0 +1,83 @@ +package jalview.datamodel; + +/** + * Data bean that holds a mapping from one sequence to another + */ +public class SequenceMapping +{ + SequenceI fromSeq; + + Mapping mapping; + + private MappingType type; + + SequenceMapping(SequenceI from, Mapping map) + { + this.fromSeq = from; + this.mapping = map; + } + + /** + * Readable representation for debugging only, not guaranteed not to change + */ + @Override + public String toString() + { + return String.format("From %s %s", fromSeq.getName(), + mapping.toString()); + } + + /** + * Returns a hashCode derived from the hashcodes of the mappings and fromSeq + * + * @see SequenceMapping#hashCode() + */ + @Override + public int hashCode() + { + return (fromSeq == null ? 0 : fromSeq.hashCode() * 31) + + mapping.hashCode(); + } + + /** + * Answers true if the objects hold the same mapping between the same two + * sequences + * + * @see Mapping#equals + */ + @Override + public boolean equals(Object obj) + { + if (!(obj instanceof SequenceMapping)) + { + return false; + } + SequenceMapping that = (SequenceMapping) obj; + if (this.mapping == null) + { + return that.mapping == null; + } + // TODO: can simplify by asserting fromSeq is a dataset sequence + return (this.fromSeq == that.fromSeq + || (this.fromSeq != null && that.fromSeq != null + && this.fromSeq.getDatasetSequence() != null + && this.fromSeq.getDatasetSequence() == that.fromSeq + .getDatasetSequence())) + && this.mapping.equals(that.mapping); + } + + public SequenceI getFromSeq() + { + return fromSeq; + } + + public Mapping getMapping() + { + return mapping; + } + + public MappingType getType() + { + return type; + } +} \ No newline at end of file diff --git a/src/jalview/datamodel/SequenceMappings.java b/src/jalview/datamodel/SequenceMappings.java new file mode 100644 index 0000000..65dab33 --- /dev/null +++ b/src/jalview/datamodel/SequenceMappings.java @@ -0,0 +1,88 @@ +package jalview.datamodel; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * A singleton object that holds all mappings between sequences + * + * @author gmcarstairs + * + */ +public class SequenceMappings +{ + private static SequenceMappings instance; + + private Map> mappingsFrom; + + private Map> mappingsTo; + + /** + * Non-instantiable class + */ + private SequenceMappings() + { + mappingsFrom = new HashMap<>(); + mappingsTo = new HashMap<>(); + } + + /** + * Answers the singleton instance of this class + * + * @return + */ + public SequenceMappings getInstance() + { + return instance; + } + + /** + * Answers a (possibly empty) unmodifiable list of mappings from the given + * sequence + * + * @param seq + * @return + */ + public List getMappingsFromSequence(SequenceI seq) + { + List from = mappingsFrom.get(seq); + return from == null ? Collections.emptyList() + : Collections.unmodifiableList(from); + } + + /** + * Answers a (possibly empty) unmodifiable list of mappings to the given + * sequence + * + * @param seq + * @return + */ + public List getMappingsToSequence(SequenceI seq) + { + List from = mappingsTo.get(seq); + return from == null ? Collections.emptyList() + : Collections.unmodifiableList(from); + } + + /** + * Answers a (possibly empty) list of mappings from the given sequence to its + * complement(s), defined as mappings that are either CdsToPeptide or + * PeptideToCds + * + * @param seq + * @return + */ + public List getMappingsToComplement(SequenceI seq) + { + List from = mappingsTo.get(seq); + List result = new ArrayList<>(); + for (SequenceMapping mapping : from) + { + MappingType type = mapping.getType(); + } + return result; + } +} diff --git a/src/jalview/io/gff/ExonerateHelper.java b/src/jalview/io/gff/ExonerateHelper.java index da0c245..303a5ac 100644 --- a/src/jalview/io/gff/ExonerateHelper.java +++ b/src/jalview/io/gff/ExonerateHelper.java @@ -164,9 +164,8 @@ public class ExonerateHelper extends Gff2Helper */ SequenceI mapFromSequence = seq; SequenceI mapToSequence = mappedSequence; - if ((type == MappingType.NucleotideToPeptide && featureIsOnTarget) - || (type == MappingType.PeptideToNucleotide - && !featureIsOnTarget)) + if ((MappingType.isDnaToPeptide(type) && featureIsOnTarget) + || (MappingType.isPeptideToDna(type) && !featureIsOnTarget)) { mapFromSequence = mappedSequence; mapToSequence = seq; @@ -299,7 +298,7 @@ public class ExonerateHelper extends Gff2Helper } /** - * Returns a MappingType depending on the exonerate 'model' value. + * Returns a MappingType depending on the exonerate 'model' value * * @param model * @return @@ -308,14 +307,25 @@ public class ExonerateHelper extends Gff2Helper { MappingType result = null; - if (model.contains(PROTEIN2DNA) || model.contains(PROTEIN2GENOME)) + if (model.contains(PROTEIN2GENOME)) { - result = MappingType.PeptideToNucleotide; + result = MappingType.PeptideToGenome; } - else if (model.contains(CODING2CODING) || model.contains(CODING2GENOME) - || model.contains(CDNA2GENOME) || model.contains(GENOME2GENOME)) + else if (model.contains(PROTEIN2DNA)) { - result = MappingType.NucleotideToNucleotide; + result = MappingType.PeptideToCds; + } + else if (model.contains(CODING2GENOME)) + { + result = MappingType.CdsToGenome; + } + else if (model.contains(CDNA2GENOME)) + { + result = MappingType.CdnaToGenome; + } + else if (model.contains(CODING2CODING) || model.contains(GENOME2GENOME)) + { + result = MappingType.GenomeToCdna; } return result; } diff --git a/src/jalview/io/gff/Gff3Helper.java b/src/jalview/io/gff/Gff3Helper.java index a25a014..ac4e1d8 100644 --- a/src/jalview/io/gff/Gff3Helper.java +++ b/src/jalview/io/gff/Gff3Helper.java @@ -216,7 +216,7 @@ public class Gff3Helper extends GffHelperBase int fromStart = Integer.parseInt(gffColumns[START_COL]); int fromEnd = Integer.parseInt(gffColumns[END_COL]); MapList mapping = constructMappingFromAlign(fromStart, fromEnd, - toStart, toEnd, MappingType.NucleotideToNucleotide); + toStart, toEnd, MappingType.GenomeToCdna); if (mapping != null) { diff --git a/src/jalview/io/gff/GffHelperBase.java b/src/jalview/io/gff/GffHelperBase.java index 1d4d3ac..2206a03 100644 --- a/src/jalview/io/gff/GffHelperBase.java +++ b/src/jalview/io/gff/GffHelperBase.java @@ -88,15 +88,15 @@ public abstract class GffHelperBase implements GffHelperI int[] to = new int[] { toStart, toEnd }; /* - * Jalview always models from dna to protein, so switch values if the - * GFF mapping is from protein to dna + * Jalview always models from dna to protein, so invert + * mapping if the GFF mapping is from protein to dna */ - if (mappingType == MappingType.PeptideToNucleotide) + if (MappingType.isPeptideToDna(mappingType)) { int[] temp = from; from = to; to = temp; - mappingType = mappingType.getInverse(); + mappingType = MappingType.CdsToPeptide; } int fromRatio = mappingType.getFromRatio(); @@ -286,7 +286,7 @@ public abstract class GffHelperBase implements GffHelperI String namesDelimiter, char nameValueSeparator, String valuesDelimiter) { - Map> map = new HashMap>(); + Map> map = new HashMap<>(); if (text == null || text.trim().length() == 0) { return map; @@ -314,7 +314,7 @@ public abstract class GffHelperBase implements GffHelperI List vals = map.get(key); if (vals == null) { - vals = new ArrayList(); + vals = new ArrayList<>(); map.put(key, vals); } for (String val : values.split(valuesDelimiter)) diff --git a/test/jalview/analysis/CrossRefTest.java b/test/jalview/analysis/CrossRefTest.java index 81ec443..2809004 100644 --- a/test/jalview/analysis/CrossRefTest.java +++ b/test/jalview/analysis/CrossRefTest.java @@ -29,7 +29,6 @@ import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; import jalview.datamodel.AlignedCodonFrame; -import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; @@ -37,6 +36,7 @@ import jalview.datamodel.Mapping; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import jalview.datamodel.SequenceMapping; import jalview.gui.JvOptionPane; import jalview.util.DBRefUtils; import jalview.util.MapList; @@ -311,9 +311,9 @@ public class CrossRefTest assertEquals(1, result.size()); assertSame(dna1, result.get(0)); // should now have a mapping from dna to pep1 - List mappings = acf.getMappings(); + List mappings = acf.getMappings(); assertEquals(1, mappings.size()); - SequenceToSequenceMapping mapping = mappings.get(0); + SequenceMapping mapping = mappings.get(0); assertSame(dna1, mapping.getFromSeq()); assertSame(pep1, mapping.getMapping().getTo()); MapList mapList = mapping.getMapping().getMap(); diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index dd19eb6..63f8e93 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -28,7 +28,6 @@ import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; import jalview.analysis.AlignmentGenerator; -import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping; import jalview.gui.JvOptionPane; import jalview.io.DataSourceType; import jalview.io.FileFormat; @@ -264,7 +263,7 @@ public class AlignmentTest { for (AlignedCodonFrame alc : alignment.getCodonFrames()) { - for (SequenceToSequenceMapping ssm : alc.getMappings()) + for (SequenceMapping ssm : alc.getMappings()) { if (ssm.getFromSeq().getDatasetSequence() != null) { diff --git a/test/jalview/datamodel/MappingTypeTest.java b/test/jalview/datamodel/MappingTypeTest.java index f6a1116..560fa71 100644 --- a/test/jalview/datamodel/MappingTypeTest.java +++ b/test/jalview/datamodel/MappingTypeTest.java @@ -21,51 +21,57 @@ package jalview.datamodel; import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertSame; -import jalview.gui.JvOptionPane; - -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class MappingTypeTest { - @BeforeClass(alwaysRun = true) - public void setUpJvOptionPane() - { - JvOptionPane.setInteractiveMode(false); - JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); - } - - @Test(groups = "Functional") - public void testGetInverse() - { - assertSame(MappingType.PeptideToNucleotide, - MappingType.NucleotideToPeptide.getInverse()); - assertSame(MappingType.NucleotideToPeptide, - MappingType.PeptideToNucleotide.getInverse()); - assertSame(MappingType.NucleotideToNucleotide, - MappingType.NucleotideToNucleotide.getInverse()); - assertSame(MappingType.PeptideToPeptide, - MappingType.PeptideToPeptide.getInverse()); - } - @Test(groups = "Functional") public void testGetFromRatio() { - assertEquals(1, MappingType.NucleotideToNucleotide.getFromRatio()); - assertEquals(1, MappingType.PeptideToNucleotide.getFromRatio()); - assertEquals(1, MappingType.PeptideToPeptide.getFromRatio()); - assertEquals(3, MappingType.NucleotideToPeptide.getFromRatio()); + /* + * nucleotide-nucleotide + */ + assertEquals(1, MappingType.GenomeToCdna.getFromRatio()); + assertEquals(1, MappingType.CdnaToGenome.getFromRatio()); + assertEquals(1, MappingType.GenomeToCds.getFromRatio()); + assertEquals(1, MappingType.CdsToGenome.getFromRatio()); + assertEquals(1, MappingType.CdnaToCds.getFromRatio()); + assertEquals(1, MappingType.CdsToCdna.getFromRatio()); + + /* + * nucleotide-peptide + */ + assertEquals(3, MappingType.GenomeToPeptide.getFromRatio()); + assertEquals(1, MappingType.PeptideToGenome.getFromRatio()); + assertEquals(3, MappingType.CdnaToPeptide.getFromRatio()); + assertEquals(1, MappingType.PeptideToCdna.getFromRatio()); + assertEquals(3, MappingType.CdsToPeptide.getFromRatio()); + assertEquals(1, MappingType.PeptideToCds.getFromRatio()); } @Test(groups = "Functional") public void testGetToRatio() { - assertEquals(1, MappingType.NucleotideToNucleotide.getToRatio()); - assertEquals(3, MappingType.PeptideToNucleotide.getToRatio()); - assertEquals(1, MappingType.PeptideToPeptide.getToRatio()); - assertEquals(1, MappingType.NucleotideToPeptide.getToRatio()); + /* + * nucleotide-nucleotide + */ + assertEquals(1, MappingType.GenomeToCdna.getToRatio()); + assertEquals(1, MappingType.CdnaToGenome.getToRatio()); + assertEquals(1, MappingType.GenomeToCds.getToRatio()); + assertEquals(1, MappingType.CdsToGenome.getToRatio()); + assertEquals(1, MappingType.CdnaToCds.getToRatio()); + assertEquals(1, MappingType.CdsToCdna.getToRatio()); + + /* + * nucleotide-peptide + */ + assertEquals(1, MappingType.GenomeToPeptide.getToRatio()); + assertEquals(3, MappingType.PeptideToGenome.getToRatio()); + assertEquals(1, MappingType.CdnaToPeptide.getToRatio()); + assertEquals(3, MappingType.PeptideToCdna.getToRatio()); + assertEquals(1, MappingType.CdsToPeptide.getToRatio()); + assertEquals(3, MappingType.PeptideToCds.getToRatio()); } } diff --git a/test/jalview/io/gff/ExonerateHelperTest.java b/test/jalview/io/gff/ExonerateHelperTest.java index 825af24..940859c 100644 --- a/test/jalview/io/gff/ExonerateHelperTest.java +++ b/test/jalview/io/gff/ExonerateHelperTest.java @@ -62,20 +62,20 @@ public class ExonerateHelperTest public void testGetMappingType() { // protein-to-dna: - assertSame(MappingType.PeptideToNucleotide, + assertSame(MappingType.PeptideToGenome, ExonerateHelper .getMappingType("exonerate:protein2genome:local")); - assertSame(MappingType.PeptideToNucleotide, + assertSame(MappingType.PeptideToGenome, ExonerateHelper.getMappingType("exonerate:protein2dna:local")); // dna-to-dna: - assertSame(MappingType.NucleotideToNucleotide, + assertSame(MappingType.GenomeToCdna, ExonerateHelper.getMappingType("coding2coding")); - assertSame(MappingType.NucleotideToNucleotide, + assertSame(MappingType.GenomeToCdna, ExonerateHelper.getMappingType("coding2genome")); - assertSame(MappingType.NucleotideToNucleotide, + assertSame(MappingType.GenomeToCdna, ExonerateHelper.getMappingType("cdna2genome")); - assertSame(MappingType.NucleotideToNucleotide, + assertSame(MappingType.GenomeToCdna, ExonerateHelper.getMappingType("genome2genome")); assertNull(ExonerateHelper.getMappingType("affine:local")); }