-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrdf_builder.py
1738 lines (1514 loc) · 85.6 KB
/
rdf_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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import uuid
import unicodedata
from namespace_registry import NamespaceRegistry as ns
from ApiCommon import log_it, split_string
from organizations import Organization
from terminologies import Term, Terminologies, Terminology
from databases import Database, Databases, get_db_category_IRI
from sexes import Sexes, Sex, get_sex_IRI
from namespace_term import Term as NsTerm
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class DataError(Exception):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pass
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class TripleList:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def __init__(self):
self.lines = list()
def append(self, s, p, o, punctuation="."):
line = " ".join([s,p,o, punctuation, "\n"])
self.lines.append(line)
def extend(self, triple_list):
self.lines.extend(triple_list.lines)
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
class RdfBuilder:
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def __init__(self, known_orgs):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
self.known_orgs = known_orgs
self.mmm2mm = {
"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06",
"Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12"}
# publication type label => publication class
self.pubtype_clazz = {
"article": ns.fabio.JournalArticle,
"book chapter": ns.fabio.BookChapter,
"patent": ns.fabio.PatentDocument,
"thesis BSc": ns.fabio.BachelorsThesis,
"thesis MSc": ns.fabio.MastersThesis,
"thesis PhD": ns.fabio.DoctoralThesis,
"book": ns.fabio.Book,
"conference": ns.fabio.ConferencePaper,
"thesis MDSc": ns.cello.MedicalDegreeMasterThesis,
"thesis MD": ns.cello.MedicalDegreeThesis,
"thesis PD": ns.cello.PrivaDocentThesis,
"thesis VMD": ns.cello.VeterinaryMedicalDegreeThesis,
"technical document": ns.cello.TechnicalDocument,
"miscellaneous document": ns.cello.MiscellaneousDocument,
}
self.hla_hgnc_ac = {
"HLA-DRA": "4947",
"HLA-DRB2": "4950",
"HLA-DRB1": "4948",
"HLA-A": "4931",
"HLA-DPB1": "4940",
"HLA-C": "4933",
"HLA-B": "4932",
"HLA-DQB1": "4944",
"HLA-DRB3": "4951",
"HLA-DRB4": "4952",
"HLA-DRB5": "4953",
"HLA-DQA1": "4942",
"HLA-DPA1": "4938",
"HLA-DRB6": "4954",
"HLA-DRB9": "4957",
}
# genome editing method labels => class
# labels MUST be those found in cellosaurus data
self.gem_ni = {
"Not specified": ns.cello.GenomeModificationMethodNOS,
"CRISPR/Cas9": ns.cello.CrispCas9,
"X-ray": ns.cello.XRay,
"Gamma radiation": ns.cello.GammaRadiation,
"Transfection": ns.cello.Transfection,
"Mutagenesis": ns.cello.Mutagenesis,
"siRNA knockdown": ns.cello.SiRNAKnockdown,
"TALEN": ns.cello.TALEN,
"ZFN": ns.cello.ZFN,
"Gene trap": ns.cello.GeneTrap,
"Transduction": ns.cello.Transduction,
"BAC homologous recombination": ns.cello.BacHomologousRecombination,
"Cre/loxP": ns.cello.CreLoxp,
"CRISPR/Cas9n": ns.cello.CrisprCas9N,
"EBV-based vector siRNA knockdown": ns.cello.EbvBasedVectorSirnaKnockdown,
"Floxing/Cre recombination": ns.cello.FloxingCreRecombination,
"Gene-targeted KO mouse": ns.cello.GeneTargetedKoMouse,
"Helper-dependent adenoviral vector": ns.cello.HelperDependentAdenoviralVector,
"Homologous recombination": ns.cello.HomologousRecombination,
"Knockout-first conditional": ns.cello.KnockoutFirstConditional,
"KO mouse": ns.cello.KoMouse,
"KO pig": ns.cello.KoPig,
"miRNA knockdown": ns.cello.MirnaKnockdown,
"Null mutation": ns.cello.NullMutation,
"P-element": ns.cello.PElement,
"PiggyBac transposition": ns.cello.PiggybacTransposition,
"Prime editing": ns.cello.PrimeEditing,
"Promoterless gene targeting": ns.cello.PromoterlessGeneTargeting,
"Recombinant Adeno-Associated Virus": ns.cello.RecombinantAdenoAssociatedVirus,
"shRNA knockdown": ns.cello.ShrnaKnockdown,
"Sleeping Beauty transposition": ns.cello.SleepingBeautyTransposition,
"Spontaneous mutation": ns.cello.SpontaneousMutation,
"Targeted integration": ns.cello.TargetedIntegration,
"Transduction/transfection": ns.cello.TransductionTransfection,
"Transfection/transduction": ns.cello.TransfectionTransduction,
"Transgenic fish": ns.cello.TransgenicFish,
"Transgenic mouse": ns.cello.TransgenicMouse,
"Transgenic rat": ns.cello.TransgenicRat,
}
# cell line labels => class
# labels MUST be those found in cellosaurus data
self.clcat_clazz = {
"Cancer cell line": ns.cello.CancerCellLine,
"Conditionally immortalized cell line": ns.cello.ConditionallyImmortalizedCellLine,
"Embryonic stem cell": ns.cello.EmbryonicStemCell,
"Factor-dependent cell line": ns.cello.FactorDependentCellLine,
"Finite cell line": ns.cello.FiniteCellLine,
"Hybrid cell line": ns.cello.HybridCellLine,
"Hybridoma": ns.cello.Hybridoma,
"Induced pluripotent stem cell": ns.cello.InducedPluripotentStemCell,
"Somatic stem cell": ns.cello.SomaticStemCell,
"Spontaneously immortalized cell line": ns.cello.SpontaneouslyImmortalizedCellLine,
"Stromal cell line": ns.cello.StromalCellLine,
"Telomerase immortalized cell line": ns.cello.TelomeraseImmortalizedCellLine,
"Transformed cell line": ns.cello.TransformedCellLine,
"Cell line": ns.cello.CellLine,
"Undefined cell line type": ns.cello.CellLine # generic cell line (in data)
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_blank_node(self):
# -- - - - - - - - - - - - - - - - - - - - - - - - - - -
return "_:BN" + uuid.uuid4().hex
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_prefixes(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lines = list()
for item in ns.namespaces:
lines.append(item.getTtlPrefixDeclaration())
return "\n".join(lines) + "\n"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_sparql_prefixes(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lines = list()
for item in ns.namespaces:
lines.append(item.getSparqlPrefixDeclaration())
return "\n".join(lines) + "\n"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_pub_IRI(self, refOrPub):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dbac = refOrPub.get("resource-internal-ref") # exists in reference-list items
if dbac is None: dbac = refOrPub["internal-id"] # exists in publication-list items
(db,ac) = dbac.split("=")
return ns.pub.IRI(db,ac)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_xref_discontinued(self, xref):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return xref.get("discontinued")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_xref_label(self, xref):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return xref.get("label")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_xref_url(self, xref):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return xref.get("url")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_xref_db(self, xref):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return xref.get("database")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_xref_term_IRI(self, xref):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return xref.get("iri")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_xref_IRI(self, xref):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# get mandatory fields
ac = xref["accession"]
db = xref["database"]
# get optional fields attached to the xref
cat = xref.get("category") or ""
lbl = xref.get("label") or ""
url = xref.get("url") or ""
dis = xref.get("discontinued") or ""
props = f"cat={cat}|lbl={lbl}|dis={dis}|url={url}"
#if props is not None: print("DEBUG props:", props)
return ns.xref.IRI(db,ac, props)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_amelogenin_gene_xref_IRI(self, chr):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ac = "461" if chr == "X" else "462"
db = "HGNC"
cat = "Organism-specific databases"
lbl = "AMEL" + chr
url = f"https://www.genenames.org/data/gene-symbol-report/#!/hgnc_id/HGNC:{ac}"
dis = ""
props = f"cat={cat}|lbl={lbl}|dis={dis}|url={url}"
return ns.xref.IRI(db,ac, props)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_hla_gene_xref_IRI(self, our_label):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ac = self.hla_hgnc_ac.get(our_label)
if ac is None:
log_it("ERROR", f"unexpected HLA Gene label '{our_label}'")
ac = ns.cello.HLAGene # default, most generic
db = "HGNC"
cat = "Organism-specific databases"
url = f"https://www.genenames.org/data/gene-symbol-report/#!/hgnc_id/HGNC:{ac}"
dis = ""
lbl = our_label
props = f"cat={cat}|lbl={lbl}|dis={dis}|url={url}"
return ns.xref.IRI(db,ac, props)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_materialized_triples_for_prop(self, parent_node, prop, xsd_label, no_rdfs_label=False):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Helper function for the materialization of triples entailed by triple in function params
# Note: the function handles rdfs:label sub props and skos:notation sub props
# TODO - to be decided / or as an option in another graph...
# Could be extended to handle dcterms:identifier and dcterms:title sub props or fully
# generalized so that all entailed triples related to the usage a prop
# having super props be generated.
# Some mechanism could be used to generate triples instance rdf_type superclass(es) triples
# The triples could be generated from here of later in the process with a simple SPARQL construct...
# this dictionary decides which properties are generated according to the prop chosen
materialization_rule = {
ns.rdfs.label : { ns.rdfs.label },
ns.cello.name : { ns.rdfs.label, ns.cello.name },
ns.skos.prefLabel : { ns.rdfs.label, ns.cello.name, ns.skos.prefLabel },
ns.skos.altLabel : { ns.rdfs.label, ns.cello.name, ns.skos.altLabel },
ns.skos.hiddenLabel : { ns.rdfs.label, ns.cello.name, ns.skos.hiddenLabel },
ns.cello.registeredName : { ns.rdfs.label, ns.cello.name, ns.cello.registeredName },
ns.cello.recommendedName : { ns.rdfs.label, ns.cello.name, ns.skos.prefLabel, ns.cello.recommendedName },
ns.cello.alternativeName : { ns.rdfs.label, ns.cello.name, ns.skos.altLabel, ns.cello.alternativeName },
ns.cello.misspellingName : { ns.rdfs.label, ns.cello.name, ns.skos.hiddenLabel, ns.cello.misspellingName },
ns.skos.notation : { ns.skos.notation },
ns.cello.hgvs : { ns.skos.notation, ns.cello.hgvs }
}
triples = TripleList()
for p in materialization_rule[prop]:
if no_rdfs_label == True and p == ns.rdfs.label: continue # skip generation of triple with rdfs:label
triples.append(parent_node, p, xsd_label)
if len(triples.lines)==0: print(f"ERROR, generated no triples for prop: {prop} and xsd_label: {xsd_label}")
return triples
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_triples_for_amelogenin_gene_instance(self, gene_BN, chr):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
triples = TripleList()
triples.append(gene_BN, ns.rdf.type, ns.cello.Gene)
triples.extend(self.get_materialized_triples_for_prop(gene_BN, ns.cello.name, ns.xsd.string(f"AMEL{chr}")))
xref_IRI = self.get_amelogenin_gene_xref_IRI(chr)
triples.append(gene_BN, ns.cello.isIdentifiedByXref, xref_IRI)
return triples
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_triples_for_hla_gene_instance(self, gene_BN, label):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
triples = TripleList()
triples.append(gene_BN, ns.rdf.type, ns.cello.HLAGene)
triples.extend(self.get_materialized_triples_for_prop(gene_BN, ns.cello.name, ns.xsd.string(label)))
xref_IRI = self.get_hla_gene_xref_IRI(label)
triples.append(gene_BN, ns.cello.isIdentifiedByXref, xref_IRI)
return triples
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_local_gem_class(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
localClass = ns.cello.GenomeModificationMethod
obigemClass = ns.OBI.GeneticTransformation # parent class
members = list()
for k in self.gem_ni: members.append(self.gem_ni[k])
members_str = " ".join(members)
member_lines = "\n ".join(split_string(members_str, 90))
text = f"""
# Define genome modification method class as a list of members (owl:oneOf)
{localClass} a owl:Class ;
rdfs:label "Genome modification method"^^xsd:string ;
rdfs:subClassOf {obigemClass} ;
owl:oneOf (
{member_lines}
) .
"""
return text.split("\n")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_gem_individual(self, ni_term: NsTerm):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
triples = TripleList()
for clazz in ni_term.props.get("rdf:type"):
triples.append(ni_term.iri, ns.rdf.type, clazz)
label = ni_term.get_label_str()
xsd_label = ns.xsd.string(label)
triples.extend(self.get_materialized_triples_for_prop(ni_term.iri, ns.cello.name, xsd_label))
comment_set = ni_term.props.get("rdfs:comment")
if comment_set is not None and len(comment_set)>0:
xsd_comment = next(iter(comment_set))
triples.append(ni_term, "rdfs:comment", xsd_comment)
url = ns.cello.url
if url.endswith("#"): url = url[:-1]
triples.append(ni_term.iri, ns.rdfs.isDefinedBy, "<" + url + ">")
return "".join(triples.lines)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_gem_IRI(self, our_label):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ni = self.gem_ni.get(our_label)
if ni is None:
log_it("ERROR", f"unexpected genome editing method '{our_label}'")
return ns.cello.GenomeModificationMethodNOS # default
return ni
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_cl_category_class_IRI(self, category_label):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
clazz = self.clcat_clazz.get(category_label)
if clazz is None:
log_it("ERROR", f"unexpected cell line category '{category_label}'")
clazz = ns.cello.CellLine # default, most generic
return clazz
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ref_class_IRI(self, ref_data):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
typ = ref_data["type"]
clazz = self.pubtype_clazz.get(typ)
if clazz is None:
ref_id = ref_data["internal-id"]
log_it("ERROR", f"unexpected publication type '{typ}' in {ref_id}")
clazz = ns.cello.Publication # default, most generic
return clazz
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_xref_dict(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return ns.xref.dbac_dict
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_sex(self, sex: Sex):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
triples = TripleList()
sex_IRI = get_sex_IRI(sex.label)
# as a named individual of type :Sex
triples.append(sex_IRI, ns.rdf.type, ns.cello.Sex)
triples.append(sex_IRI, ns.rdf.type, ns.owl.NamedIndividual)
triples.extend(self.get_materialized_triples_for_prop(sex_IRI, ns.cello.name, ns.xsd.string(sex.label))) # onto NI
url = ns.cello.url
if url.endswith("#"): url = url[:-1]
triples.append(sex_IRI, ns.rdfs.isDefinedBy, "<" + url + ">")
return "".join(triples.lines)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_cello_terminology_individual(self, termi):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Note: some databases are also declared as terminologies
triples = TripleList()
termi_IRI = self.get_terminology_or_database_IRI(termi.abbrev)
triples.append(termi_IRI, ns.rdf.type, ns.cello.CelloConceptScheme)
triples.append(termi_IRI, ns.rdf.type, ns.owl.NamedIndividual)
triples.extend(self.get_materialized_triples_for_prop(termi_IRI, ns.cello.alternativeName, ns.xsd.string(termi.name), no_rdfs_label=True)) # onto NI (long name is the alternative one)
triples.extend(self.get_materialized_triples_for_prop(termi_IRI, ns.cello.recommendedName, ns.xsd.string(termi.abbrev))) # onto NI (short name is the recommended one)
triples.append(termi_IRI, ns.cello.version, ns.xsd.string(termi.version))
triples.append(termi_IRI, ns.rdfs.seeAlso, "<" + termi.url + ">")
url = ns.cello.url
if url.endswith("#"): url = url[:-1]
triples.append(termi_IRI, ns.rdfs.isDefinedBy, "<" + url + ">")
return "".join(triples.lines)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_cello_database_individual(self, db: Database):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Note1 : some databases are also declared as terminologies
# Note2 : in UniProt, a database is an instance of class up:Database
# : in cello, we define a database as an instance of cello:Database subclass
# : and as a NamedIndividual
triples = TripleList()
db_IRI = self.get_terminology_or_database_IRI(db.rdf_id)
triples.append(db_IRI, ns.rdf.type, get_db_category_IRI(db.cat))
triples.append(db_IRI, ns.rdf.type, ns.owl.NamedIndividual)
triples.extend(self.get_materialized_triples_for_prop(db_IRI, ns.cello.alternativeName, ns.xsd.string(db.name), no_rdfs_label=True)) # db NI (long name is the alternative one)
triples.extend(self.get_materialized_triples_for_prop(db_IRI, ns.cello.recommendedName, ns.xsd.string(db.abbrev))) # db NI (short name is the recommended one)
if db.in_up:
up_db = "<http://purl.uniprot.org/database/" + db.abbrev + ">"
#triples.append(db_IRI, ns.owl.sameAs, up_db) # <=============== link between up and cello instances
triples.append(db_IRI, ns.skos.exactMatch, up_db) # <=============== link between up and cello instances
triples.append(db_IRI, ns.rdfs.seeAlso, "<" + db.url + ">")
url = ns.cello.url
if url.endswith("#"): url = url[:-1]
triples.append(db_IRI, ns.rdfs.isDefinedBy, "<" + url + ">")
return "".join(triples.lines)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_term(self, term):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
triples = TripleList()
# term IRI is built like xref IRI
# note that sometimes an IRI is both a :Xref and a:Concept
db = term.scheme
ac = term.id
xr_IRI = ns.xref.IRI(db, ac, None, store=False)
triples.append(xr_IRI, ns.rdf.type, ns.skos.Concept)
triples.append(xr_IRI, ns.skos.inScheme, self.get_terminology_or_database_IRI(term.scheme))
no_accent_label = self.remove_accents(term.prefLabel)
triples.extend(self.get_materialized_triples_for_prop(xr_IRI, ns.skos.prefLabel, ns.xsd.string(no_accent_label)))
triples.extend(self.get_materialized_triples_for_prop(xr_IRI, ns.skos.notation, ns.xsd.string(term.id)))
for alt in term.altLabelList:
no_accent_label = self.remove_accents(alt)
triples.extend(self.get_materialized_triples_for_prop(xr_IRI, ns.skos.altLabel, ns.xsd.string(no_accent_label)))
for parent_id in term.parentIdList:
parent_IRI = ns.xref.IRI(db, parent_id, None, store=False)
triples.append(xr_IRI, ns.cello.more_specific_than, parent_IRI)
return("".join(triples.lines))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_terminology_or_database_IRI(self, abbrev):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return "db:" + abbrev
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_xref_key(self, xref_key):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# split all fields: db, ac, and props: cat(egory), lbl, url, dis(continued)
(db,ac) = xref_key.split("=")
xr_dict = self.get_xref_dict()
prop_dict = dict()
for props in xr_dict[xref_key]:
for prop in props.split("|"):
pos = prop.find("=")
name = prop[0:pos]
value = prop[pos+1:]
if value != "":
if name not in prop_dict: prop_dict[name] = set()
prop_dict[name].add(value)
# send a WARNING when a prop has multiple values
singles = [ xref_key ]
multiples = list()
for k in sorted(prop_dict):
vset = prop_dict[k]
if len(vset)==1:
for v in vset: break # get first value in set
singles.append(k + ":" + v)
else:
mv = list()
for v in vset: mv.append(v)
multiples.append(f"Xref {xref_key} has multiple {k} : " + " | ".join(mv))
if len(multiples) > 0:
for m in multiples: log_it("WARNING", m)
# build the triples and return them
triples = TripleList()
xr_IRI = ns.xref.IRI(db, ac, None, store=False)
triples.append(xr_IRI, ns.rdf.type, ns.cello.Xref)
triples.append(xr_IRI, ns.cello.accession, ns.xsd.string(ac))
triples.append(xr_IRI, ns.cello.database, self.get_terminology_or_database_IRI(ns.xref.cleanDb(db)))
# we usually expect one item in the set associated to each key of prop_dict
# if we get more than one item, we take the first as the prop value
if "lbl" in prop_dict:
for value in prop_dict["lbl"]: break
triples.extend(self.get_materialized_triples_for_prop(xr_IRI, ns.cello.name, ns.xsd.string(value)))
if "dis" in prop_dict:
for value in prop_dict["dis"]: break
triples.append(xr_IRI, ns.cello.discontinued, ns.xsd.string(value))
if "url" in prop_dict:
for url in prop_dict["url"]: break
url = "". join(["<", self.encode_url(url), ">"])
triples.append(xr_IRI, ns.rdfs.seeAlso, url)
return("".join(triples.lines))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_orga_dict(self):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return ns.orga.nccc_dict
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_org_merged_with_known_org(self, org: Organization):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# if we just have a name, try to merge with a known org
# defined in institution_list and cellosaurus_xrefs.txt
korg = self.known_orgs.get(org.name)
if korg is not None:
# if one of the following fields is not None or a non empty string, emit WARNING
if org.shortname or org.city or org.country or org.contact:
print(f"WARNING, we are merging\n{org}\nwith\n{korg}")
# merge org with korg
org.name = korg.name
org.shortname = korg.shortname
org.city = korg.city
org.country = korg.country
org.contact = korg.contact
org.isInstitute = korg.isInstitute
org.isOnlineResource = korg.isOnlineResource
return org
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_orga(self, data, count):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# build an org object from data collected from annotations
(name, shortname, city, country, contact) = data.split("|")
if shortname == "": shortname = None
if city == "": city = None
if country == "": country = None
if contact == "": contact = None
org = Organization(name=name, shortname=shortname, city=city, country=country, contact=contact)
# build the triples and return them
triples = TripleList()
orga_IRI = ns.orga.IRI(org.name, org.shortname, org.city, org.country, org.contact, store = False)
triples.append(orga_IRI, ns.rdf.type, ns.schema.Organization)
triples.extend(self.get_materialized_triples_for_prop(orga_IRI, ns.cello.alternativeName, ns.xsd.string(org.name))) # long name is the alternative name
if org.shortname is not None and len(org.shortname)>0:
triples.extend(self.get_materialized_triples_for_prop(orga_IRI, ns.cello.recommendedName, ns.xsd.string(org.shortname))) # shortname is the rec name
if org.city is not None and len(org.city)>0:
triples.append(orga_IRI, ns.cello.city, ns.xsd.string(org.city))
if org.country is not None and len(org.country)>0:
triples.append(orga_IRI, ns.cello.country, ns.xsd.string(org.country))
if org.contact is not None and len(org.contact)>0:
for name in org.contact.split(" and "):
p_BN = self.get_blank_node()
triples.append(p_BN, ns.rdf.type, ns.schema.Person)
triples.extend(self.get_materialized_triples_for_prop(p_BN, ns.cello.name, ns.xsd.string(name)))
triples.append(p_BN, ns.cello.isMemberOf, orga_IRI)
return("".join(triples.lines))
# - - - - - - - - - - - - - - - - - - - - - - - - - -
def remove_accents(self, input_str):
# - - - - - - - - - - - - - - - - - - - - - - - - - -
nfkd_form = unicodedata.normalize('NFKD', input_str)
return u"".join([c for c in nfkd_form if not unicodedata.combining(c)])
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def encode_url(self, url):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# WARNING: escape to unicode is necessary for < and > and potentially for other characters...
# some DOIs contain weird chars like in :
# https://dx.doi.org/10.1002/(SICI)1096-8652(199910)62:2<93::AID-AJH5>3.0.CO;2-7
encoded_url = url.replace("<", "\\u003C").replace(">","\\u003E")
return encoded_url
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_ref(self, ref_obj):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
triples = TripleList()
ref_data = ref_obj["publication"]
ref_IRI = self.get_pub_IRI(ref_data)
# class: article, thesis, patent, ... (mandatory)
ref_class = self.get_ref_class_IRI(ref_data)
triples.append(ref_IRI, ns.rdf.type, ref_class)
# internal id (mandatory) for debug purpose
ref_id = ref_data["internal-id"]
triples.append(ref_IRI, ns.cello.internalId, ns.xsd.string(ref_id))
# authors (mandatory)
for p in ref_data["author-list"]:
p_type = p.get("type")
p_name = p["name"]
if p_type == "consortium":
orga_IRI = ns.orga.IRI(p_name, None, None, None, None)
triples.append(ref_IRI, ns.cello.creator, orga_IRI)
else:
for name in p_name.split(" and "):
p_BN = self.get_blank_node()
triples.append(ref_IRI, ns.cello.creator, p_BN)
triples.append(p_BN, ns.rdf.type, ns.schema.Person)
#triples.append(p_BN, ns.cello.name, ns.xsd.string(name))
triples.extend(self.get_materialized_triples_for_prop(p_BN, ns.cello.name, ns.xsd.string(name)))
# title (mandatory)
ttl = ref_data["title"]
triples.append(ref_IRI, ns.cello.title, ns.xsd.string(ttl))
# date (mandatory)
dt = ref_data["date"]
year = dt[-4:]
triples.append(ref_IRI, ns.cello.publicationYear, ns.xsd.string(year))
if len(dt) > 4:
if len(dt) != 11: raise DataError("Publication", "Unexpecting date format in " + ref_id)
day = dt[0:2]
month = self.mmm2mm[dt[3:6]]
#print("mydate",year,month,day)
triples.append(ref_IRI, ns.cello.publicationDate, ns.xsd.date("-".join([year, month, day])))
# xref-list (mandatory), we create and xref and a direct link to the url via rdfs:seeAlso
for xref in ref_data["xref-list"]:
accession = xref["accession"]
if self.get_xref_db(xref) == "PubMed": triples.append(ref_IRI, ns.cello.pmid, ns.xsd.string(accession))
elif self.get_xref_db(xref) == "DOI": triples.append(ref_IRI, ns.cello.doi, ns.xsd.string3(accession))
elif self.get_xref_db(xref) == "PMCID": triples.append(ref_IRI, ns.cello.pmcId, ns.xsd.string(accession))
xref_IRI = self.get_xref_IRI(xref)
triples.append(ref_IRI, ns.cello.seeAlsoXref, xref_IRI)
url = "". join(["<", self.encode_url(xref["url"]), ">"])
triples.append(ref_IRI, ns.rdfs.seeAlso, url )
# first page, last page, volume, journal (optional)
p1 = ref_data.get("first-page")
if p1 is not None: triples.append(ref_IRI, ns.cello.startingPage, ns.xsd.string(p1))
p2 = ref_data.get("last-page")
if p2 is not None: triples.append(ref_IRI, ns.cello.endingPage, ns.xsd.string(p2))
vol = ref_data.get("volume")
if vol is not None: triples.append(ref_IRI, ns.cello.volume, ns.xsd.string(vol))
jou = ref_data.get("journal-name")
if jou is not None: triples.append(ref_IRI, ns.cello.iso4JournalTitleAbbreviation, ns.xsd.string(jou))
# city, country, institution and publisher
city = ref_data.get("city")
country = ref_data.get("country")
institu = ref_data.get("institution")
if institu is not None:
orga_IRI = ns.orga.IRI(institu, None, city, country, None)
triples.append(ref_IRI, ns.cello.publisher, orga_IRI)
publisher = ref_data.get("publisher")
if publisher is not None:
orga_IRI = ns.orga.IRI(publisher, None, city, country, None)
triples.append(ref_IRI, ns.cello.publisher, orga_IRI)
# issn13 and entity titles
issn13 = ref_data.get("issn-13")
if issn13 is not None:
triples.append(ref_IRI, ns.cello.issn13, ns.xsd.string(issn13))
book_title = ref_data.get("book-title")
if book_title is not None:
triples.append(ref_IRI, ns.cello.bookTitle, ns.xsd.string(book_title))
doc_title = ref_data.get("document-title")
if doc_title is not None:
triples.append(ref_IRI, ns.cello.documentTitle, ns.xsd.string(doc_title))
doc_serie_title = ref_data.get("document-serie-title")
if doc_serie_title is not None:
triples.append(ref_IRI, ns.cello.documentSerieTitle, ns.xsd.string(doc_serie_title))
conf_title = ref_data.get("conference-title")
if conf_title is not None:
triples.append(ref_IRI, ns.cello.conferenceTitle, ns.xsd.string(conf_title))
# editors (optional)
for p in ref_data.get("editor-list") or []:
p_name = p["name"]
for name in p_name.split(" and "):
p_BN = self.get_blank_node()
triples.append(ref_IRI, ns.cello.editor, p_BN)
triples.append(p_BN, ns.rdf.type, ns.schema.Person)
triples.extend(self.get_materialized_triples_for_prop(p_BN, ns.cello.name, ns.xsd.string(name)))
return("".join(triples.lines))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_possibly_triples_for_xref_term_IRI(self, parent_node, xref):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# The method creates a list of triples.
# The returned list might be empty or contain a single triple
# depending on the existence of a term IRI in the xref
triples = TripleList()
term_IRI = self.get_xref_term_IRI(xref)
if term_IRI: triples.append(parent_node, ns.cello.isIdentifiedByIRI, f"<{term_IRI}>")
return triples
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_ttl_for_cl(self, ac, cl_obj):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
triples = TripleList()
cl_IRI = ns.cvcl.IRI(ac)
triples.append(cl_IRI, ns.rdfs.seeAlso, f"<https://www.cellosaurus.org/{ac}>")
cl_data = cl_obj["cell-line"]
# fields: AC, AS, ACAS
for ac_obj in cl_data["accession-list"]:
some_ac = ns.xsd.string(ac_obj["value"])
triples.append(cl_IRI, ns.cello.accession, some_ac)
pred = ns.cello.primaryAccession if ac_obj["type"] == "primary" else ns.cello.secondaryAccession
triples.append(cl_IRI, pred, some_ac)
# fields: ID, SY, IDSY
for name_obj in cl_data["name-list"]:
name = ns.xsd.string(name_obj["value"])
pred = ns.cello.recommendedName if name_obj["type"] == "identifier" else ns.cello.alternativeName
triples.extend(self.get_materialized_triples_for_prop(cl_IRI, pred, name))
# fields: CC, registration
for reg_obj in cl_data.get("registration-list") or []:
name = ns.xsd.string(reg_obj["registration-number"])
triples.extend(self.get_materialized_triples_for_prop(cl_IRI, ns.cello.registeredName, name))
annot_BN = self.get_blank_node()
triples.append(cl_IRI, ns.cello.hasRegistationRecord, annot_BN)
triples.append(annot_BN, ns.rdf.type, ns.cello.RegistrationRecord)
triples.extend(self.get_materialized_triples_for_prop(annot_BN, ns.cello.registeredName, name))
org_name = reg_obj["registry"]
org_IRI = ns.orga.IRI(org_name, "", "", "", "")
triples.append(annot_BN, ns.cello.inRegister, org_IRI)
# fields: CC, misspelling
for msp_obj in cl_data.get("misspelling-list") or []:
name = ns.xsd.string(msp_obj["misspelling-name"])
triples.extend(self.get_materialized_triples_for_prop(cl_IRI, ns.cello.misspellingName, name))
annot_BN = self.get_blank_node()
triples.append(cl_IRI, ns.cello.hasMisspellingRecord, annot_BN)
triples.append(annot_BN, ns.rdf.type, ns.cello.MisspellingRecord)
triples.extend(self.get_materialized_triples_for_prop(annot_BN, ns.cello.misspellingName, name))
note = msp_obj.get("misspelling-note")
if note is not None: triples.append(annot_BN, ns.rdfs.comment, ns.xsd.string(note))
for ref in msp_obj.get("reference-list") or []:
triples.append(annot_BN, ns.cello.appearsIn, self.get_pub_IRI(ref))
for xref in msp_obj.get("xref-list") or []:
triples.append(annot_BN, ns.cello.appearsIn, self.get_xref_IRI(xref))
# fields: DR
for xref in cl_data.get("xref-list") or []:
xref_IRI = self.get_xref_IRI(xref)
triples.append(cl_IRI, ns.cello.seeAlsoXref, xref_IRI)
triples.extend(self.get_possibly_triples_for_xref_term_IRI(cl_IRI, xref))
if self.get_xref_db(xref)=="Wikidata":
# we use owl:sameAs because our cell lines and their equivalent in wikidata are instances (as opposed as classes)
triples.append(cl_IRI, ns.owl.sameAs, ns.wd.IRI(xref["accession"]))
if self.get_xref_discontinued(xref):
# also used for "CC Discontinued: " lines
triples.extend(self.get_triples_for_cc_discontinued(cl_IRI, xref["database"], xref["accession"], xref_IRI))
# fields: RX
for rx in cl_data.get("reference-list") or []:
triples.append(cl_IRI, ns.cello.references, self.get_pub_IRI(rx))
# fields: WW
for ww in cl_data.get("web-page-list") or []:
# TODO: handle the 4 fields category, specifier, institution, not only url
ww_iri = "".join(["<", ww["url"], ">"])
triples.append(cl_IRI, ns.rdfs.seeAlso, ww_iri)
# fields: SX
sx = cl_data.get("sex")
if sx is not None:
triples.append(cl_IRI, ns.cello.comesFromIndividualWithSex, get_sex_IRI(sx))
# fields: AG
ag = cl_data.get("age")
if ag is not None:
triples.append(cl_IRI, ns.cello.comesFromIndividualAtAge, ns.xsd.string(ag))
# fields: OI
for oi in cl_data.get("same-origin-as") or []:
oi_iri = ns.cvcl.IRI(oi["accession"])
triples.append(cl_IRI, ns.cello.comesFromSameIndividualAs, oi_iri)
# fields: HI
for hi in cl_data.get("derived-from") or []:
hi_iri = ns.cvcl.IRI(hi["accession"])
triples.append(cl_IRI, ns.cello.hasParentCellLine, hi_iri)
# fields: CH
for ch in cl_data.get("child-list") or []:
ch_iri = ns.cvcl.IRI(ch["accession"]["value"])
triples.append(cl_IRI, ns.cello.hasChildCellLine, ch_iri)
# fields: CA
ca = cl_data["category"] # we expect one value for each cell line
if ca is not None:
triples.append(cl_IRI, ns.rdf.type, self.get_cl_category_class_IRI(ca))
else:
triples.append(cl_IRI, ns.rdf.type, ns.cello.CellLine)
# fields DT, dtc, dtu, dtv
triples.append(cl_IRI, ns.cello.created, ns.xsd.date(cl_data["created"]))
triples.append(cl_IRI, ns.cello.modified, ns.xsd.date(cl_data["last-updated"]))
triples.append(cl_IRI, ns.cello.version, ns.xsd.string(cl_data["entry-version"]))
# fields: CC, genome-ancestry
annot = cl_data.get("genome-ancestry")
if annot is not None:
annot_BN = self.get_blank_node()
triples.append(cl_IRI, ns.cello.hasGenomeAncestry, annot_BN)
triples.append(annot_BN, ns.rdf.type ,ns.cello.GenomeAncestry)
# ref can be publi or organization, but only publi in real data
src = annot.get("source")
if src is not None:
triples.extend(self.get_triples_for_source(annot_BN, src))
else:
log_it("ERROR", f"reference of genome-ancestry source is null: {ac}")
for pop in annot["population-list"]:
pop_percent_BN = self.get_blank_node()
triples.append(annot_BN, ns.cello.hasComponent, pop_percent_BN)
triples.append(pop_percent_BN, ns.rdf.type, ns.cello.PopulationPercentage)
pop_name = ns.xsd.string(pop["population-name"])
pop_BN = self.get_blank_node()
triples.append(pop_BN, ns.rdf.type, ns.cello.Population)
triples.extend(self.get_materialized_triples_for_prop(pop_BN, ns.cello.name, pop_name))
triples.append(pop_percent_BN, ns.cello.hasPopulation, pop_BN)
percent = ns.xsd.float(pop["population-percentage"])
triples.append(pop_percent_BN, ns.cello.percentage, percent)
# fields: CC hla
for annot in cl_data.get("hla-typing-list") or []:
annot_BN = self.get_blank_node()
triples.append(cl_IRI, ns.cello.hasHLAtyping, annot_BN)
triples.append(annot_BN, ns.rdf.type ,ns.cello.HLATyping)
src = annot.get("source")
if src is not None:
triples.extend(self.get_triples_for_source(annot_BN, src))
for gall in annot["hla-gene-alleles-list"]:
gene_label = gall["gene"]
for allele in gall["alleles"].split(","):
obs_BN = self.get_blank_node()
triples.append(annot_BN, ns.cello.includesObservation, obs_BN)
triples.append(obs_BN, ns.rdf.type, ns.schema.Observation)
gene_BN = self.get_blank_node()
triples.append(obs_BN, ns.cello.hasTarget, gene_BN)
triples.extend(self.get_triples_for_hla_gene_instance(gene_BN, gene_label))
allele_BN = self.get_blank_node()
allele_id = "*".join([gene_label, allele])
triples.append(obs_BN, ns.cello.detectedAllele, allele_BN)
triples.append(allele_BN, ns.rdf.type, ns.cello.HLA_Allele)
triples.append(allele_BN, ns.cello.alleleIdentifier, ns.xsd.string(allele_id))
# fields: CC str, WARNING: str-list is not a list !!!
annot = cl_data.get("str-list")
if annot is not None:
triples.extend(self.get_triples_for_short_tandem_repeat(cl_IRI, annot))
# fields: di
for annot in cl_data.get("disease-list") or []:
triples.extend(self.get_triples_for_disease(cl_IRI, annot))
# fields: ox
for annot in cl_data.get("species-list") or []:
triples.extend(self.get_triples_for_species(cl_IRI, annot))
# field: breed
breed_annot = cl_data.get("breed")
if breed_annot is not None:
triples.extend(self.get_triples_for_breed(cl_IRI, breed_annot))
# fields: CC sequence-variation
for annot in cl_data.get("sequence-variation-list") or []:
triples.extend(self.get_triples_for_sequence_variation(cl_IRI, annot))
# fields: derived-from-site
for annot in cl_data.get("derived-from-site-list") or []:
triples.extend(self.get_triples_for_derived_from_site(cl_IRI, annot))
ct_annot = cl_data.get("cell-type")
if ct_annot is not None:
triples.extend(self.get_triples_for_cell_type(cl_IRI, ct_annot))
# fields: CC doubling-time
for annot in cl_data.get("doubling-time-list") or []:
triples.extend(self.get_triples_for_doubling_time(cl_IRI, annot))
# fields: CC transformant
for annot in cl_data.get("transformant-list") or []:
triples.extend(self.get_triples_for_transformant(cl_IRI, annot))
# fields: CC msi
for annot in cl_data.get("microsatellite-instability-list") or []:
triples.extend(self.get_triples_for_msi(cl_IRI, annot))
# fields: CC mab-isotype
for annot in cl_data.get("monoclonal-antibody-isotype-list") or []:
triples.extend(self.get_triples_for_mab_isotype(cl_IRI, annot))
# fields: CC mab-target
for annot in cl_data.get("monoclonal-antibody-target-list") or []:
triples.extend(self.get_triples_for_mab_target(cl_IRI, annot))
# fields: CC resistance
for annot in cl_data.get("resistance-list") or []:
triples.extend(self.get_triples_for_resistance(cl_IRI, annot))
# fields: CC knockout
for annot in cl_data.get("knockout-cell-list") or []:
triples.extend(self.get_triples_for_cc_knockout_cell(cl_IRI, annot))
# fields: CC integration
for annot in cl_data.get("genetic-integration-list") or []:
triples.extend(self.get_triples_for_cc_genetic_integration(cl_IRI, annot))
# fields: CC from, ...
for cc in cl_data.get("comment-list") or []:
categ = cc["category"]
if categ == "From":
triples.extend(self.get_triples_for_cc_from(cl_IRI, cc))
elif categ == "Part of":
triples.extend(self.get_triples_for_cc_part_of(cl_IRI, cc))
elif categ == "Group":
triples.extend(self.get_triples_for_cc_in_group(cl_IRI, cc))
elif categ == "Anecdotal":
triples.extend(self.get_triples_for_cc_anecdotal(cl_IRI, cc))
elif categ == "Biotechnology":
triples.extend(self.get_triples_for_cc_biotechnology(cl_IRI, cc))
elif categ == "Characteristics":
triples.extend(self.get_triples_for_cc_characteristics(cl_IRI, cc))
elif categ == "Caution":
triples.extend(self.get_triples_for_cc_caution(cl_IRI, cc))
elif categ == "Donor information":
triples.extend(self.get_triples_for_cc_donor_info(cl_IRI, cc))
elif categ == "Discontinued":
provider, product_id = cc["value"].split("; ")
triples.extend(self.get_triples_for_cc_discontinued(cl_IRI, provider, product_id)) # also used in DR lines
elif categ == "Karyotypic information":
triples.extend(self.get_triples_for_cc_karyotypic_info(cl_IRI, cc))
elif categ == "Miscellaneous":
triples.extend(self.get_triples_for_cc_miscellaneous_info(cl_IRI, cc))
elif categ == "Senescence":
triples.extend(self.get_triples_for_cc_senescence_info(cl_IRI, cc))
elif categ == "Virology":
triples.extend(self.get_triples_for_cc_virology_info(cl_IRI, cc))
elif categ == "Omics":
triples.extend(self.get_triples_for_cc_omics_info(cl_IRI, cc))
elif categ == "Population":
triples.extend(self.get_triples_for_cc_population_info(cl_IRI, cc))
return("".join(triples.lines))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def extract_hgvs_list(self, label):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# How to test if description is hgvs ? based on mut type ? and/or parser ?
# hgvs formal only in Mutation | Simple(_edited/_corrected)
# hgvs ends at first <space>
# hgvs formal only if starts with c. , m. , n. , p. , chrN:g.
# if first hgvs is p.* and first in paranthese is starts with c. => c.* => additional hgvs
hgvs_list = list()