X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FAtomSpecModel.java;h=f0d1e847a08ac9ec63937e40c4541866bc256fcf;hb=ec1c914a99011e20634fbff19df71e2627766dfd;hp=f3c9c1ea57393019e59bc4eae48abd58496fd928;hpb=85a66ca345b3831b9925bc421084db9c2af3054b;p=jalview.git diff --git a/src/jalview/ext/rbvi/chimera/AtomSpecModel.java b/src/jalview/ext/rbvi/chimera/AtomSpecModel.java index f3c9c1e..f0d1e84 100644 --- a/src/jalview/ext/rbvi/chimera/AtomSpecModel.java +++ b/src/jalview/ext/rbvi/chimera/AtomSpecModel.java @@ -1,33 +1,35 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.ext.rbvi.chimera; -import jalview.util.IntRangeComparator; - import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; /** - * A class to model a Chimera atomspec pattern, for example - * - *
- * #0:15.A,28.A,54.A,63.A,70-72.A,83-84.A,97-98.A|#1:2.A,6.A,11.A,13-14.A,70.A,82.A,96-97.A
- * 
- * - * where - * - * - *
- * @see http://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/frameatom_spec.html
- * 
+ * A class to model a Chimera or Jmol residue set, as + * {@code Map>>}. This can then be + * traversed to generate the required display command in Chimera or Jmol syntax. */ public class AtomSpecModel { @@ -38,7 +40,12 @@ public class AtomSpecModel */ public AtomSpecModel() { - atomSpec = new TreeMap>>(); + atomSpec = new TreeMap<>(); + } + + public Map>> getMap() + { + return atomSpec; } /** @@ -57,7 +64,7 @@ public class AtomSpecModel Map> modelData = atomSpec.get(model); if (modelData == null) { - atomSpec.put(model, modelData = new TreeMap>()); + atomSpec.put(model, modelData = new TreeMap<>()); } /* @@ -66,7 +73,7 @@ public class AtomSpecModel List chainData = modelData.get(chain); if (chainData == null) { - chainData = new ArrayList(); + chainData = new ArrayList<>(); modelData.put(chain, chainData); } @@ -78,103 +85,42 @@ public class AtomSpecModel } /** - * Returns the range(s) formatted as a Chimera atomspec + * Answers an iterable set of the structure models in this model * * @return */ - public String getAtomSpec() + public Iterable getModels() { - StringBuilder sb = new StringBuilder(128); - boolean firstModel = true; - for (Integer model : atomSpec.keySet()) - { - if (!firstModel) - { - sb.append("|"); - } - firstModel = false; - sb.append("#").append(model).append(":"); - - boolean firstPositionForModel = true; - final Map> modelData = atomSpec.get(model); - - for (String chain : modelData.keySet()) - { - chain = chain.trim(); - - List rangeList = modelData.get(chain); - - /* - * sort ranges into ascending start position order - */ - Collections.sort(rangeList, IntRangeComparator.ASCENDING); - - int start = rangeList.isEmpty() ? 0 : rangeList.get(0)[0]; - int end = rangeList.isEmpty() ? 0 : rangeList.get(0)[1]; - - Iterator iterator = rangeList.iterator(); - while (iterator.hasNext()) - { - int[] range = iterator.next(); - if (range[0] <= end + 1) - { - /* - * range overlaps or is contiguous with the last one - * - so just extend the end position, and carry on - * (unless this is the last in the list) - */ - end = Math.max(end, range[1]); - } - else - { - /* - * we have a break so append the last range - */ - appendRange(sb, start, end, chain, firstPositionForModel); - firstPositionForModel = false; - start = range[0]; - end = range[1]; - } - } - - /* - * and append the last range - */ - if (!rangeList.isEmpty()) - { - appendRange(sb, start, end, chain, firstPositionForModel); - firstPositionForModel = false; - } - } - } - return sb.toString(); + return atomSpec.keySet(); } /** - * @param sb - * @param start - * @param end - * @param chain - * @param firstPositionForModel + * Answers an iterable set of the chains in this model for the given structure + * model, or an empty set if none + * + * @param model + * @return */ - protected void appendRange(StringBuilder sb, int start, int end, - String chain, boolean firstPositionForModel) + public Iterable getChains(Integer model) { - if (!firstPositionForModel) + if (atomSpec.containsKey(model)) { - sb.append(","); + return atomSpec.get(model).keySet(); } - if (end == start) - { - sb.append(start); - } - else - { - sb.append(start).append("-").append(end); - } - if (chain.length() > 0) + return Collections.emptySet(); + } + + public List getRanges(Integer model, String chain) + { + Map> modelData = atomSpec.get(model); + if (modelData != null) { - sb.append(".").append(chain); + List chainData = modelData.get(chain); + if (chainData != null) + { + return chainData; + } } + return Collections.EMPTY_LIST; } }