- Timestamp:
- 08/14/09 21:50:23 (3 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/corelib/src/org/bridgedb/webservice/IDMapperBiomart.java
r155 r156 28 28 import java.util.Vector; 29 29 30 import javax.xml.parsers.ParserConfigurationException; 31 30 32 import org.bridgedb.AbstractIDMapperCapabilities; 31 33 import org.bridgedb.BridgeDb; … … 41 43 import org.bridgedb.webservice.biomart.XMLQueryBuilder; 42 44 45 import org.xml.sax.SAXException; 46 43 47 /** 44 48 * … … 55 59 private Driver() { } 56 60 57 private static final String DATASET_TAG = "dataset=";58 59 61 /** {@inheritDoc} */ 60 public IDMapper connect(String location) throws IDMapperException {61 // e.g.: dataset=oanatinus_gene_ensembl62 // e.g.: http://www.biomart.org/biomart/martservice?dataset=oanatinus_gene_ensembl62 public IDMapper connect(String location) throws IDMapperException { 63 // e.g.: transitivity=false,id-type-filter=true@dataset=oanatinus_gene_ensembl 64 // e.g.: http://www.biomart.org/biomart/martservice?dataset=oanatinus_gene_ensembl 63 65 String baseURL = BiomartStub.defaultBaseURL; 64 String param = location; 65 int idx = location.indexOf('?'); 66 boolean transitivity = false; 67 boolean idTypeFilter = true; 68 69 String config = null; 70 String path = location; 71 int idx = location.indexOf("@"); 72 if (idx==0) { 73 path =location.substring(idx+1); 74 } else if (idx>0) { 75 config = location.substring(0, idx); 76 path = location.substring(idx+1); 77 } 78 79 if (config!=null) { 80 String transitivityTag = "transitivity="; 81 idx = config.indexOf(transitivityTag); 82 if (idx!=-1) { 83 String tran = config.substring(idx+transitivityTag.length()); 84 if (tran.toLowerCase().startsWith("true")) { 85 transitivity = true; 86 } else if (tran.toLowerCase().startsWith("false")) { 87 transitivity = false; 88 } else { 89 throw new IDMapperException( 90 "transivity can only be true or false"); 91 } 92 } 93 94 95 String idTypeFilterTag = "id-type-filter="; 96 idx = config.indexOf(idTypeFilterTag); 97 if (idx!=-1) { 98 String filter = config.substring(idx+idTypeFilterTag.length()); 99 if (filter.toLowerCase().startsWith("true")) { 100 idTypeFilter = true; 101 } else if (filter.toLowerCase().startsWith("false")) { 102 idTypeFilter = false; 103 } else { 104 throw new IDMapperException( 105 "id-type-filter can only be true or false"); 106 } 107 } 108 } 109 110 String param = path; 111 idx = path.indexOf('?'); 66 112 if (idx>-1) { 67 baseURL = location.substring(0,idx); 68 param = location.substring(idx+1); 69 } 70 71 idx = param.indexOf(DATASET_TAG); 72 String datasetName = param.substring(idx+DATASET_TAG.length()); 113 baseURL = path.substring(0,idx); 114 param = path.substring(idx+1); 115 } 116 117 String martTag = "mart="; 118 idx = param.indexOf(martTag); 119 String martName = param.substring(idx+martTag.length()); 120 121 idx = martName.indexOf("&"); 122 if (idx>-1) { 123 martName = martName.substring(0,idx); 124 } 125 126 String datasetTag = "dataset="; 127 idx = param.indexOf(datasetTag); 128 String datasetName = param.substring(idx+datasetTag.length()); 73 129 74 130 idx = datasetName.indexOf("&"); … … 77 133 } 78 134 79 return new IDMapperBiomart(datasetName, baseURL); 80 } 81 } 82 135 return new IDMapperBiomart(martName, datasetName, baseURL, 136 idTypeFilter, transitivity); 137 } 138 } 139 140 private String martName; 83 141 private String datasetName; 84 142 private BiomartStub stub; … … 94 152 * Transitivity is unsupported.ID only. ID only for target data sources. 95 153 * Use default url of BiMart. 154 * @param martName name of mart 96 155 * @param datasetName name of dataset 97 156 * @throws IDMapperException if failed to link to the dataset 98 157 */ 99 public IDMapperBiomart(String datasetName) throws IDMapperException {100 this( datasetName, null);158 public IDMapperBiomart(String martName, String datasetName) throws IDMapperException { 159 this(martName, datasetName, null); 101 160 } 102 161 103 162 /** 104 163 * Use default url of BiMart. 164 * @param martName name of mart 105 165 * @param datasetName name of dataset 106 166 * @param idOnlyForTgtDataSource id-only option, filter data source ends … … 109 169 * @throws IDMapperException if failed to link to the dataset 110 170 */ 111 public IDMapperBiomart(String datasetName, boolean idOnlyForTgtDataSource,171 public IDMapperBiomart(String martName, String datasetName, boolean idOnlyForTgtDataSource, 112 172 boolean transitivity) throws IDMapperException { 113 this( datasetName, null, idOnlyForTgtDataSource, transitivity);173 this(martName, datasetName, null, idOnlyForTgtDataSource, transitivity); 114 174 } 115 175 116 176 /** 117 177 * Transitivity is unsupported.ID only. ID only for target data sources. 178 * @param martName name of mart 118 179 * @param datasetName name of dataset 119 180 * @param baseURL base url of BioMart 120 181 * @throws IDMapperException if failed to link to the dataset 121 182 */ 122 public IDMapperBiomart(String datasetName, String baseURL)183 public IDMapperBiomart(String martName, String datasetName, String baseURL) 123 184 throws IDMapperException { 124 this( datasetName, baseURL, true);185 this(martName, datasetName, baseURL, true); 125 186 } 126 187 127 188 /** 128 189 * Transitivity is unsupported. 190 * @param martName name of mart 129 191 * @param datasetName name of dataset 130 192 * @param baseURL base url of BioMart … … 133 195 * @throws IDMapperException if failed to link to the dataset 134 196 */ 135 public IDMapperBiomart(String datasetName, String baseURL,197 public IDMapperBiomart(String martName, String datasetName, String baseURL, 136 198 boolean idOnlyForTgtDataSource) throws IDMapperException { 137 this( datasetName, baseURL, idOnlyForTgtDataSource, false);199 this(martName, datasetName, baseURL, idOnlyForTgtDataSource, false); 138 200 } 139 201 … … 141 203 * Construct from a dataset, a database, id-only option and transitivity 142 204 * option. 205 * @param martName name of mart 143 206 * @param datasetName name of dataset 144 207 * @param baseURL base url of BioMart … … 148 211 * @throws IDMapperException if failed to link to the dataset 149 212 */ 150 public IDMapperBiomart(String datasetName, String baseURL,213 public IDMapperBiomart(String martName, String datasetName, String baseURL, 151 214 boolean idOnlyForTgtDataSource, boolean transitivity) throws IDMapperException { 215 this.martName = martName; 152 216 this.datasetName = datasetName; 153 217 if (baseURL!=null) { … … 162 226 throw new IDMapperException(e); 163 227 } 228 229 try { 230 if (!stub.getRegistry().containsKey(martName)) { 231 throw new IDMapperException("Mart not exist."); 232 } 233 234 if (!stub.getAvailableDatasets(martName).contains(stub.getDataset(datasetName))) { 235 throw new IDMapperException("dataset not exist."); 236 } 237 } catch (IOException e) { 238 throw new IDMapperException(e); 239 } catch (ParserConfigurationException e) { 240 throw new IDMapperException(e); 241 } catch (SAXException e) { 242 throw new IDMapperException(e); 243 } 164 244 165 245 setIDOnlyForTgtDataSource(idOnlyForTgtDataSource); … … 224 304 public String getBaseURL() { 225 305 return baseURL; 306 } 307 308 /** 309 * 310 * @param mart mart name 311 */ 312 public void setMart(final String mart) { 313 this.martName = mart; 314 } 315 316 /** 317 * 318 * @return mart name 319 */ 320 public String getMart() { 321 return martName; 226 322 } 227 323
