View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2009 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // OldViewXML.java
20  // Since: 2010/04/22
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.config;
26  
27  import java.util.ArrayList;
28  import java.util.HashSet;
29  import java.util.List;
30  import java.util.Set;
31  
32  import org.utgenome.gwt.utgb.client.view.TrackView;
33  
34  /**
35   * For reading view.xml files used in UTGB 1.3.x.
36   * 
37   * @author leo
38   * 
39   */
40  public class OldViewXML {
41  
42  	public static class Prop {
43  		public String key;
44  		public String value;
45  	}
46  
47  	public static class TrackGroup {
48  
49  		public String className;
50  
51  		public GroupProperties groupProperties = new GroupProperties();
52  		public List<Prop> property = new ArrayList<Prop>();
53  		public List<Track> track = new ArrayList<Track>();
54  
55  		public String getProperty(String key) {
56  			for (Prop p : groupProperties.property) {
57  				if (p.key != null && p.key.equals(key)) {
58  					return p.value;
59  				}
60  			}
61  			return null;
62  		}
63  
64  		public Set<String> propKeySet() {
65  			HashSet<String> keySet = new HashSet<String>();
66  			for (Prop p : groupProperties.property) {
67  				if (p.key != null) {
68  					keySet.add(p.key);
69  				}
70  			}
71  			return keySet;
72  		}
73  
74  	}
75  
76  	public static class GroupProperties {
77  		public List<Prop> property = new ArrayList<Prop>();
78  		public TrackWindow trackWindow = new TrackWindow();
79  	}
80  
81  	public static class TrackWindow {
82  		public int start;
83  		public int end;
84  		public int width;
85  	}
86  
87  	public static class Track {
88  
89  		public String name;
90  		public String className;
91  		public int height;
92  		public boolean pack;
93  
94  		public List<Prop> property = new ArrayList<Prop>();
95  	}
96  
97  	public TrackGroup trackGroup;
98  
99  	public TrackView toTrackView() {
100 		TrackView v = new TrackView();
101 		v.trackGroup.class_ = trackGroup.className;
102 		v.trackGroup.id = 1;
103 
104 		// coordinate
105 		TrackView.Coordinate c = new TrackView.Coordinate();
106 		c.start = trackGroup.groupProperties.trackWindow.start;
107 		c.end = trackGroup.groupProperties.trackWindow.end;
108 		c.species = trackGroup.getProperty("species");
109 		c.ref = trackGroup.getProperty("revision");
110 		c.chr = trackGroup.getProperty("target");
111 
112 		c.pixelWidth = trackGroup.groupProperties.trackWindow.width;
113 
114 		v.trackGroup.coordinate = c;
115 		for (Prop p : trackGroup.property) {
116 			v.trackGroup.property.put(p.key, p.value);
117 		}
118 		for (String key : trackGroup.propKeySet()) {
119 			if (key == null)
120 				continue;
121 
122 			if (key.equals("species") || key.equals("revision") || key.equals("target"))
123 				continue;
124 
125 			String val = trackGroup.getProperty(key);
126 			v.trackGroup.property.put(key, val);
127 		}
128 
129 		for (Track each : trackGroup.track) {
130 			TrackView.Track t = new TrackView.Track();
131 			t.name = each.name;
132 			t.height = each.height;
133 			t.pack = each.pack;
134 			t.class_ = each.className;
135 			if (t.class_.startsWith("org.utgenome.gwt.utgb.client.track.lib."))
136 				t.class_ = t.class_.replace("org.utgenome.gwt.utgb.client.track.lib.", "");
137 
138 			for (Prop p : each.property) {
139 				t.property.put(p.key, p.value);
140 			}
141 
142 			v.track.add(t);
143 		}
144 
145 		return v;
146 	}
147 }