+ public static boolean check3diPeptideMapping(AlignmentI al1, AlignmentI al2)
+ {
+ if (al1.getHeight()!=al2.getHeight())
+ { return false;
+ }
+ int mappable=0;
+ for (SequenceI al1seq: al1.getSequences())
+ {
+ boolean foundMappable = false;
+ for (SequenceI al2seq:al2.getSequences())
+ {
+ if (canBuild3diMapping(al1seq,al2seq))
+ {
+ foundMappable = true;
+ break;
+ }
+ }
+ if (foundMappable)
+ {
+ mappable++;
+ }
+ }
+ if (mappable == al1.getHeight())
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * exact name, start-end, and identical length non-gap sequences
+ * @param al1seq
+ * @param al2seq
+ * @return
+ */
+ public static boolean canBuild3diMapping(SequenceI al1seq,
+ SequenceI al2seq)
+ {
+ if (!al1seq.getDisplayId(true)
+ .equalsIgnoreCase(al2seq.getDisplayId(true))) {
+ return false;
+ }
+ String s1 = AlignSeq
+ .extractGaps(jalview.util.Comparison.GapChars,
+ al1seq.getSequenceAsString());
+ String s2 = AlignSeq.extractGaps(
+ jalview.util.Comparison.GapChars,
+ al2seq.getSequenceAsString());
+ return s1.length()==s2.length();
+ }
+
+ public static boolean map3diPeptideToProteinAligment(
+ AlignmentI proteinAlignment, AlignmentI tdiAlignment)
+ {
+ if (proteinAlignment==null || tdiAlignment==null)
+ {
+ return false;
+ }
+ Set<SequenceI> mappedDna = new HashSet<>();
+ Set<SequenceI> mappedProtein = new HashSet<>();
+
+ /*
+ * First pass - map sequences where cross-references exist. This include
+ * 1-to-many mappings to support, for example, variant cDNA.
+ */
+ boolean mappingPerformed = mapProteinToTdiAlignment(proteinAlignment,
+ tdiAlignment, mappedDna, mappedProtein);
+ return mappingPerformed;
+
+
+ }
+
+
+ /**
+ * Make mappings between compatible sequences (ids are identical, length of seqs are identical).
+ *
+ * @param proteinAlignment
+ * @param tdiAlignment
+ * @param mappedTdiSeq
+ * a set of mapped DNA sequences (to add to)
+ * @param mappedProtein
+ * a set of mapped Protein sequences (to add to)
+ * @param xrefsOnly
+ * if true, only map sequences where xrefs exist
+ * @return
+ */
+ protected static boolean mapProteinToTdiAlignment(
+ final AlignmentI proteinAlignment, final AlignmentI tdiAlignment,
+ Set<SequenceI> mappedTdiSeq, Set<SequenceI> mappedProtein)
+ {
+ boolean mappingExistsOrAdded = false;
+ List<SequenceI> thisSeqs = proteinAlignment.getSequences();
+ for (SequenceI aaSeq : thisSeqs)
+ {
+ boolean proteinMapped = false;
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+
+ for (SequenceI cdnaSeq : tdiAlignment.getSequences())
+ {
+
+ if (mappingExists(proteinAlignment.getCodonFrames(),
+ aaSeq.getDatasetSequence(), cdnaSeq.getDatasetSequence()))
+ {
+ mappingExistsOrAdded = true;
+ }
+ else
+ {
+ if (canBuild3diMapping(aaSeq, cdnaSeq))
+ {
+ MapList map = new MapList(new int[] { aaSeq.getStart(),aaSeq.getEnd()},new int[] { cdnaSeq.getStart(),cdnaSeq.getEnd()},1,1);
+ acf.addMap(cdnaSeq, aaSeq, map);
+ mappingExistsOrAdded = true;
+ proteinMapped = true;
+ mappedTdiSeq.add(cdnaSeq);
+ mappedProtein.add(aaSeq);
+ }
+ }
+ }
+ if (proteinMapped)
+ {
+ proteinAlignment.addCodonFrame(acf);
+ }
+ }
+ return mappingExistsOrAdded;
+ }
+