2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.Iterator;
22 import java.util.Vector;
24 public class EmblFeatureLocations
30 boolean locationComplement;
33 * @return the locationComplement
35 public boolean isLocationComplement()
37 return locationComplement;
41 * @param locationComplement
42 * the locationComplement to set
44 public void setLocationComplement(boolean locationComplement)
46 this.locationComplement = locationComplement;
50 * @return the locationType
52 public String getLocationType()
59 * the locationType to set
61 public void setLocationType(String locationType)
63 this.locationType = locationType;
67 * @return the locElements
69 public Vector getLocElements()
76 * the locElements to set
78 public void setLocElements(Vector locElements)
80 this.locElements = locElements;
84 * Return all location elements as start-end pairs (without accessions) TODO:
85 * pass back complement and 'less than or more than' range information Note:
86 * do not use this since it throws away any accessionIds associated with each
89 * @return int[] { start1, end1, ... }
91 public int[] getElementRanges()
93 return getElementRanges(null);
97 * Return all location elements concerning given accession as start-end pairs
98 * TODO: pass back complement and 'less than or more than' range information
99 * TODO: deal with multiple accessions
102 * the accession string for which locations are requested, or null
104 * @return null or int[] { start1, end1, ... }
107 public int[] getElementRanges(String accession)
110 int[] se = new int[locElements.size() * 2];
111 if (locationType.equalsIgnoreCase("single"))
113 for (Enumeration le = locElements.elements(); le.hasMoreElements();)
115 EmblFeatureLocElement loce = (EmblFeatureLocElement) le
117 if (accession == null || loce.accession != null
118 && accession.equals(loce.accession))
120 BasePosition bp[] = loce.getBasePositions();
123 se[sepos++] = Integer.parseInt(bp[0].getPos());
124 se[sepos++] = Integer.parseInt(bp[1].getPos());
129 else if (locationType.equalsIgnoreCase("join"))
131 for (Enumeration le = locElements.elements(); le.hasMoreElements();)
133 EmblFeatureLocElement loce = (EmblFeatureLocElement) le
135 if (accession == null || loce.accession != null
136 && accession.equals(loce.accession))
138 BasePosition bp[] = loce.getBasePositions();
141 se[sepos++] = Integer.parseInt(bp[0].getPos());
142 se[sepos++] = Integer.parseInt(bp[1].getPos());
148 else if (locationType != null)
150 if (jalview.bin.Cache.log != null)
151 jalview.bin.Cache.log
152 .error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
153 + locationType + "'");
156 .println("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
157 + locationType + "'");
159 // trim range if necessary.
160 if (se != null && sepos != se.length)
162 int[] trimmed = new int[sepos];
163 System.arraycopy(se, 0, trimmed, 0, sepos);