Changeset 156
- Timestamp:
- 08/14/09 21:50:23 (2 years ago)
- Location:
- trunk/corelib
- Files:
-
- 5 modified
-
src/org/bridgedb/file/IDMapperText.java (modified) (4 diffs)
-
src/org/bridgedb/webservice/IDMapperBiomart.java (modified) (11 diffs)
-
src/org/bridgedb/webservice/biomart/BiomartStub.java (modified) (1 diff)
-
test/org/bridgedb/TestBiomart.java (modified) (3 diffs)
-
test/org/bridgedb/TestFile.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/corelib/src/org/bridgedb/file/IDMapperText.java
r134 r156 49 49 { 50 50 // parse arguments to determine idsep and dssep 51 // sample: dssep :\t,idsep:;,idsep:,@file:/localfile.txt51 // sample: dssep=\t,idsep=;,idsep=,,transitivity=false@file:/localfile.txt 52 52 // \t represents tab, \@ represents @ 53 53 String path = null; 54 54 char[] dssep = null; 55 55 char[] idsep = null; 56 boolean transitivity = false; 56 57 57 58 int idx = location.indexOf("@"); … … 81 82 82 83 String config = location.substring(0, idx)+","; 84 String prefixTran = "transitivity="; 85 idx = config.indexOf(prefixTran); 86 String tran = config.substring(idx+prefixTran.length()); 87 if (tran.toLowerCase().startsWith("true")) { 88 transitivity = true; 89 } else if (tran.toLowerCase().startsWith("false")) { 90 transitivity = false; 91 } else { 92 throw new IDMapperException( 93 "transivity can only be true or false"); 94 } 95 83 96 dssep = parseConfig(config, "dssep"); 84 97 idsep = parseConfig(config, "idsep"); … … 88 101 try 89 102 { 90 return new IDMapperText(new URL(path), dssep, idsep); 103 return new IDMapperText(new URL(path), dssep, idsep, 104 transitivity); 91 105 } 92 106 catch (MalformedURLException ex) … … 98 112 private char[] parseConfig(String config, String head) { 99 113 Set<Character> delimiters = new HashSet(); 100 Pattern p = Pattern.compile(head+":(.|\\t|\\@),", Pattern.CASE_INSENSITIVE); 114 Pattern p = Pattern.compile(head+"=(.|\\t|\\@),", 115 Pattern.CASE_INSENSITIVE); 101 116 Matcher m = p.matcher(config); 102 117 while (m.find()) { -
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 -
trunk/corelib/src/org/bridgedb/webservice/biomart/BiomartStub.java
r134 r156 242 242 243 243 Database database = databases.get(martName); 244 245 if (database==null) { 246 return null; 247 } 244 248 245 249 Map<String, String> detail = database.getParam(); -
trunk/corelib/test/org/bridgedb/TestBiomart.java
r149 r156 61 61 for (Dataset ds : datasets) { 62 62 System.out.println ("\t" + ds.getName()); 63 IDMapperBiomart idMapper = new IDMapperBiomart(d s.getName());63 IDMapperBiomart idMapper = new IDMapperBiomart(db.getName(),ds.getName()); 64 64 //IDMapper idMapper = BridgeDb.connect("idmapper-biomart:dataset="+ds.getName()); 65 65 IDMapperCapabilities cap = idMapper.getCapabilities(); … … 100 100 // System.out.println (db.getName()); 101 101 // } 102 BiomartStub biomartStub = BiomartStub.getInstance();102 //BiomartStub biomartStub = BiomartStub.getInstance(); 103 103 104 Set<Dataset> datasets = new HashSet(biomartStub.getAvailableDatasets("ensembl"));104 //Set<Dataset> datasets = new HashSet(biomartStub.getAvailableDatasets("ensembl")); 105 105 106 IDMapperBiomart mapper = new IDMapperBiomart(" hsapiens_gene_ensembl");106 IDMapperBiomart mapper = new IDMapperBiomart("ensembl", "hsapiens_gene_ensembl"); 107 107 System.out.println("\n===Supported source data sources==="); 108 108 for (DataSource ds : mapper.getCapabilities().getSupportedSrcDataSources()) … … 127 127 128 128 //IDMapperBiomart mapper = new IDMapperBiomart("hsapiens_gene_ensembl"); 129 IDMapper mapper = BridgeDb.connect ("idmapper-biomart: dataset=hsapiens_gene_ensembl");129 IDMapper mapper = BridgeDb.connect ("idmapper-biomart:mart=ensembl&dataset=hsapiens_gene_ensembl"); 130 130 System.out.println("\n===Supported source data sources==="); 131 131 for (DataSource ds : mapper.getCapabilities().getSupportedSrcDataSources()) -
trunk/corelib/test/org/bridgedb/TestFile.java
r105 r156 57 57 58 58 public void testRead() throws IDMapperException, IOException 59 { 59 { 60 60 IDMapperFile idMapper = new IDMapperText (YEAST_IDS.toURL()); 61 61 … … 67 67 tgtDataSources.add(ENTREZ); 68 68 tgtDataSources.add(EMBL); 69 69 70 70 long start = System.currentTimeMillis(); 71 71 // mapID for the first time will trigger reading … … 75 75 System.out.println (delta); 76 76 measure.add ("timing::text file non-transitive", "" + delta, "msec"); 77 77 78 78 Set<Xref> expected = new HashSet<Xref>(); 79 79 expected.addAll (Arrays.asList( 80 new Xref("YHR055C", ENS_YEAST), 81 new Xref("U00061", EMBL), 80 new Xref("YHR055C", ENS_YEAST), 81 new Xref("U00061", EMBL), 82 82 new Xref("K02204", EMBL), 83 83 new Xref("AY558517", EMBL), … … 88 88 Set<Xref> xrefs = mapXrefs.get(XREF1); 89 89 assertEquals (expected, xrefs); 90 90 91 91 for (Xref xr : xrefs) { 92 92 System.out.println(xr.getDataSource().getFullName() + ": " + xr.getId()); 93 93 } 94 94 95 95 } 96 96 97 97 public void testTransitive() throws MalformedURLException, IDMapperException 98 98 { 99 IDMapperFile idMapper = new IDMapperText (YEAST_IDS.toURL(), 99 IDMapperFile idMapper = new IDMapperText (YEAST_IDS.toURL(), 100 100 new char[] { '\t' }, 101 101 new char[] { ',' }, 102 102 true); 103 103 104 104 Set<Xref> srcXrefs = new HashSet<Xref>(); 105 105 srcXrefs.add(XREF1); … … 109 109 tgtDataSources.add(ENTREZ); 110 110 tgtDataSources.add(EMBL); 111 111 112 112 long start = System.currentTimeMillis(); 113 113 // mapID for the first time will trigger reading … … 117 117 System.out.println (delta); 118 118 measure.add ("timing::text file transitive", "" + delta, "msec"); 119 119 120 120 System.out.println (mapXrefs); 121 121 Set<Xref> xrefs = mapXrefs.get(XREF1); 122 122 123 123 for (Xref xr : xrefs) { 124 124 System.out.println(xr.getDataSource().getFullName() + ": " + xr.getId());
