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 jalview.bin.Cache;
24 import jalview.util.ArrayUtils;
26 import java.util.Arrays;
27 import java.util.Vector;
30 * Data model for a <location> child element of a <feature> read
31 * from an EMBL query reply
33 * @see embl_mapping.xml
34 * @see http://www.insdc.org/files/feature_table.html#3.4.2
36 public class EmblFeatureLocations
38 Vector<EmblFeatureLocElement> locElements;
42 boolean locationComplement;
45 * @return the locationComplement
47 public boolean isLocationComplement()
49 return locationComplement;
53 * @param locationComplement
54 * the locationComplement to set
56 public void setLocationComplement(boolean locationComplement)
58 this.locationComplement = locationComplement;
62 * @return the locationType
64 public String getLocationType()
71 * the locationType to set
73 public void setLocationType(String locationType)
75 this.locationType = locationType;
79 * @return the locElements
81 public Vector<EmblFeatureLocElement> getLocElements()
88 * the locElements to set
90 public void setLocElements(Vector<EmblFeatureLocElement> locElements)
92 this.locElements = locElements;
96 * Return all location elements as start-end pairs (without accessions) TODO:
97 * pass back complement and 'less than or more than' range information Note:
98 * do not use this since it throws away any accessionIds associated with each
101 * @return int[] { start1, end1, ... }
103 public int[] getElementRanges()
105 return getElementRanges(null);
109 * Return all location elements concerning given accession as start-end pairs.
110 * If the CDS feature is on the forward strand, then start <= end, if on the
111 * reverse strand then start > end.
114 * the accession string for which locations are requested, or null
116 * @return int[] { start1, end1, ... }
118 int[] getElementRanges(String accession)
121 int[] se = new int[locElements.size() * 2];
122 if ("single".equalsIgnoreCase(locationType)
123 || "join".equalsIgnoreCase(locationType))
125 for (EmblFeatureLocElement loce : locElements)
127 if (accession == null || loce.accession != null
128 && accession.equals(loce.accession))
130 BasePosition bp[] = loce.getBasePositions();
135 int start = Integer.parseInt(bp[0].getPos());
136 int end = Integer.parseInt(bp[1].getPos());
139 } catch (NumberFormatException e)
142 .println("format error in EMBL CDS location basePosition: "
149 .println("format error in EMBL CDS location, basePosition count = "
155 else if (locationType != null)
157 if (Cache.log != null)
160 .error("EmblFeatureLocations.getElementRanges cannot deal with locationType=='"
161 + locationType + "'");
166 .println("EmblFeatureLocations.getElementRanges cannot deal with locationType=='"
167 + locationType + "'");
171 if (sepos != se.length)
174 * we failed to parse something - trim off null values
176 se = Arrays.copyOf(se, sepos);
180 * If on the complement, reverse the ranges to [end, start, ...end1, start1].
181 * For an example of a joined complement, see (tRNA feature) CAGL0B00165r on
182 * http://www.ebi.ac.uk/ena/data/view/CR380948&display=xml
183 * http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/CR380948/emblxml
185 if (locationComplement)
187 ArrayUtils.reverseIntArray(se);