+
+ /**
+ * Change any mapping to the given sequence to be to its dataset sequence
+ * instead. For use when mappings are created before their referenced
+ * sequences are instantiated, for example when parsing GFF data.
+ *
+ * @param seq
+ */
+ public void updateToDataset(SequenceI seq)
+ {
+ if (seq == null || seq.getDatasetSequence() == null)
+ {
+ return;
+ }
+ SequenceI ds = seq.getDatasetSequence();
+
+ for (SequenceToSequenceMapping ssm : mappings)
+ /*
+ * 'from' sequences
+ */
+ {
+ if (ssm.fromSeq == seq)
+ {
+ ssm.fromSeq = ds;
+ }
+
+ /*
+ * 'to' sequences
+ */
+ if (ssm.mapping.to == seq)
+ {
+ ssm.mapping.to = ds;
+ }
+ }
+ }
+
+ /**
+ * Answers true if this object contains no mappings
+ *
+ * @return
+ */
+ public boolean isEmpty()
+ {
+ return mappings.isEmpty();
+ }
+
+ /**
+ * Method for debug / inspection purposes only, may change in future
+ */
+ @Override
+ public String toString()
+ {
+ return mappings == null ? "null" : mappings.toString();
+ }
+
+ /**
+ * Returns the first mapping found that is between 'fromSeq' and 'toSeq', or
+ * null if none found
+ *
+ * @param fromSeq
+ * aligned or dataset sequence
+ * @param toSeq
+ * aligned or dataset sequence
+ * @return
+ */
+ public Mapping getMappingBetween(SequenceI fromSeq, SequenceI toSeq)
+ {
+ SequenceI dssFrom = fromSeq.getDatasetSequence() == null ? fromSeq
+ : fromSeq.getDatasetSequence();
+ SequenceI dssTo = toSeq.getDatasetSequence() == null ? toSeq
+ : toSeq.getDatasetSequence();
+
+ for (SequenceToSequenceMapping mapping : mappings)
+ {
+ SequenceI from = mapping.fromSeq;
+ SequenceI to = mapping.mapping.to;
+ if ((from == dssFrom && to == dssTo)
+ || (from == dssTo && to == dssFrom))
+ {
+ return mapping.mapping;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns a hashcode derived from the list of sequence mappings
+ *
+ * @see SequenceToSequenceMapping#hashCode()
+ * @see AbstractList#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ return this.mappings.hashCode();
+ }
+
+ /**
+ * Two AlignedCodonFrame objects are equal if they hold the same ordered list
+ * of mappings
+ *
+ * @see SequenceToSequenceMapping#
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof AlignedCodonFrame))
+ {
+ return false;
+ }
+ return this.mappings.equals(((AlignedCodonFrame) obj).mappings);
+ }
+
+ public List<SequenceToSequenceMapping> getMappings()
+ {
+ return mappings;
+ }