2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel.xdb.embl;
21 import java.util.Enumeration;
22 import java.util.Iterator;
23 import java.util.Vector;
25 public class EmblFeatureLocations
31 boolean locationComplement;
34 * @return the locationComplement
36 public boolean isLocationComplement()
38 return locationComplement;
42 * @param locationComplement
43 * the locationComplement to set
45 public void setLocationComplement(boolean locationComplement)
47 this.locationComplement = locationComplement;
51 * @return the locationType
53 public String getLocationType()
60 * the locationType to set
62 public void setLocationType(String locationType)
64 this.locationType = locationType;
68 * @return the locElements
70 public Vector getLocElements()
77 * the locElements to set
79 public void setLocElements(Vector locElements)
81 this.locElements = locElements;
85 * Return all location elements as start-end pairs (without accessions) TODO:
86 * pass back complement and 'less than or more than' range information Note:
87 * do not use this since it throws away any accessionIds associated with each
90 * @return int[] { start1, end1, ... }
92 public int[] getElementRanges()
94 return getElementRanges(null);
98 * Return all location elements concerning given accession as start-end pairs
99 * TODO: pass back complement and 'less than or more than' range information
100 * TODO: deal with multiple accessions
103 * the accession string for which locations are requested, or
104 * null for all locations
105 * @return null or int[] { start1, end1, ... }
108 public int[] getElementRanges(String accession)
111 int[] se = new int[locElements.size() * 2];
112 if (locationType.equalsIgnoreCase("single"))
114 for (Enumeration le = locElements.elements(); le.hasMoreElements();)
116 EmblFeatureLocElement loce = (EmblFeatureLocElement) le
118 if (accession == null || loce.accession != null
119 && accession.equals(loce.accession))
121 BasePosition bp[] = loce.getBasePositions();
124 se[sepos++] = Integer.parseInt(bp[0].getPos());
125 se[sepos++] = Integer.parseInt(bp[1].getPos());
130 else if (locationType.equalsIgnoreCase("join"))
132 for (Enumeration le = locElements.elements(); le.hasMoreElements();)
134 EmblFeatureLocElement loce = (EmblFeatureLocElement) le
136 if (accession == null || loce.accession != null
137 && accession.equals(loce.accession))
139 BasePosition bp[] = loce.getBasePositions();
142 se[sepos++] = Integer.parseInt(bp[0].getPos());
143 se[sepos++] = Integer.parseInt(bp[1].getPos());
149 else if (locationType != null)
151 if (jalview.bin.Cache.log != null)
152 jalview.bin.Cache.log
153 .error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
154 + locationType + "'");
157 .println("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
158 + locationType + "'");
160 // trim range if necessary.
161 if (se != null && sepos != se.length)
163 int[] trimmed = new int[sepos];
164 System.arraycopy(se, 0, trimmed, 0, sepos);