2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.datamodel.xdb.embl;
20 import java.util.Enumeration;
21 import java.util.Vector;
23 public class EmblFeatureLocations
29 boolean locationComplement;
32 * @return the locationComplement
34 public boolean isLocationComplement()
36 return locationComplement;
40 * @param locationComplement
41 * the locationComplement to set
43 public void setLocationComplement(boolean locationComplement)
45 this.locationComplement = locationComplement;
49 * @return the locationType
51 public String getLocationType()
58 * the locationType to set
60 public void setLocationType(String locationType)
62 this.locationType = locationType;
66 * @return the locElements
68 public Vector getLocElements()
75 * the locElements to set
77 public void setLocElements(Vector locElements)
79 this.locElements = locElements;
83 * Return all location elements as start-end pairs (without accessions) TODO:
84 * pass back complement and 'less than or more than' range information Note:
85 * do not use this since it throws away any accessionIds associated with each
88 * @return int[] { start1, end1, ... }
90 public int[] getElementRanges()
92 return getElementRanges(null);
96 * Return all location elements concerning given accession as start-end pairs
97 * TODO: pass back complement and 'less than or more than' range information
98 * TODO: deal with multiple accessions
101 * the accession string for which locations are requested, or null
103 * @return null or int[] { start1, end1, ... }
106 public int[] getElementRanges(String accession)
109 int[] se = new int[locElements.size() * 2];
110 if (locationType.equalsIgnoreCase("single"))
112 for (Enumeration le = locElements.elements(); le.hasMoreElements();)
114 EmblFeatureLocElement loce = (EmblFeatureLocElement) le
116 if (accession == null || loce.accession != null
117 && accession.equals(loce.accession))
119 BasePosition bp[] = loce.getBasePositions();
122 se[sepos++] = Integer.parseInt(bp[0].getPos());
123 se[sepos++] = Integer.parseInt(bp[1].getPos());
128 else if (locationType.equalsIgnoreCase("join"))
130 for (Enumeration le = locElements.elements(); le.hasMoreElements();)
132 EmblFeatureLocElement loce = (EmblFeatureLocElement) le
134 if (accession == null || loce.accession != null
135 && accession.equals(loce.accession))
137 BasePosition bp[] = loce.getBasePositions();
140 se[sepos++] = Integer.parseInt(bp[0].getPos());
141 se[sepos++] = Integer.parseInt(bp[1].getPos());
147 else if (locationType != null)
149 if (jalview.bin.Cache.log != null)
150 jalview.bin.Cache.log
151 .error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
152 + locationType + "'");
155 .println("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
156 + locationType + "'");
158 // trim range if necessary.
159 if (se != null && sepos != se.length)
161 int[] trimmed = new int[sepos];
162 System.arraycopy(se, 0, trimmed, 0, sepos);