ascii type
[jalview.git] / src / jalview / datamodel / xdb / embl / EmblFeatureLocations.java
1 package jalview.datamodel.xdb.embl;
2
3 import java.util.Iterator;
4 import java.util.Vector;
5
6 public class EmblFeatureLocations {
7     Vector locElements;
8     String locationType;
9     boolean locationComplement;
10     /**
11      * @return the locationComplement
12      */
13     public boolean isLocationComplement() {
14         return locationComplement;
15     }
16     /**
17      * @param locationComplement the locationComplement to set
18      */
19     public void setLocationComplement(boolean locationComplement) {
20         this.locationComplement = locationComplement;
21     }
22     /**
23      * @return the locationType
24      */
25     public String getLocationType() {
26         return locationType;
27     }
28     /**
29      * @param locationType the locationType to set
30      */
31     public void setLocationType(String locationType) {
32         this.locationType = locationType;
33     }
34     /**
35      * @return the locElements
36      */
37     public Vector getLocElements() {
38         return locElements;
39     }
40     /**
41      * @param locElements the locElements to set
42      */
43     public void setLocElements(Vector locElements) {
44         this.locElements = locElements;
45     }
46     /**
47      * Return all location elements as start-end pairs on referenced sequence 
48      * TODO: pass back complement and 'less than or more than' range information
49      * @return int[] { start1, end1, ... }
50      */
51     public int[] getElementRanges() {
52         if (locationType.equalsIgnoreCase("single")) {
53             int[] se = new int[locElements.size()*2];            
54             int sepos=0;
55             for (Iterator le=locElements.iterator();le.hasNext();) {
56                 EmblFeatureLocElement loce = (EmblFeatureLocElement) le.next();
57                 BasePosition bp[] = loce.getBasePositions();
58                 if (bp.length==2) {
59                     se[sepos++] = Integer.parseInt(bp[0].getPos());
60                     se[sepos++] = Integer.parseInt(bp[1].getPos());
61                 }
62             }
63             return se;
64         }
65         if (locationType.equalsIgnoreCase("join")) {
66             int[] se = new int[locElements.size()*2];            
67             int sepos=0;
68             for (Iterator le=locElements.iterator();le.hasNext();) {
69                 EmblFeatureLocElement loce = (EmblFeatureLocElement) le.next();
70                 BasePosition bp[] = loce.getBasePositions();
71                 if (bp.length==2) {
72                     se[sepos++] = Integer.parseInt(bp[0].getPos());
73                     se[sepos++] = Integer.parseInt(bp[1].getPos());
74                 }
75             }
76             return se;
77         }
78         if (locationType!=null)
79         {
80           jalview.bin.Cache.log.error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"+locationType+"'");
81         }
82         return null;
83     }
84 }