1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ubic.basecode.ontology;
16
17 import org.apache.commons.lang3.StringUtils;
18 import org.junit.Test;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import ubic.basecode.ontology.model.OntologyTerm;
22 import ubic.basecode.ontology.providers.CellLineOntologyService;
23 import ubic.basecode.ontology.providers.DiseaseOntologyService;
24 import ubic.basecode.ontology.providers.NIFSTDOntologyService;
25
26 import java.io.InputStream;
27 import java.util.Collection;
28 import java.util.zip.GZIPInputStream;
29
30 import static java.util.Objects.requireNonNull;
31 import static org.junit.Assert.*;
32
33
34
35
36 public class OntologyTermTest extends AbstractOntologyTest {
37
38 private static final Logger log = LoggerFactory.getLogger( OntologyTermTest.class );
39
40 @Test
41 public void testGetChildren() throws Exception {
42
43 DiseaseOntologyService s = new DiseaseOntologyService();
44 InputStream is = new GZIPInputStream( requireNonNull( this.getClass().getResourceAsStream( "/data/doid.short.owl.gz" ) ) );
45 s.initialize( is, false );
46
47 assertTrue( s.getAdditionalPropertyUris().contains( "http://purl.obolibrary.org/obo/BFO_0000050" ) );
48 assertTrue( s.getAdditionalPropertyUris().contains( "http://www.obofoundry.org/ro/ro.owl#proper_part_of" ) );
49
50 OntologyTerm t = s.getTerm( "http://purl.obolibrary.org/obo/DOID_4159" );
51 assertNotNull( t );
52
53
54 assertEquals( "skin cancer", t.getLabel() );
55
56 Collection<OntologyTerm> children = t.getChildren( true );
57 assertEquals( 2, children.size() );
58 boolean found = false;
59 for ( OntologyTerm par : children ) {
60 if ( par.getUri().equals( "http://purl.obolibrary.org/obo/DOID_8923" ) ) {
61 found = true;
62 }
63 }
64 assertTrue( found );
65
66 Collection<OntologyTerm> allchildren = t.getChildren( false );
67 found = false;
68 assertEquals( 6, allchildren.size() );
69 for ( OntologyTerm chil : allchildren ) {
70 if ( chil.getUri().equals( "http://purl.obolibrary.org/obo/DOID_10054" ) ) {
71 found = true;
72 }
73
74 log.info( "Annotations: " + StringUtils.join( chil.getAnnotations(), "," ) );
75 log.info( "Comment: " + chil.getComment() );
76 log.info( "Individuals: " + StringUtils.join( chil.getIndividuals(), "," ) );
77 log.info( "Individuals: " + StringUtils.join( chil.getIndividuals( true ), "," ) );
78 log.info( "Individuals: " + StringUtils.join( chil.getIndividuals( false ), "," ) );
79 log.info( "Restrictions: " + StringUtils.join( chil.getRestrictions(), "," ) );
80 log.info( "AlternativeIDs: " + StringUtils.join( chil.getAlternativeIds(), "," ) );
81 }
82 assertTrue( found );
83 }
84
85
86
87
88 @Test
89 public void testGetChildrenHasProperPart() throws Exception {
90 NIFSTDOntologyService s = new NIFSTDOntologyService();
91 InputStream is = new GZIPInputStream( requireNonNull( this.getClass().getResourceAsStream(
92 "/data/NIF-GrossAnatomy.small.owl.xml.gz" ) ) );
93 s.initialize( is, false );
94
95 OntologyTerm t = s.getTerm( "http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-GrossAnatomy.owl#birnlex_734" );
96 assertNotNull( t );
97
98 Collection<OntologyTerm> c = t.getChildren( true );
99 assertEquals( 6, c.size() );
100
101
102
103
104
105
106
107
108
109 OntologyTerm t1 = s.getTerm( "http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-GrossAnatomy.owl#birnlex_898" );
110 assertNotNull( t1 );
111 assertTrue( c.contains( t1 ) );
112
113 Collection<OntologyTerm> c2 = t.getChildren( false );
114 assertEquals( 7, c2.size() );
115 OntologyTerm t2 = s.getTerm( "http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-GrossAnatomy.owl#birnlex_4037" );
116 assertNotNull( t2 );
117 assertTrue( c.contains( t2 ) );
118 }
119
120 @Test
121 public void testGetParents() throws Exception {
122
123 DiseaseOntologyService s = new DiseaseOntologyService();
124 InputStream is = new GZIPInputStream( requireNonNull( this.getClass().getResourceAsStream( "/data/doid.short.owl.gz" ) ) );
125
126 s.initialize( is, false );
127
128
129
130
131
132
133 OntologyTerm t = s.getTerm( "http://purl.obolibrary.org/obo/DOID_10040" );
134 assertNotNull( t );
135 Collection<OntologyTerm> parents = t.getParents( true );
136 assertEquals( 1, parents.size() );
137 OntologyTerm p = parents.iterator().next();
138 assertEquals( "http://purl.obolibrary.org/obo/DOID_8923", p.getUri() );
139
140 Collection<OntologyTerm> parents2 = t.getParents( false );
141 assertEquals( 7, parents2.size() );
142 boolean found = false;
143 for ( OntologyTerm par : parents2 ) {
144 if ( par.getUri().equals( "http://purl.obolibrary.org/obo/DOID_0060122" ) ) {
145 found = true;
146 }
147
148
149 log.info( "Annotations: " + StringUtils.join( par.getAnnotations(), "," ) );
150 log.info( "Comment: " + par.getComment() );
151 log.info( "Individuals: " + StringUtils.join( par.getIndividuals(), "," ) );
152 log.info( "Individuals: " + StringUtils.join( par.getIndividuals( true ), "," ) );
153 log.info( "Individuals: " + StringUtils.join( par.getIndividuals( false ), "," ) );
154 log.info( "Restrictions: " + StringUtils.join( par.getRestrictions(), "," ) );
155 log.info( "AlternativeIDs: " + StringUtils.join( par.getAlternativeIds(), "," ) );
156 }
157
158 assertTrue( found );
159 }
160
161 @Test
162 public void testGetParentsHasProperPart() throws Exception {
163 NIFSTDOntologyService s = new NIFSTDOntologyService();
164
165 assertFalse( s.getProcessImports() );
166
167 InputStream is = new GZIPInputStream( requireNonNull( this.getClass().getResourceAsStream(
168 "/data/NIF-GrossAnatomy.small.owl.xml.gz" ) ) );
169 assertNotNull( is );
170 s.initialize( is, false );
171
172
173 OntologyTerm t = s
174 .getTerm( "http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-GrossAnatomy.owl#birnlex_1492" );
175
176 assertNotNull( t );
177
178 Collection<OntologyTerm> parents = t.getParents( true );
179 assertEquals( 3, parents.size() );
180
181
182
183
184 boolean found = false;
185 for ( OntologyTerm p : parents ) {
186 if ( p.getUri().equals(
187 "http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-GrossAnatomy.owl#nlx_anat_101177" ) ) {
188 found = true;
189 }
190 }
191 assertTrue( found );
192
193
194
195
196
197
198
199
200
201 Collection<OntologyTerm> parents2 = t.getParents( false );
202 assertEquals( 14, parents2.size() );
203
204
205 assertTrue( parents2.contains( s.getTerm( "http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-GrossAnatomy.owl#birnlex_1503" ) ) );
206 assertFalse( parents2.contains( ( OntologyTerm ) s.getResource( "http://www.ifomis.org/bfo/1.1/snap#Continuant" ) ) );
207 }
208
209 @Test
210 public void testRejectNonEnglish() throws Exception {
211 CellLineOntologyService s = new CellLineOntologyService();
212 InputStream is = new GZIPInputStream( requireNonNull( this.getClass().getResourceAsStream( "/data/clo_merged.sample.owl.xml.gz" ) ) );
213 s.initialize( is, false );
214
215 OntologyTerm t = s.getTerm( "http://purl.obolibrary.org/obo/CLO_0000292" );
216 assertNotNull( t );
217 assertEquals( "immortal larynx-derived cell line cell", t.getLabel() );
218 }
219 }