-
Notifications
You must be signed in to change notification settings - Fork 1
/
ontology_builder.py
982 lines (837 loc) · 49.7 KB
/
ontology_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
import sys
from datetime import datetime
from namespaces import Term
from namespace_registry import NamespaceRegistry as ns
from ApiCommon import log_it, split_string, get_onto_preferred_prefix
from sparql_client import EndpointClient
from tree_functions import Tree
from databases import Database, Databases, get_db_category_IRI
from concept_term import ConceptTermData
#-------------------------------------------------
class OntologyBuilder:
#-------------------------------------------------
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def __init__(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# load info from data_in used later by describe...() functions
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
self.ctd = ConceptTermData()
self.prefixes = list()
for space in ns.namespaces: self.prefixes.append(space.getTtlPrefixDeclaration())
lines = list()
for space in ns.namespaces: lines.append(space.getSparqlPrefixDeclaration())
rqPrefixes = "\n".join(lines)
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
# store queries used to retrieve ranges and domains of properties from sparql endpoint
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
self.client = EndpointClient("http://localhost:8890/sparql")
self.domain_query_template = rqPrefixes + """
select ?prop ?value (count(distinct ?s) as ?count) where {
values ?prop { $prop }
?s ?prop ?o .
?s rdf:type ?value .
} group by ?prop ?value"""
self.range_query_template = rqPrefixes + """
select ?prop ?value (count(*) as ?count) where {
values ?prop { $prop }
?s ?prop ?o .
optional { ?o rdf:type ?cl . }
BIND(
IF (bound(?cl) , ?cl, IF ( isIRI(?o), 'rdfs:Resource', datatype(?o))
) as ?value)
} group by ?prop ?value"""
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
# domain / ranges to remove
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
self.rdfs_domain_to_remove = dict()
self.rdfs_domain_to_remove[ns.cello.accession] = { ns.skos.Concept }
#self.rdfs_domain_to_remove[ns.cello.category] = { ns.skos.Concept, ns.owl.NamedIndividual }
self.rdfs_domain_to_remove[ns.cello.database] = { ns.skos.Concept }
self.rdfs_domain_to_remove[ns.cello.hasVersion] = { ns.owl.NamedIndividual }
self.rdfs_domain_to_remove[ns.cello.shortname] = { ns.owl.NamedIndividual }
self.rdfs_domain_to_remove[ns.cello.more_specific_than] = { ns.cello.Xref }
self.rdfs_range_to_remove = dict()
self.rdfs_range_to_remove[ns.cello.hasXref] = { ns.skos.Concept }
self.rdfs_range_to_remove[ns.cello.more_specific_than] = { ns.cello.Xref }
self.rdfs_range_to_remove[ns.cello.database] = { ns.owl.NamedIndividual, ns.cello.CelloConceptScheme }
#self.rdfs_range_to_remove[ns.cello.genomeModificationMethod] = { ns.owl.NamedIndividual }
self.rdfs_range_to_remove[ns.cello.fromIndividualWithSex] = { ns.owl.NamedIndividual }
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
# add description of terms (subClasses, ...) to terms in namespaces
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
self.describe_cell_line_and_subclasses()
self.describe_genetic_characteristics_and_subclasses()
self.describe_genome_editing_method_and_subclasses()
self.describe_sequence_variation_and_subclasses()
self.describe_publication_hierarchy_based_on_fabio_no_redundancy()
self.describe_terminology_database_and_subclasses()
self.describe_cell_line_properties()
self.describe_organization_related_terms()
self.describe_misc_terms()
self.describe_ranges_and_domains()
self.describe_annotation_properties()
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def build_class_tree(self, local_only=False):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# NOW build tree with (local) child - parent relationships based on rdfs:subClassOf()
edges = dict()
relevant_namespaces = ns.namespaces
if local_only: relevant_namespaces = [ ns.cello ]
for space in relevant_namespaces:
for term_id in space.terms:
term: Term = space.terms[term_id]
if not term.isA(ns.owl.Class): continue
for parent_iri in term.props.get(ns.rdfs.subClassOf) or set():
if parent_iri.startswith(ns.cello.pfx) or not local_only:
#print("DEBUG tree", term.iri, "has parent", parent_iri)
if term.iri in edges:
log_it(f"WARNING, multiple parents for {term.iri}: parent {edges[term.iri]} replaced with {parent_iri}")
edges[term.iri] = parent_iri
self.tree = Tree(edges)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_related_terms(self, parent_class_IRI, term, termIsClass=True):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# CAUTION: for owl:equivalentProperty triples to be parsed by protege, widoco, ...
# the property appearing in the object of the triple must be declared
# in the ontology as the same property type (ObjectProperty, DatatypeProperty, ...)
# as the property appearing in the subject in the triple
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#print("parent_clss_IRI", parent_class_IRI)
for rel_key in term:
rel_prop = None
if rel_key == "EQ":
if termIsClass: rel_prop = ns.owl.equivalentClass
else: rel_prop = ns.owl.equivalentProperty
elif rel_key == "<<":
if termIsClass: rel_prop = ns.rdfs.subClassOf
else: rel_prop = ns.rdfs.subPropertyOf
elif rel_key == "BR": rel_prop = ns.skos.broadMatch
elif rel_key == "CL": rel_prop = ns.skos.closeMatch
if rel_prop is None:log_it("ERROR, unknown relation in concept_term:", term)
for el in term[rel_key]:
#print(". el:", el)
iri = self.ctd.getTermIRI(el)
#print(". iri: ", iri)
prefixed_iri = ns.getPrefixedIRI(iri)
#print(" .prefixed IRI")
if prefixed_iri is None:
ns.describe(parent_class_IRI, rel_prop, iri)
else:
el_id = prefixed_iri.split(":")[1]
# properties in wd: are already explicitly registered as Object/or/DatatypeProperty in their namespace
ns.getNamespace(iri).registerTerm(el_id)
if termIsClass: ns.describe(prefixed_iri, ns.rdf.type, ns.owl.Class) # WARNING: this might be a lie in some cases
el_lbl = self.ctd.getTermLabel(el)
ns.describe(prefixed_iri, ns.rdfs.label, ns.xsd.string(el_lbl))
ns.describe(parent_class_IRI, rel_prop, prefixed_iri)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_annotation_properties(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ns.describe(ns.cello.hasVersion, ns.rdfs.subPropertyOf, ns.dcterms.hasVersion)
ns.describe(ns.cello.modified, ns.rdfs.subPropertyOf, ns.dcterms.modified)
ns.describe(ns.cello.created, ns.rdfs.subPropertyOf, ns.dcterms.created)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_organization_related_terms(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# describing our own terms as subClass/Prop of terms defined elsewhere
# instead of simply using these external terms allow to give them a domain / range
# and additional semantic relationships to other terms
ns.describe(ns.cello.memberOf, ns.rdfs.subPropertyOf, ns.schema.memberOf)
ns.describe(ns.cello.city, ns.rdfs.subPropertyOf, ns.schema.location)
ns.describe(ns.cello.country, ns.rdfs.subPropertyOf, ns.schema.location)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_genetic_characteristics_and_subclasses(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# OBI:0001404 - genetic characteristics information
# OBI:0001364 - genetic alteration information = superclass for seq var + gen.int + gen.ko)
# OBI:0001225 - genetic population background information
ns.describe(ns.OBI._0001225, ns.rdfs.subClassOf, ns.OBI._0001404)
ns.describe(ns.OBI._0001364, ns.rdfs.subClassOf, ns.OBI._0001404)
ns.describe(ns.cello.GeneticIntegration, ns.rdfs.subClassOf, ns.OBI._0001364)
ns.describe(ns.cello.SequenceVariationComment, ns.rdfs.subClassOf, ns.OBI._0001364)
ns.describe(ns.cello.GeneKnockout, ns.rdfs.subClassOf, ns.OBI._0001364)
ns.describe(ns.cello.GenomeAncestry, ns.rdfs.subClassOf, ns.OBI._0001225)
ns.describe(ns.cello.HLATyping, ns.rdfs.subClassOf, ns.OBI._0001404)
ns.describe(ns.cello.ShortTandemRepeatProfile, ns.rdfs.subClassOf, ns.OBI._0001404)
ns.describe(ns.cello.MicrosatelliteInstability, ns.rdfs.subClassOf, ns.OBI._0001404)
ns.describe(ns.cello.KaryotypicInfoComment, ns.rdfs.subClassOf, ns.OBI._0001404)
ns.describe(ns.cello.KaryotypicInfoComment, ns.owl.equivalentClass, ns.OBI._0002769)
# obsolete, replaced with HGNC sref
# ns.describe(ns.NCIt.C101157, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C190000, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C19409, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C28585, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C29953, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C62758, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C62778, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C70614, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C71259, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C71261, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C71263, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C71265, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.NCIt.C71267, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.OGG._3000003128, ns.rdfs.subClassOf, ns.cello.HLAGene)
# ns.describe(ns.OGG._3000003132, ns.rdfs.subClassOf, ns.cello.HLAGene)
# subclass OBI:0002769 karyotype information
# ...
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_genome_editing_method_and_subclasses(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ns.describe(ns.FBcv._0003008, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.NCIt.C17262, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.NCIt.C44386, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.OBI._0001152, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.OBI._0001154, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.OBI._0002626, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.OBI._0003134, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.OBI._0003135, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.OBI._0003137, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.OBI._0600059, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.BacHomologousRecombination, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.CreLoxp, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.CrisprCas9N, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.EbvBasedVectorSirnaKnockdown, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.FloxingCreRecombination, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.GeneTargetedKoMouse, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.HelperDependentAdenoviralVector, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.HomologousRecombination, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.KnockoutFirstConditional, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.KoMouse, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.KoPig, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.MirnaKnockdown, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.NullMutation, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.PElement, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.PiggybacTransposition, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.PrimeEditing, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.PromoterlessGeneTargeting, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.RecombinantAdenoAssociatedVirus, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.ShrnaKnockdown, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.SleepingBeautyTransposition, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.SpontaneousMutation, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.TargetedIntegration, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.TransductionTransfection, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.TransfectionTransduction, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.TransgenicFish, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.TransgenicMouse, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
ns.describe(ns.cello.TransgenicRat, ns.rdfs.subClassOf, ns.OBI.GenomeModificationMethod)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_cell_line_properties(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
for celloPropIRI in self.ctd.getCelloTermKeys("CellLineProperties"):
term = self.ctd.getCelloTerm("CellLineProperties", celloPropIRI)
self.describe_related_terms(celloPropIRI, term, termIsClass=False)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_ranges_and_domains(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
self.build_class_tree()
for term_id in ns.cello.terms:
term: Term = ns.cello.terms[term_id]
if not term.isA(ns.rdf.Property): continue
# gather domain classes
log_it("DEBUG", "querying prop_name", term.iri, "domains")
domain_dic = dict()
domain_query = self.domain_query_template.replace("$prop", term.iri)
response = self.client.run_query(domain_query)
if not response.get("success"):
log_it("ERROR", response.get("error_type"))
log_it(response.get("error_msg"))
sys.exit(2)
rows = response.get("results").get("bindings")
for row in rows:
value = self.client.apply_prefixes(row.get("value").get("value"))
count = int(row.get("count").get("value"))
domain_dic[value]=count
# simplify domain
domain_set = set(domain_dic.keys())
if len(domain_set)>3:
domain_set = self.tree.get_close_parent_set(domain_set)
for domain_to_remove in self.rdfs_domain_to_remove.get(term.iri) or {}:
domain_set = domain_set - { domain_to_remove }
# gather range datatypes / classes
log_it("DEBUG", "querying prop_name", term.iri, "ranges")
range_dic = dict()
range_query = self.range_query_template.replace("$prop", term.iri)
response = self.client.run_query(range_query)
if not response.get("success"):
log_it("ERROR", response.get("error_type"))
log_it(response.get("error_msg"))
sys.exit(2)
rows = response.get("results").get("bindings")
for row in rows:
value = self.client.apply_prefixes(row.get("value").get("value"))
count = int(row.get("count").get("value"))
range_dic[value]=count
# ttl comment about domain classes found in data
domain_comments = list()
tmp = list()
for k in domain_dic: tmp.append(f"{k}({domain_dic[k]})")
for line in split_string(" ".join(tmp), 90):
domain_comments.append("# domain classes found in data: " + line)
# simplify ranges
range_set = set(range_dic.keys())
if len(range_set)>3:
range_set = self.tree.get_close_parent_set(range_set)
# hack to replace xsd:date with rdfs:Literal to be OWL2 frienly
if ns.xsd.dateDataType in range_set:
range_set = range_set - { ns.xsd.dateDataType }
range_set.add(ns.rdfs.Literal)
for range_to_remove in self.rdfs_range_to_remove.get(term.iri) or {}:
range_set = range_set - { range_to_remove }
# ttl comment about prop range
range_comments = list()
tmp = list()
for k in range_dic: tmp.append(f"{k}({range_dic[k]})")
for line in split_string(" ".join(tmp), 90):
range_comments.append("# range entities found in data: " + line)
# check prop type
prop_types = set() # we should have a single item in this set (otherwise OWL reasoners dislike it)
for r in range_dic:
if r.startswith("xsd:") or r == ns.rdfs.Literal: prop_types.add("owl:DatatypeProperty")
else: prop_types.add("owl:ObjectProperty")
if len(prop_types) != 1:
log_it("ERROR", term.iri, "has not one and only one type", prop_types)
else:
declared_types = term.props.get(ns.rdf.type) # also includes rdf:Property
found_type = prop_types.pop()
if found_type not in declared_types and ns.owl.AnnotationProperty not in declared_types:
log_it("ERROR", term.iri, f"range declaration {declared_types} does not match data {found_type}")
for domain in domain_set: ns.describe(term.iri, ns.rdfs.domain, domain)
for comment in domain_comments: ns.describe(term.iri, "domain_comments", comment)
for range in range_set: ns.describe(term.iri, ns.rdfs.range, range)
for comment in range_comments: ns.describe(term.iri, "range_comments", comment)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_publication_hierarchy_based_on_fabio_no_redundancy(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# TODO: add relationshp with dcterms.Bibliographic.... ?
# Publication hierarchy based on fabio Expression
ns.describe( ns.cello.Publication, ns.rdfs.subClassOf, ns.fabio.Expression)
ns.describe( ns.fabio.Book, ns.rdfs.subClassOf, ns.cello.Publication)
ns.describe( ns.fabio.BookChapter, ns.rdfs.subClassOf, ns.cello.Publication)
ns.describe( ns.fabio.JournalArticle, ns.rdfs.subClassOf, ns.cello.Publication)
ns.describe( ns.fabio.PatentDocument, ns.rdfs.subClassOf, ns.cello.Publication)
ns.describe( ns.fabio.ReportDocument, ns.rdfs.subClassOf, ns.cello.Publication)
ns.describe( ns.cello.TechnicalDocument, ns.rdfs.subClassOf, ns.fabio.ReportDocument)
ns.describe( ns.cello.MiscellaneousDocument, ns.rdfs.subClassOf, ns.fabio.ReportDocument)
ns.describe( ns.fabio.ConferencePaper, ns.rdfs.subClassOf, ns.cello.Publication)
ns.describe( ns.fabio.Thesis, ns.rdfs.subClassOf, ns.cello.Publication)
ns.describe( ns.fabio.BachelorsThesis, ns.rdfs.subClassOf, ns.fabio.Thesis)
ns.describe( ns.fabio.MastersThesis, ns.rdfs.subClassOf, ns.fabio.Thesis)
ns.describe( ns.fabio.DoctoralThesis, ns.rdfs.subClassOf, ns.fabio.Thesis)
ns.describe( ns.cello.MedicalDegreeThesis, ns.rdfs.subClassOf, ns.fabio.Thesis)
ns.describe( ns.cello.MedicalDegreeMasterThesis, ns.rdfs.subClassOf, ns.fabio.Thesis)
ns.describe( ns.cello.PrivaDocentThesis, ns.rdfs.subClassOf, ns.fabio.Thesis)
ns.describe( ns.cello.VeterinaryMedicalDegreeThesis, ns.rdfs.subClassOf, ns.fabio.Thesis)
# Relationships with UniProt
ns.describe( ns.cello.Publication, ns.skos.closeMatch, ns.up.Published_Citation)
ns.describe( ns.fabio.BookChapter, ns.skos.closeMatch, ns.up.Book_Citation) # book citation is for book chapter !
ns.describe( ns.fabio.JournalArticle, ns.skos.closeMatch, ns.up.Journal_Citation )
ns.describe( ns.fabio.PatentDocument, ns.skos.closeMatch, ns.up.Patent_Citation)
ns.describe( ns.fabio.Thesis, ns.skos.closeMatch, ns.up.Thesis_Citation)
ns.describe( ns.fabio.BachelorsThesis, ns.skos.broadMatch, ns.up.Thesis_Citation)
ns.describe( ns.fabio.MastersThesis, ns.skos.broadMatch, ns.up.Thesis_Citation)
ns.describe( ns.fabio.DoctoralThesis, ns.skos.broadMatch, ns.up.Thesis_Citation)
ns.describe( ns.cello.MedicalDegreeThesis, ns.skos.broadMatch, ns.up.Thesis_Citation)
ns.describe( ns.cello.MedicalDegreeMasterThesis, ns.skos.broadMatch, ns.up.Thesis_Citation)
ns.describe( ns.cello.PrivaDocentThesis, ns.skos.broadMatch, ns.up.Thesis_Citation)
ns.describe( ns.cello.VeterinaryMedicalDegreeThesis, ns.skos.broadMatch, ns.up.Thesis_Citation)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_misc_terms(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# for tk in self.ctd.getCelloTermKeys("MiscClasses"):
# term_data = self.ctd.getCelloTerm("MiscClasses", tk)
# self.describe_related_terms(tk, term_data, termIsClass=True)
# - - - - - - - -
# misc classes
# - - - - - - - -
# describe our disease class as a superclass of ncit disorder and ordo clinical entities
ns.describe(ns.NCIt.C2991_Disease, ns.rdfs.subClassOf, ns.cello.Disease)
ns.describe(ns.ORDO.C001_Clinical_Entity, ns.rdfs.subClassOf, ns.cello.Disease)
ns.describe(ns.cello.Breed, ns.owl.equivalentClass, ns.NCIt.C53692_Breed)
ns.describe(ns.cello.Species, ns.rdfs.subClassOf, ns.NCIt.C40098_Taxon)
ns.describe(ns.cello.Population, ns.rdfs.subClassOf, ns.OBI._0000181)
ns.describe(ns.cello.Gene, ns.owl.equivalentClass, ns.NCIt.C16612)
ns.describe(ns.cello.HLAGene, ns.rdfs.subClassOf, ns.cello.Gene)
ns.describe(ns.cello.HLA_Allele, ns.rdfs.subClassOf, ns.GENO._0000512_Allele)
ns.describe(ns.cello.Locus, ns.owl.equivalentClass, ns.NCIt.C45822)
ns.describe(ns.cello.STR_Allele, ns.rdfs.subClassOf, ns.GENO._0000512_Allele)
ns.describe(ns.cello.Marker, ns.rdfs.subClassOf, ns.NCIt.C13441_ShortTandemRepeat)
ns.describe(ns.cello.Marker, ns.rdfs.subClassOf, ns.cello.Locus)
ns.describe(ns.CHEBI.Protein, ns.rdfs.subClassOf, ns.CHEBI.ChemicalEntity)
ns.describe(ns.CHEBI.Protein, ns.skos.closeMatch, ns.up.Protein)
ns.describe(ns.NCIt.C16717_IGH, ns.rdfs.subClassOf, ns.CHEBI.Protein)
ns.describe(ns.NCIt.C16720_IGL, ns.rdfs.subClassOf, ns.CHEBI.Protein)
# - - - - - - - -
# misc properties
# - - - - - - - -
# ns.describe(ns.cello.hasAllele, ns.rdfs.subPropertyOf, ns.GENO._0000413_has_allele) # unused
# ns.describe(ns.cello.isAlleleOf, ns.rdfs.subPropertyOf, ns.GENO._0000408_is_allele_of) # unused
ns.describe(ns.cello.hasTarget, ns.rdfs.subPropertyOf, ns.schema.observationAbout)
ns.describe(ns.cello.hasSource, ns.rdfs.subPropertyOf, ns.dcterms.source)
ns.describe(ns.cello.appearsIn, ns.rdfs.subPropertyOf, ns.dcterms.source)
ns.describe(ns.cello.references, ns.rdfs.subPropertyOf, ns.dcterms.references)
ns.describe(ns.cello.hasXref, ns.rdfs.subPropertyOf, ns.dcterms.references)
ns.describe(ns.cello.hasAnnotation, ns.owl.inverseOf, ns.IAO.is_about_0000136)
ns.describe(ns.cello.hasInternalId, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.cello.issn13, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.prism.hasDOI, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.fabio.hasPubMedCentralId, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.fabio.hasPubMedId, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.cello.hasISO4JournalTitleAbbreviation, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.prism.volume, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.cello.markerId, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.cello.alleleIdentifier, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.cello.accession, ns.rdfs.subPropertyOf, ns.dcterms.identifier)
ns.describe(ns.cello.primaryAccession, ns.rdfs.subPropertyOf, ns.cello.accession)
ns.describe(ns.cello.primaryAccession, ns.owl.equivalentProperty, ns.wd.P3289_AC)
ns.describe(ns.cello.secondaryAccession, ns.rdfs.subPropertyOf, ns.cello.accession)
ns.describe(ns.cello.name, ns.owl.equivalentProperty, ns.rdfs.label)
ns.describe(ns.cello.shortname, ns.rdfs.subPropertyOf, ns.cello.name)
ns.describe(ns.cello.registeredName, ns.rdfs.subPropertyOf, ns.cello.name)
ns.describe(ns.skos.prefLabel, ns.rdfs.subPropertyOf, ns.cello.name)
ns.describe(ns.skos.altLabel, ns.rdfs.subPropertyOf, ns.cello.name)
ns.describe(ns.skos.hiddenLabel, ns.rdfs.subPropertyOf, ns.cello.name)
ns.describe(ns.cello.recommendedName, ns.rdfs.subPropertyOf, ns.skos.prefLabel)
ns.describe(ns.cello.alternativeName, ns.rdfs.subPropertyOf, ns.skos.altLabel)
ns.describe(ns.cello.misspellingName, ns.rdfs.subPropertyOf, ns.skos.hiddenLabel)
ns.describe(ns.cello.hgvs, ns.rdfs.subPropertyOf, ns.skos.notation)
ns.describe(ns.cello.includesObservation, ns.rdfs.subPropertyOf, ns.BFO._0000051_has_part)
ns.describe(ns.cello.hasComponent, ns.rdfs.subPropertyOf, ns.BFO._0000051_has_part)
ns.describe(ns.cello.zygosity, ns.rdfs.subPropertyOf, ns.GENO._0000608_has_zygozity)
ns.describe(ns.cello.inGroup, ns.rdfs.subPropertyOf, ns.schema.category)
ns.describe(ns.cello.belongsTo, ns.rdfs.subPropertyOf, ns.schema.category)
ns.describe(ns.cello.establishedBy, ns.rdfs.subPropertyOf, ns.dcterms.source)
ns.describe(ns.cello.isDerivedFromCellType, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.isDerivedFromSite, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasGenomeAncestry, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasHLAtyping, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.comesFomIndividualBelongingToBreed, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasSequenceVariationComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasAnecdotalComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasCautionComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasCharacteristicsComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasBiotechnologyComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasDonorInfoComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasDoublingTimeComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasKaryotypicInfoComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasMiscellaneousInfoComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasMisspellingRecord, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasSenescenceComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasVirologyComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.hasOmicsComment, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
ns.describe(ns.cello.comesFromIndividualBelongingToPopulation, ns.rdfs.subPropertyOf, ns.cello.hasAnnotation)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_terminology_database_and_subclasses(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Describe root cellosaurus terminology class
ns.describe(ns.cello.CelloConceptScheme, ns.rdfs.subClassOf, ns.skos.ConceptScheme)
# Describe parent class of our Database class and equivalence to uniprot Database
ns.describe(ns.cello.Database, ns.rdfs.subClassOf, ns.NCIt.C15426_Database)
ns.describe(ns.cello.Database, ns.owl.equivalentClass, ns.up.Database)
ns.describe(ns.cello.Xref, ns.rdfs.subClassOf, ns.NCIt.C43621_Xref)
# we add programmaticaly the subClassOf relationships between Database and its children
# so that we can take advantage of close_parent_set() method during computation of domain / ranges of related properties
databases = Databases()
for k in databases.categories():
cat = databases.categories()[k]
cat_label = cat["label"]
cat_IRI = get_db_category_IRI(cat_label)
cat_id = cat_IRI.split(":")[1]
ns.cello.registerClass(cat_id)
ns.describe(cat_IRI, ns.rdfs.subClassOf, ns.cello.Database)
ns.describe(cat_IRI, ns.rdfs.label, ns.xsd.string(cat_label))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_sequence_variation_and_subclasses(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# describe children of SequenceVariation class
ns.describe( ns.NCIt.GeneMutation, ns.rdfs.subClassOf, ns.NCIt.SequenceVariation )
ns.describe( ns.NCIt.GeneFusion, ns.rdfs.subClassOf, ns.NCIt.SequenceVariation )
ns.describe( ns.NCIt.GeneAmplification, ns.rdfs.subClassOf, ns.NCIt.SequenceVariation )
ns.describe( ns.NCIt.GeneDeletion, ns.rdfs.subClassOf, ns.NCIt.SequenceVariation )
ns.describe( ns.cello.RepeatExpansion, ns.rdfs.subClassOf, ns.NCIt.GeneMutation )
#ns.describe( ns.cello.SimpleMutation, ns.rdfs.subClassOf, ns.NCIt.GeneMutation ) # SimpleMutation is not used
#ns.describe( ns.cello.UnexplicitMutation, ns.rdfs.subClassOf, ns.cello.GeneMutation ) # SimpleMutation is not used
ns.describe( ns.cello.GeneDuplication, ns.rdfs.subClassOf, ns.NCIt.GeneAmplification )
ns.describe( ns.cello.GeneTriplication, ns.rdfs.subClassOf, ns.NCIt.GeneAmplification )
ns.describe( ns.cello.GeneQuadruplication, ns.rdfs.subClassOf, ns.NCIt.GeneAmplification )
ns.describe( ns.cello.GeneExtensiveAmplification, ns.rdfs.subClassOf, ns.NCIt.GeneAmplification )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def describe_cell_line_and_subclasses(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# generate rdfs:subClass links between wd.CellLine and others
for id in ns.wd.terms:
term = ns.wd.terms[id]
if "owl:Class" in term.props["rdf:type"]:
if term.iri != ns.wd.CellLine:
ns.describe(term.iri, ns.rdfs.subClassOf, ns.wd.CellLine)
# describe how CellLine classes relate in the universe
ns.describe(ns.wd.CellLine, ns.skos.closeMatch, "<http://purl.obolibrary.org/obo/CLO_0000031>")
ns.describe(ns.wd.CellLine, ns.skos.closeMatch, "<http://id.nlm.nih.gov/mesh/D002460>")
ns.describe(ns.wd.CellLine, ns.rdfs.seeAlso, "<https://www.cellosaurus.org/>")
ns.describe(ns.wd.Q23058136, ns.skos.closeMatch, f"<{ns.OBI.url}0001906>" )
ns.describe(ns.wd.Q107102664, ns.skos.closeMatch, f"<{ns.BTO.url}0001581>" )
ns.describe(ns.wd.Q107102664, ns.skos.closeMatch, f"<{ns.CLO.url}0037279>" )
ns.describe(ns.wd.Q27671617, ns.skos.closeMatch, f"<{ns.CLO.url}0009829>" )
ns.describe(ns.wd.Q27554370, ns.skos.closeMatch, f"<{ns.BTO.url}0001926>" )
ns.describe(ns.wd.Q27554370, ns.skos.closeMatch, f"<{ns.CLO.url}0036932>" )
ns.describe(ns.wd.Q107103143, ns.skos.closeMatch, f"<{ns.CLO.url}0037307>" )
ns.describe(ns.wd.Q27671698, ns.skos.closeMatch, f"<{ns.BTO.url}0005996>" )
ns.describe(ns.wd.Q27555384, ns.skos.closeMatch, f"<{ns.OMIT.url}0003790>" )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_onto_header(self, version="alpha"):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lines = list()
# set last modification date for ontology
now = datetime.now()
date_string = now.strftime("%Y-%m-%d")
# set ontology URL
onto_url = "<" + self.get_onto_url() + ">"
# set ontology description
onto_descr = """The Cellosaurus ontology describes the concepts used to build the Cellosaurus knowledge resource on cell lines.
The Cellosaurus attempts to describe all cell lines used in biomedical research."""
# set ontology abstract
onto_abstract = onto_descr
# set preferred prefix for ontology
onto_prefix = "cls"
# set ontology introduction
onto_intro = onto_descr
# Note: all the prefixes are declared in namespace.py but not necessarily all the properties because used only once...
lines.append(onto_url)
lines.append(" a " + ns.owl.Ontology + " ;")
lines.append(" " + ns.rdfs.label + " " + ns.xsd.string("Cellosaurus ontology") + " ;")
lines.append(" " + ns.dcterms.created + " " + ns.xsd.date("2024-07-30") + " ;")
lines.append(" " + ns.dcterms.modified + " " + ns.xsd.date(date_string) + " ;")
lines.append(" " + ns.dcterms.description + " " + ns.xsd.string3(onto_descr) + " ;")
lines.append(" " + ns.dcterms.license + " <http://creativecommons.org/licenses/by/4.0> ;")
lines.append(" " + ns.dcterms.title + " " + ns.xsd.string("Cellosaurus ontology") + " ;")
lines.append(" " + ns.dcterms.hasVersion + " " + ns.xsd.string(version) + " ;")
lines.append(" " + ns.owl.versionInfo + " " + ns.xsd.string(version) + " ;")
lines.append(" " + ns.dcterms.abstract + " " + ns.xsd.string3(onto_abstract) + " ;")
lines.append(" " + ns.vann.preferredNamespacePrefix + " " + ns.xsd.string(get_onto_preferred_prefix()) + " ;")
lines.append(" " + ns.bibo.status + " <http://purl.org/ontology/bibo/status/published> ;")
lines.append(" " + ns.widoco.introduction + " " + ns.xsd.string3(onto_intro) + " ;")
lines.append(" " + ns.rdfs.seeAlso + " " + ns.help.IRI("index-en.html") + " ;")
lines.append(" " + ns.widoco.rdfxmlSerialization + " " + ns.help.IRI("ontology.owl") + " ;")
lines.append(" " + ns.widoco.ntSerialization + " " + ns.help.IRI("ontology.nt") + " ;")
lines.append(" " + ns.widoco.turtleSerialization + " " + ns.help.IRI("ontology.ttl") + " ;")
lines.append(" " + ns.widoco.jsonldSerialization + " " + ns.help.IRI("ontology.jsonld") + " ;")
# shacl declaration of prefixes for void tools
for elem in ns.namespaces:
lines.append(" " + ns.sh.declare + " [ ")
pfx = elem.pfx
if pfx == "": pfx = "cello"
lines.append(" " + ns.sh._prefix + " " + ns.xsd.string(pfx) + " ;")
lines.append(" " + ns.sh.namespace + " " + ns.xsd.string(elem.url) + " ;")
lines.append(" ] ;")
lines.append(" .")
lines.extend(self.get_query_examples())
lines.append("")
return lines
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_topic_comments(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
text = """
# Topic individuals
cello:Biotechnology a owl:NamedIndividual, NCIt:C16351 ;
rdfs:label "Biotechnology"^^xsd:string ;
rdfs:comment "The field devoted to applying the techniques of biochemistry, cellular biology, biophysics, and molecular biology to addressing issues related to human beings and the environment."^^xsd:string ;
.
cello:Senescence a owl:NamedIndividual, NCIt:C17467 ;
rdfs:label "Senescence"^^xsd:string ;
rdfs:comment "PDL stands for Population Doubling Level. The process of growing old and showing the effects of time."^^xsd:string ;
.
cello:DoublingTime a owl:NamedIndividual, NCIt:C94346 ;
rdfs:label "Doubling time"^^xsd:string ;
rdfs:comment "In biology, the amount of time it takes for one cell to divide or for a group of cells (such as a tumor) to double in size. The doubling time is different for different kinds of cancer cells or tumors."^^xsd:string ;
.
cello:Virology a owl:NamedIndividual, NCIt:C17256 ;
rdfs:label "Virology"^^xsd:string ;
rdfs:comment "The science that deals with the study of viruses."^^xsd:string ;
.
cello:Omics a owl:NamedIndividual, NCIt:C205365 ;
rdfs:label "Omics"^^xsd:string ;
rdfs:comment "The fields of research that use large scale sets of bioinformatics data to identify, describe and quantify the entire set of molecules and molecular processes that contribute to the form and function of cells, tissues and organisms."^^xsd:string ;
.
cello:GeneralTopic a owl:Class ;
rdfs:label "General topic" ;
rdfs:subClassOf EDAM:topic_0003 ;
.
cello:Characteristics a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "Characteristics"^^xsd:string ;
rdfs:comment "Production process or specific biological properties of the cell line"^^xsd:string ;
.
cello:Discontinuation a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "Discontinuation"^^xsd:string ;
rdfs:comment "Discontinuation status of the cell line in a cell line catalog."^^xsd:string ;
.
cello:Miscellaneous a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "Miscellaneous"^^xsd:string ;
rdfs:comment "Miscellaneous remarks about the cell line."^^xsd:string ;
.
cello:Caution a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "Caution"^^xsd:string ;
rdfs:comment "Errors, inconsistencies, ambiguities regarding the origin or other aspects of the cell line."^^xsd:string ;
.
cello:Anecdotal a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "Anecdotal"^^xsd:string ;
rdfs:comment "Anecdotal details regarding the cell line (its origin, its name or any other particularity)."^^xsd:string ;
.
cello:Misspelling a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "Misspelling"^^xsd:string ;
rdfs:comment "Identified misspelling(s) of the cell line name with in some case the specific publication or external resource entry where it appears."^^xsd:string ;
.
cello:DonorInfo a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "DonorInfo"^^xsd:string ;
rdfs:comment "Miscellaneous information relevant to the donor of the cell line."^^xsd:string ;
.
cello:Registration a owl:NamedIndividual, cello:GeneralTopic ;
rdfs:label "Registration"^^xsd:string ;
rdfs:comment "Register or official list in which the cell line is registered."^^xsd:string ;
.
# Define some of these external terms as Topic subclasses
cello:CellLineAnnotationTopic a owl:Class ;
rdfs:label "Cell line annotation topic"^^xsd:string ;
rdfs:subClassOf EDAM:topic_0003 ;
owl:equivalentClass [
owl:intersectionOf (
EDAM:topic_0003
[
rdf:type owl:Class ;
owl:oneOf (cello:Biotechnology cello:Senescence cello:DoublingTime cello:Virology cello:Omics cello:Characteristics
cello:Miscellaneous cello:Caution cello:Anecdotal cello:DonorInfo cello:Misspelling cello:Discontinuation cello:Registration) ;
]
)
]
.
# Define a topic data item
cello:VirologyComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Virology ;
]
)
] .
cello:BiotechnologyComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Biotechnology ;
]
)
] .
cello:SenescenceComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Senescence ;
]
)
] .
cello:DoublingTimeComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:DoublingTime ;
]
)
] .
cello:OmicsComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Omics ;
]
)
] .
cello:CharacteristicsComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Characteristics ;
]
)
] .
cello:DiscontinuationRecord a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Discontinuation ;
]
)
] .
cello:MiscellaneousComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Miscellaneous ;
]
)
] .
cello:CautionComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Caution ;
]
)
] .
cello:AnecdotalComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Anecdotal ;
]
)
] .
cello:MisspellingRecord a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Misspelling ;
]
)
] .
cello:DonorInfoComment a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:DonorInfo ;
]
)
] .
cello:RegistrationRecord a owl:Class ;
rdfs:subClassOf IAO:0000027 ;
owl:equivalentClass [
owl:intersectionOf (
IAO:0000027
[ rdf:type owl:Restriction ;
owl:onProperty EDAM:has_topic ;
owl:hasValue cello:Registration ;
]
)
] .
"""
return text.split("\n")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_query_examples(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lines = list()
px = get_onto_preferred_prefix()
lines.append("")
lines.append(px + ":Query_001 a sh:SPARQLExecutable ;")
lines.append(""" rdfs:comment "Count of cell lines" ; """)
lines.append(""" sh:select "select (count(*) as ?cnt) where { ?cl rdf:type / rdfs:subClassOf cello:CellLine . }" ; """)
lines.append(" .")
lines.append("")
lines.append(px +":Query_002 a sh:SPARQLExecutable ;")
lines.append(""" rdfs:comment "Count of publication citations" ; """)
lines.append(""" sh:select "select (count(*) as ?cnt) where { ?cl rdf:type / rdfs:subClassOf cello:Publication . }" ; """)
lines.append(" .")
lines.append("")
return lines
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_onto_url(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
onto_url = ns.cello.url
if onto_url.endswith("#"): onto_url = onto_url[:-1]
return onto_url
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_onto_prefixes(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return self.prefixes
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_imported_terms(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lines = list()
allButCello = list(ns.namespaces)
# remove basic ones
allButCello.remove(ns.xsd)
allButCello.remove(ns.rdf)
allButCello.remove(ns.rdfs)
allButCello.remove(ns.owl)
allButCello.remove(ns.sh)
allButCello.remove(ns.widoco)
#allButCello.remove(ns.dcterms) # only some terms are hidden for the moment
# remove namespaces for our data
allButCello.remove(ns.cello)
allButCello.remove(ns.cvcl)
allButCello.remove(ns.db)
allButCello.remove(ns.orga)
allButCello.remove(ns.xref)
# remove irrelevant ones
allButCello.remove(ns.pubmed)
for nspace in allButCello: lines.extend(self.get_terms(nspace))
return lines
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_terms(self, nspace, owlType=None):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lines = list()
for id in nspace.terms:
term: Term = nspace.terms[id]
if owlType is None or term.isA(owlType): lines.extend(term.ttl_lines())
return lines
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_onto_terms(self, owlType=None):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return self.get_terms(ns.cello, owlType)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_onto_pretty_ttl_lines(self, version):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lines = list()
lines.extend(self.get_onto_prefixes())
lines.append("\n#\n# Ontology properties\n#\n")
lines.extend(self.get_onto_header(version))
lines.append("#\n# External terms used in ontology\n#\n")
lines.extend(self.get_imported_terms())
lines.append("#\n# Classes defined in ontology\n#\n")
lines.extend(self.get_onto_terms(ns.owl.Class))
lines.append("#\n# Annotation Properties used in ontology\n#\n")
lines.extend(self.get_onto_terms(ns.owl.AnnotationProperty))
lines.append("#\n# Object Properties used in ontology\n#\n")
lines.extend(self.get_onto_terms(ns.owl.ObjectProperty))
lines.append("#\n# Datatype Properties used in ontology\n#\n")
lines.extend(self.get_onto_terms(ns.owl.DatatypeProperty))
lines.extend(self.get_topic_comments())
return lines
# =============================================
if __name__ == '__main__':
# =============================================
ob = OntologyBuilder()
lines = ob.get_onto_pretty_ttl_lines("dev version")
for l in lines: print(l)