2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel.xdb.embl;
23 import java.util.Vector;
26 * Data model for a <loctaion> child element of a <feature> read
27 * from an EMBL query reply
29 * @see embl_mapping.xml
31 public class EmblFeatureLocations
33 Vector<EmblFeatureLocElement> locElements;
37 boolean locationComplement;
40 * @return the locationComplement
42 public boolean isLocationComplement()
44 return locationComplement;
48 * @param locationComplement
49 * the locationComplement to set
51 public void setLocationComplement(boolean locationComplement)
53 this.locationComplement = locationComplement;
57 * @return the locationType
59 public String getLocationType()
66 * the locationType to set
68 public void setLocationType(String locationType)
70 this.locationType = locationType;
74 * @return the locElements
76 public Vector<EmblFeatureLocElement> getLocElements()
83 * the locElements to set
85 public void setLocElements(Vector<EmblFeatureLocElement> locElements)
87 this.locElements = locElements;
91 * Return all location elements as start-end pairs (without accessions) TODO:
92 * pass back complement and 'less than or more than' range information Note:
93 * do not use this since it throws away any accessionIds associated with each
96 * @return int[] { start1, end1, ... }
98 public int[] getElementRanges()
100 return getElementRanges(null);
104 * Return all location elements concerning given accession as start-end pairs
105 * TODO: pass back complement and 'less than or more than' range information
106 * TODO: deal with multiple accessions
109 * the accession string for which locations are requested, or null
111 * @return null or int[] { start1, end1, ... }
114 public int[] getElementRanges(String accession)
117 int[] se = new int[locElements.size() * 2];
118 if (locationType.equalsIgnoreCase("single")) // TODO: or "simple" ?
120 for (EmblFeatureLocElement loce : locElements)
122 if (accession == null || loce.accession != null
123 && accession.equals(loce.accession))
125 BasePosition bp[] = loce.getBasePositions();
128 se[sepos++] = Integer.parseInt(bp[0].getPos());
129 se[sepos++] = Integer.parseInt(bp[1].getPos());
134 else if (locationType.equalsIgnoreCase("join"))
136 for (EmblFeatureLocElement loce : locElements)
138 if (accession == null || loce.accession != null
139 && accession.equals(loce.accession))
141 BasePosition bp[] = loce.getBasePositions();
144 se[sepos++] = Integer.parseInt(bp[0].getPos());
145 se[sepos++] = Integer.parseInt(bp[1].getPos());
151 else if (locationType != null)
153 if (jalview.bin.Cache.log != null)
155 jalview.bin.Cache.log
156 .error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
157 + locationType + "'");
162 .println("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
163 + locationType + "'");
166 // trim range if necessary.
167 if (se != null && sepos != se.length)
169 int[] trimmed = new int[sepos];
170 System.arraycopy(se, 0, trimmed, 0, sepos);