Skip to content

Commit b8c28a8

Browse files
committed
Merge branch 'release-1.0.25'
2 parents b3bd485 + ed1f39f commit b8c28a8

22 files changed

Lines changed: 501 additions & 761 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>baseCode</name>
66
<groupId>baseCode</groupId>
77
<artifactId>baseCode</artifactId>
8-
<version>1.0.24</version>
8+
<version>1.0.25</version>
99
<inceptionYear>2003</inceptionYear>
1010
<description>
1111
<![CDATA[Data structures, math and statistics tools, and utilities that are often needed across projects.]]>

src/ontology.properties

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,30 @@ load.nifstdOntology=false
1313
load.experimentalFactorOntology=false
1414
load.uberonOntology=false
1515

16-
url.chebiOntology=http://ontologies.berkeleybop.org/chebi.owl
17-
url.diseaseOntology=http://ontologies.berkeleybop.org/doid.owl
18-
url.cellTypeOntology=http://ontologies.berkeleybop.org/cl.owl
19-
url.mouseDevelOntology=http://ontologies.berkeleybop.org/emap.owl
20-
url.humanDevelOntology=http://ontologies.berkeleybop.org/ehdaa2.owl
21-
url.mammalPhenotypeOntology=http://ontologies.berkeleybop.org/mp.owl
22-
url.humanPhenotypeOntology=http://ontologies.berkeleybop.org/hp.owl
16+
# where possible, use URLs from http://www.obofoundry.org/
17+
url.chebiOntology=http://purl.obolibrary.org/obo/chebi.owl
18+
url.diseaseOntology=http://purl.obolibrary.org/obo/doid.owl
19+
url.cellTypeOntology=http://purl.obolibrary.org/obo/cl.owl
20+
url.mouseDevelOntology=http://purl.obolibrary.org/obo/emapa.owl
21+
url.humanDevelOntology=http://purl.obolibrary.org/obo/ehdaa2.owl
22+
url.mammalPhenotypeOntology=http://purl.obolibrary.org/obo/mp.owl
23+
url.humanPhenotypeOntology=http://purl.obolibrary.org/obo/hp.owl
24+
url.seqOntology=http://purl.obolibrary.org/obo/so.owl
25+
url.unitsOntology=http://purl.obolibrary.org/obo/uo.owl
26+
url.cellLineOntology=https://raw.githubusercontent.com/CLO-ontology/CLO/master/src/ontology/clo-merged.owl
27+
# Uberon version without extensions: I think this is the right fil from purl
28+
#url.uberonOntology=http://ontologies.berkeleybop.org/uberon.owl
29+
url.uberonOntology=http://purl.obolibrary.org/obo/uberon.owl
30+
31+
# as recommended at https://www.ebi.ac.uk/efo/faq.html#efodownload
32+
url.efOntology=https://raw.githubusercontent.com/EBISPOT/efo/master/efo.owl
2333
url.obiOntology=http://svn.code.sf.net/p/obi/code/releases/2016-10-11/obi.owl
24-
url.seqOntology=http://ontologies.berkeleybop.org/so.owl
25-
url.unitsOntology=http://ontologies.berkeleybop.org/uo.owl
26-
url.cellLineOntology=https://raw.githubusercontent.com/CLO-ontology/CLO/master/src/ontology/clo.owl
27-
url.efOntology=https://www.ebi.ac.uk/efo/efo.owl
28-
# version without extensions:
29-
url.uberonOntology=http://ontologies.berkeleybop.org/uberon.owl
3034

35+
36+
# no longer actively used.
3137
url.nifstdOntology=http://ontology.neuinfo.org/NIF/nif-gemma.owl
32-
url.fmaOntology=http://ontologies.berkeleybop.org/fma.owl
38+
url.fmaOntology=http://purl.obolibrary.org/obo/fma.owl
3339

3440
ontology.index.dir=ontology.index.dir
3541
ontology.cache.dir=
42+
ncbo.api.key=

src/ubic/basecode/ontology/OntologyLoader.java

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.InputStream;
2626
import java.io.InputStreamReader;
2727
import java.io.Reader;
28+
import java.net.HttpURLConnection;
2829
import java.net.URL;
2930
import java.net.URLConnection;
3031
import java.nio.file.Files;
@@ -59,7 +60,7 @@
5960
/**
6061
* Reads ontologies from OWL resources
6162
*
62-
* @author paul
63+
* @author paul
6364
* @version $Id$
6465
*/
6566
public class OntologyLoader {
@@ -70,13 +71,13 @@ public class OntologyLoader {
7071
private static final String TMP_CACHE_SUFFIX = ".tmp";
7172

7273
/**
73-
* @param url
74-
* @param model
74+
* @param url
75+
* @param model
7576
* @return
7677
*/
7778
public static Collection<OntologyResource> initialize( String url, OntModel model ) {
7879

79-
Collection<OntologyResource> result = new HashSet<OntologyResource>();
80+
Collection<OntologyResource> result = new HashSet<>();
8081

8182
ExtendedIterator<OntClass> classIt = model.listClasses();
8283
int count = 0;
@@ -139,9 +140,9 @@ public static Collection<OntologyResource> initialize( String url, OntModel mode
139140
/**
140141
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available.
141142
*
142-
* @param is
143-
* @param url, used as a key
144-
* @param spec
143+
* @param is
144+
* @param url, used as a key
145+
* @param spec
145146
* @return
146147
*/
147148
public static OntModel loadMemoryModel( InputStream is, String url, OntModelSpec spec ) {
@@ -154,7 +155,7 @@ public static OntModel loadMemoryModel( InputStream is, String url, OntModelSpec
154155
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available. Uses
155156
* OWL_MEM_TRANS_INF
156157
*
157-
* @param url
158+
* @param url
158159
* @return
159160
*/
160161
public static OntModel loadMemoryModel( String url ) {
@@ -166,7 +167,7 @@ public static OntModel loadMemoryModel( String url ) {
166167
* OWL_MEM_TRANS_INF
167168
* If load from URL fails, attempt to load from disk cache under @cacheName.
168169
*
169-
* @param url
170+
* @param url
170171
* @return
171172
*/
172173
public static OntModel loadMemoryModel( String url, String cacheName ) {
@@ -176,7 +177,7 @@ public static OntModel loadMemoryModel( String url, String cacheName ) {
176177
/**
177178
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available.
178179
*
179-
* @param url
180+
* @param url
180181
* @return
181182
*/
182183
public static OntModel loadMemoryModel( String url, OntModelSpec spec ) {
@@ -187,9 +188,9 @@ public static OntModel loadMemoryModel( String url, OntModelSpec spec ) {
187188
* Load an ontology into memory. Use this type of model when fast access is critical and memory is available.
188189
* If load from URL fails, attempt to load from disk cache under @cacheName.
189190
*
190-
* @param url
191-
* @param spec e.g. OWL_MEM_TRANS_INF
192-
* @param cacheName unique name of this ontology, will be used to load from disk in case of failed url connection
191+
* @param url
192+
* @param spec e.g. OWL_MEM_TRANS_INF
193+
* @param cacheName unique name of this ontology, will be used to load from disk in case of failed url connection
193194
* @return
194195
*/
195196
public static OntModel loadMemoryModel( String url, OntModelSpec spec, String cacheName ) {
@@ -205,15 +206,34 @@ public static OntModel loadMemoryModel( String url, OntModelSpec spec, String ca
205206
// help ensure mis-configured web servers aren't causing trouble.
206207
urlc.setRequestProperty( "Accept", "application/rdf+xml" );
207208

209+
try {
210+
HttpURLConnection c = ( HttpURLConnection ) urlc;
211+
c.setInstanceFollowRedirects( true );
212+
} catch ( ClassCastException e ) {
213+
// not via http, using a FileURLConnection.
214+
}
215+
208216
if ( tries > 0 ) {
209217
log.info( "Retrying connecting to " + url + " [" + tries + "/" + MAX_CONNECTION_TRIES
210218
+ " of max tries" );
211219
} else {
212-
log.info( "Connecting to ontology from " + url );
220+
log.info( "Connecting to " + url );
213221
}
214222

215223
urlc.connect(); // Will error here on bad URL
216224

225+
if ( urlc instanceof HttpURLConnection ) {
226+
String newUrl = urlc.getHeaderField( "Location" );
227+
228+
if ( StringUtils.isNotBlank( newUrl ) ) {
229+
log.info( "Redirect to " + newUrl );
230+
urlc = new URL( newUrl ).openConnection();
231+
// help ensure mis-configured web servers aren't causing trouble.
232+
urlc.setRequestProperty( "Accept", "application/rdf+xml" );
233+
urlc.connect();
234+
}
235+
}
236+
217237
break;
218238
} catch ( IOException e ) {
219239
// try to recover.
@@ -343,7 +363,7 @@ public static boolean deleteOldCache( String cacheName ) {
343363
/**
344364
* Get model that is entirely in memory with default OntModelSpec.OWL_MEM_RDFS_INF.
345365
*
346-
* @param url
366+
* @param url
347367
* @return
348368
*/
349369
static OntModel getMemoryModel( String url ) {
@@ -353,8 +373,8 @@ static OntModel getMemoryModel( String url ) {
353373
/**
354374
* Get model that is entirely in memory.
355375
*
356-
* @param url
357-
* @param specification
376+
* @param url
377+
* @param specification
358378
* @return
359379
*/
360380
static OntModel getMemoryModel( String url, OntModelSpec specification ) {
@@ -370,7 +390,7 @@ static OntModel getMemoryModel( String url, OntModelSpec specification ) {
370390
}
371391

372392
/**
373-
* @param name
393+
* @param name
374394
* @return
375395
*/
376396
public static File getDiskCachePath( String name ) {
@@ -379,18 +399,16 @@ public static File getDiskCachePath( String name ) {
379399
return null;
380400
}
381401

382-
if (!new File(ontologyDir).exists()) {
383-
new File(ontologyDir).mkdirs();
402+
if ( !new File( ontologyDir ).exists() ) {
403+
new File( ontologyDir ).mkdirs();
384404
}
385-
405+
386406
assert ontologyDir != null;
387407

388408
String path = ontologyDir + File.separator + "ontology" + File.separator + name;
389409

390410
File indexFile = new File( path );
391-
392-
393-
411+
394412
return indexFile;
395413
}
396414

src/ubic/basecode/ontology/model/OntologyTermImpl.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
22
* The baseCode project
3-
*
3+
*
44
* Copyright (c) 2013 University of British Columbia
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
77
* the License. You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
1212
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
* specific language governing permissions and limitations under the License.
@@ -38,18 +38,17 @@
3838

3939
/**
4040
* Represents a class in an ontology
41-
*
41+
*
4242
* @author Paul
43-
* @version $Id$
4443
*/
4544
public class OntologyTermImpl extends AbstractOntologyResource implements OntologyTerm {
4645

4746
private static final String HAS_ALTERNATE_ID = "http://www.geneontology.org/formats/oboInOwl#hasAlternativeId";
4847
private static final String NOTHING = "http://www.w3.org/2002/07/owl#Nothing";
49-
private static Set<String> REJECT_PARENT_URI = new HashSet<String>();
48+
private static Set<String> REJECT_PARENT_URI = new HashSet<>();
5049

5150
/**
52-
*
51+
*
5352
*/
5453
private static final long serialVersionUID = 1L;
5554

@@ -95,7 +94,7 @@ public boolean equals( Object obj ) {
9594

9695
@Override
9796
public Collection<String> getAlternativeIds() {
98-
Collection<String> results = new HashSet<String>();
97+
Collection<String> results = new HashSet<>();
9998

10099
Property alternate = ResourceFactory.createProperty( HAS_ALTERNATE_ID );
101100
for ( StmtIterator it = this.ontResource.listProperties( alternate ); it.hasNext(); ) {
@@ -109,7 +108,7 @@ public Collection<String> getAlternativeIds() {
109108

110109
@Override
111110
public Collection<AnnotationProperty> getAnnotations() {
112-
Collection<AnnotationProperty> annots = new HashSet<AnnotationProperty>();
111+
Collection<AnnotationProperty> annots = new HashSet<>();
113112
StmtIterator iterator = ontResource.listProperties();
114113
// this is a little slow because we have to go through all statements for the term.
115114
while ( iterator.hasNext() ) {
@@ -126,14 +125,14 @@ public Collection<AnnotationProperty> getAnnotations() {
126125

127126
@Override
128127
public Collection<OntologyTerm> getChildren( boolean direct ) {
129-
Collection<OntologyTerm> result = new HashSet<OntologyTerm>();
128+
Collection<OntologyTerm> result = new HashSet<>();
130129
getChildren( direct, result );
131130
return result;
132131
}
133132

134133
/*
135134
* (non-Javadoc)
136-
*
135+
*
137136
* @see ubic.gemma.ontology.OntologyTerm#getComment()
138137
*/
139138
@Override
@@ -144,7 +143,7 @@ public String getComment() {
144143

145144
/*
146145
* (non-Javadoc)
147-
*
146+
*
148147
* @see ubic.gemma.ontology.OntologyTerm#getIndividuals()
149148
*/
150149
@Override
@@ -153,12 +152,12 @@ public Collection<OntologyIndividual> getIndividuals() {
153152
}
154153

155154
/**
156-
* @param direct
155+
* @param direct
157156
* @return
158157
*/
159158
@Override
160159
public Collection<OntologyIndividual> getIndividuals( boolean direct ) {
161-
Collection<OntologyIndividual> inds = new HashSet<OntologyIndividual>();
160+
Collection<OntologyIndividual> inds = new HashSet<>();
162161
ExtendedIterator<? extends OntResource> iterator = this.ontResource.listInstances( direct );
163162
while ( iterator.hasNext() ) {
164163
Individual i = ( Individual ) iterator.next();
@@ -184,20 +183,20 @@ public Object getModel() {
184183

185184
@Override
186185
public Collection<OntologyTerm> getParents( boolean direct ) {
187-
Collection<OntologyTerm> result = new HashSet<OntologyTerm>();
186+
Collection<OntologyTerm> result = new HashSet<>();
188187
this.getParents( direct, result );
189188
return result;
190189
}
191190

192191
/**
193-
*
192+
*
194193
*/
195194
@Override
196195
public Collection<OntologyRestriction> getRestrictions() {
197196
/*
198197
* Remember that restrictions are superclasses.
199198
*/
200-
Collection<OntologyRestriction> result = new HashSet<OntologyRestriction>();
199+
Collection<OntologyRestriction> result = new HashSet<>();
201200
ExtendedIterator<OntClass> iterator = ontResource.listSuperClasses( false );
202201
while ( iterator.hasNext() ) {
203202
OntClass c = iterator.next();
@@ -248,7 +247,7 @@ public Collection<OntologyRestriction> getRestrictions() {
248247

249248
/*
250249
* (non-Javadoc)
251-
*
250+
*
252251
* @see ubic.gemma.analysis.ontology.OntologyTerm#getTerm()
253252
*/
254253
@Override
@@ -286,7 +285,7 @@ public int hashCode() {
286285

287286
/*
288287
* (non-Javadoc)
289-
*
288+
*
290289
* @see ubic.gemma.analysis.ontology.OntologyTerm#isRoot()
291290
*/
292291
@Override
@@ -296,7 +295,7 @@ public boolean isRoot() {
296295

297296
/*
298297
* (non-Javadoc)
299-
*
298+
*
300299
* @see ubic.basecode.ontology.model.OntologyTerm#isTermObsolete()
301300
*/
302301
@Override

0 commit comments

Comments
 (0)