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; } }