- Timestamp:
- 08/19/09 05:53:32 (3 years ago)
- Location:
- trunk/corelib/src/org/bridgedb/webservice/biomart/util
- Files:
-
- 1 added
- 1 copied
-
. (added)
-
BiomartClient.java (copied) (copied from trunk/corelib/src/org/bridgedb/webservice/biomart/BiomartStub.java) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/corelib/src/org/bridgedb/webservice/biomart/util/BiomartClient.java
r156 r161 16 16 // 17 17 18 package org.bridgedb.webservice.biomart ;18 package org.bridgedb.webservice.biomart.util; 19 19 20 20 import java.io.BufferedReader; … … 30 30 import java.util.HashMap; 31 31 import java.util.Map; 32 import java.util.Vector;33 32 34 33 import javax.xml.parsers.DocumentBuilder; … … 45 44 * BioMart service class, adapted from BioMart client in Cytoscape. 46 45 */ 47 public final class Biomart Stub{46 public final class BiomartClient { 48 47 public static final String defaultBaseURL = "http://www.biomart.org/biomart/martservice"; 49 48 50 49 private final String baseURL; 51 private static final String RESOURCE = "/org/bridgedb/webservice/biomart/ filterconversion.txt";50 private static final String RESOURCE = "/org/bridgedb/webservice/biomart/util/filterconversion.txt"; 52 51 53 52 //private Map<String, Map<String, String>> databases = null; 54 private Map<String, Database> databases = null;53 private Map<String, Database> marts = null; 55 54 56 55 private Map<String, Dataset> datasets = new HashMap(); 57 private Map<String, Vector<Dataset>> mapDbDss = new HashMap();56 private Map<String, Map<String,Dataset>> mapDbDss = new HashMap(); 58 57 private Map<String, Map<String, Filter>> mapDsFilters = new HashMap(); 59 58 private Map<String, Map<String, Attribute>> mapDsAttrs = new HashMap(); … … 62 61 63 62 private static final int BUFFER_SIZE = 81920; 64 65 // one instance per base url66 private static Map<String, BiomartStub> instances = new HashMap();67 68 /**69 * Get a BioMartStub with the default base URL.70 * @return BiomartStub71 * @throws IOException if failed to read local resource72 */73 public static BiomartStub getInstance() throws IOException {74 return getInstance(defaultBaseURL);75 }76 77 /**78 * Get a BioMartStub with the base URL.79 * @param baseURL base URL of BioMart80 * @return BioMartStub81 * @throws IOException if failed to read local resource82 */83 public static BiomartStub getInstance(String baseURL) throws IOException {84 if (baseURL==null) {85 throw new IllegalArgumentException("base url cannot be null");86 }87 88 BiomartStub instance = instances.get(baseURL);89 if (instance==null) {90 instance = new BiomartStub(baseURL);91 instances.put(baseURL, instance);92 }93 94 return instance;95 }96 97 63 98 64 /** … … 102 68 * @throws IOException if failed to read local resource 103 69 */ 104 p rivate BiomartStub(String baseURL) throws IOException {70 public BiomartClient(String baseURL) throws IOException { 105 71 this.baseURL = baseURL + "?"; 106 72 loadConversionFile(); … … 149 115 * @return converted attribute 150 116 */ 151 p ublic Attribute filterToAttributeName(String dsName, String dbName,117 private Attribute filterToAttribute(String dsName, String dbName, 152 118 String filterID) { 153 119 if (filterConversionMap.get(dbName) == null) { … … 160 126 161 127 /** 128 * 129 * @param dataset 130 * @param filter 131 * @return 132 */ 133 public Attribute filterToAttribute(String dataset, String filter) { 134 Attribute attr; 135 if (dataset.contains("REACTOME")) { 136 attr = filterToAttribute(dataset, "REACTOME", filter); 137 } else if (dataset.contains("UNIPROT")) { 138 attr = filterToAttribute(dataset, "UNIPROT", filter); 139 } else if (dataset.contains("VARIATION")) { 140 attr = getAttribute(dataset, filter + "_stable_id"); 141 } else { 142 attr = getAttribute(dataset, filter); 143 } 144 145 return attr; 146 } 147 148 /** 162 149 * Get the registry information from the base URL. 163 150 * … … 170 157 throws IOException, ParserConfigurationException, SAXException { 171 158 // If already loaded, just return it. 172 if ( databases != null)173 return databases;159 if (marts != null) 160 return marts; 174 161 175 162 // Initialize database map. 176 databases = new HashMap<String, Database>();163 marts = new HashMap<String, Database>(); 177 164 178 165 // Prepare URL for the registry status … … 208 195 } 209 196 210 databases.put(dbID, new Database(dbID,entry));197 marts.put(dbID, new Database(dbID,entry)); 211 198 } 212 199 … … 214 201 is = null; 215 202 216 return databases;203 return marts; 217 204 } 218 205 … … 223 210 * @throws IOException if failed to read 224 211 */ 225 public Vector<Dataset> getAvailableDatasets(final String martName)212 public Map<String, Dataset> getAvailableDatasets(final String martName) 226 213 throws IOException { 227 Vector<Dataset> result = mapDbDss.get(martName);214 Map<String, Dataset> result = mapDbDss.get(martName); 228 215 if (result!=null) { 229 216 return result; … … 239 226 240 227 //final Map<String, String> datasources = new HashMap<String, String>(); 241 result = new Vector();242 243 Database database = databases.get(martName);228 result = new HashMap(); 229 230 Database database = marts.get(martName); 244 231 245 232 if (database==null) { … … 266 253 if ((parts.length > 4) && parts[3].equals("1")) { 267 254 Dataset dataset = new Dataset(parts[1], parts[2], database); 268 result. add(dataset);255 result.put(dataset.getName(),dataset); 269 256 //datasourceMap.put(parts[1], martName); 270 257 datasets.put(parts[1], dataset); … … 498 485 * @return database 499 486 */ 500 public Database get Database(final String dbname) {501 return databases.get(dbname);487 public Database getMart(final String dbname) { 488 return marts.get(dbname); 502 489 } 503 490
