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  // Coordinate.java
20  // Since: Jan 16, 2009
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.bio;
26  
27  import java.util.Map;
28  
29  import com.google.gwt.user.client.rpc.IsSerializable;
30  
31  /**
32   * Coordinate system
33   * 
34   * @author leo
35   * 
36   */
37  public class Coordinate implements IsSerializable {
38  
39  	/**
40  	 * Name of the group who defines genetic maps . e.g, utgb, ensembl, ucsc
41  	 */
42  	private String group = "utgb";
43  
44  	/**
45  	 * Species name. e.g., human, medaka, etc.
46  	 */
47  	private String species;
48  
49  	/**
50  	 * Reference genome sequence revision. e.g. hg18 (for human), version1.0 (for medaka)
51  	 */
52  	private String revision;
53  	/**
54  	 * name of the coordinate. e.g. chr1, scaffold10
55  	 */
56  	private String name;
57  
58  	public Coordinate() {
59  	}
60  
61  	public Coordinate(String group, String species, String revision, String name) {
62  		this.group = group;
63  		this.species = species;
64  		this.revision = revision;
65  		this.name = name;
66  	}
67  
68  	public String getTrackURL(String baseURL, Map additionalProperties) {
69  
70  		String url = getTrackURL(baseURL);
71  		StringBuilder buf = new StringBuilder();
72  		buf.append(url);
73  		for (Object eachKey : additionalProperties.keySet()) {
74  			buf.append("&");
75  			buf.append(eachKey.toString());
76  			buf.append("=");
77  			buf.append(additionalProperties.get(eachKey).toString());
78  		}
79  		return buf.toString();
80  	}
81  
82  	public String getTrackURL(String baseURL) {
83  
84  		if (baseURL.contains("%q"))
85  			baseURL = baseURL.replace("%q", "group=%group&species=%species&revision=%ref&name=%chr&start=%start&end=%end&width=%pixelwidth");
86  
87  		baseURL = baseURL.replaceAll("%group", group);
88  		baseURL = baseURL.replaceAll("%species", species);
89  		baseURL = baseURL.replaceAll("%ref", revision);
90  		baseURL = baseURL.replaceAll("%chr", name);
91  
92  		return baseURL.trim();
93  
94  	}
95  
96  	/**
97  	 * Create a new coordinate for UTGB
98  	 * 
99  	 * @param species
100 	 * @param revision
101 	 * @param coordinateName
102 	 * @return
103 	 */
104 	public static Coordinate newUTGBCoordinate(String species, String revision, String coordinateName) {
105 		return new Coordinate("utgb", species, revision, coordinateName);
106 	}
107 
108 	public String getGroup() {
109 		return group;
110 	}
111 
112 	public void setGroup(String group) {
113 		this.group = group;
114 	}
115 
116 	public String getName() {
117 		return name;
118 	}
119 
120 	public void setName(String name) {
121 		this.name = name;
122 	}
123 
124 	public String getSpecies() {
125 		return species;
126 	}
127 
128 	public void setSpecies(String species) {
129 		this.species = species;
130 	}
131 
132 	public String getRevision() {
133 		return revision;
134 	}
135 
136 	public void setRevision(String revision) {
137 		this.revision = revision;
138 	}
139 
140 }