2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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 {
28 boolean locationComplement;
30 * @return the locationComplement
32 public boolean isLocationComplement() {
33 return locationComplement;
36 * @param locationComplement the locationComplement to set
38 public void setLocationComplement(boolean locationComplement) {
39 this.locationComplement = locationComplement;
42 * @return the locationType
44 public String getLocationType() {
48 * @param locationType the locationType to set
50 public void setLocationType(String locationType) {
51 this.locationType = locationType;
54 * @return the locElements
56 public Vector getLocElements() {
60 * @param locElements the locElements to set
62 public void setLocElements(Vector locElements) {
63 this.locElements = locElements;
66 * Return all location elements as start-end pairs (without accessions)
67 * TODO: pass back complement and 'less than or more than' range information
68 * Note: do not use this since it throws away any accessionIds associated with
70 * @return int[] { start1, end1, ... }
72 public int[] getElementRanges() {
73 return getElementRanges(null);
76 * Return all location elements concerning given accession as start-end pairs
77 * TODO: pass back complement and 'less than or more than' range information
78 * TODO: deal with multiple accessions
79 * @param accession the accession string for which locations are requested, or null for all locations
80 * @return null or int[] { start1, end1, ... }
83 public int[] getElementRanges(String accession)
86 int[] se = new int[locElements.size()*2];
87 if (locationType.equalsIgnoreCase("single")) {
88 for (Enumeration le=locElements.elements();le.hasMoreElements();) {
89 EmblFeatureLocElement loce = (EmblFeatureLocElement) le.nextElement();
90 if (accession==null || loce.accession!=null && accession.equals(loce.accession))
92 BasePosition bp[] = loce.getBasePositions();
94 se[sepos++] = Integer.parseInt(bp[0].getPos());
95 se[sepos++] = Integer.parseInt(bp[1].getPos());
100 if (locationType.equalsIgnoreCase("join")) {
101 for (Enumeration le=locElements.elements();le.hasMoreElements();) {
102 EmblFeatureLocElement loce = (EmblFeatureLocElement) le.nextElement();
103 if (accession==null || loce.accession!=null && accession.equals(loce.accession))
105 BasePosition bp[] = loce.getBasePositions();
107 se[sepos++] = Integer.parseInt(bp[0].getPos());
108 se[sepos++] = Integer.parseInt(bp[1].getPos());
114 if (locationType!=null)
116 if (jalview.bin.Cache.log!=null)
117 jalview.bin.Cache.log.error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"+locationType+"'");
119 System.err.println("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"+locationType+"'");
121 // trim range if necessary.
122 if (se!=null && sepos!=se.length)
124 int[] trimmed = new int[sepos];
125 System.arraycopy(se,0,trimmed, 0, sepos);