Writers¶
Functions for writing SSSOM data to various output formats.
sssom.writers
¶
Serialization functions for SSSOM.
write_table(msdf, file, embedded_mode=True, serialisation='tsv', sort=False, condense=True)
¶
Write a mapping set dataframe to the file as a table.
Source code in src/sssom/writers.py
write_tsv(msdf, path, embedded_mode=True, sort=False)
¶
Write a mapping set to a TSV file.
write_rdf(msdf, file, serialisation=None, *, hydrate=False, condense=False)
¶
Write a mapping set dataframe to the file as RDF.
:param msdf: A mapping set dataframe
:param file: The path or file object to write to
:param serialisation: The RDF format to serialize to, see :data:RDF_FORMATS. Defaults to
turtle.
:param hydrate: If true, will add subject-predicate-objects directly representing mappings. This
is opt-in behavior.
Source code in src/sssom/writers.py
write_json(msdf, output, serialisation='json', condense=True)
¶
Write a mapping set dataframe to the file as JSON.
:param msdf: A mapping set dataframe :param output: A path or write-supported file object to write JSON to :param serialisation: The JSON format to use. Supported formats are:
- ``fhir_json``: Outputs JSON in FHIR ConceptMap format
(https://fhir-ru.github.io/conceptmap.html)
https://mapping-commons.github.io/sssom-py/sssom.html#sssom.writers.to_fhir_json
- ``json``: Outputs to SSSOM JSON
https://mapping-commons.github.io/sssom-py/sssom.html#sssom.writers.to_json
- ``ontoportal_json``: Outputs JSON in Ontoportal format (https://ontoportal.org/)
https://mapping-commons.github.io/sssom-py/sssom.html#sssom.writers.to_ontoportal_json
Source code in src/sssom/writers.py
write_fhir_json(msdf, output, serialisation='fhir_json')
¶
Write a mapping set dataframe to the file as FHIR ConceptMap JSON.
Source code in src/sssom/writers.py
write_ontoportal_json(msdf, output, serialisation='ontoportal_json')
¶
Write a mapping set dataframe to the file as the ontoportal mapping JSON model.
Source code in src/sssom/writers.py
write_owl(msdf, file, serialisation=SSSOM_DEFAULT_RDF_SERIALISATION, condense=False)
¶
Write a mapping set dataframe to the file as OWL.
Source code in src/sssom/writers.py
to_owl_graph(msdf)
¶
Convert a mapping set dataframe to OWL in an RDF graph.
Source code in src/sssom/writers.py
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 | |
to_rdf_graph(msdf, *, hydrate=False)
¶
get_rdflib_endpoint_app(msdf, *, hydrate=True)
¶
Get a FastAPI app that serves the mappings from a SPARQL endpoint.
Source code in src/sssom/writers.py
to_fhir_json(msdf)
¶
Convert a mapping set dataframe to a JSON object.
:param msdf: MappingSetDataFrame: Collection of mappings represented as DataFrame, together w/ additional metadata.
:returns: Dict: A Dictionary serializable as JSON.
.. seealso::
ConceptMap=SSSOM mapping spreadsheet
https://docs.google.com/spreadsheets/d/1J19foBAYO8PCHwOfksaIGjNu-q5ILUKFh2HpOCgYle0/edit#gid=1389897118
.. todo:: add to CLI & to these functions: r4 vs r5 param
.. todo:: What if the msdf doesn't have everything we need? (i) metadata, e.g. yml, (ii) what if we need to override?
.. todo:: allow any nested arbitrary override: (get in kwargs, else metadata.get(key, None))
.. todo:: mapping_justification consider ValueString -> ValueCoding https://github.com/timsbiomed/issues/issues/152
.. todo:: when/how to conform to R5 instead of R4? https://build.fhir.org/conceptmap.html
Source code in src/sssom/writers.py
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 | |
to_json(msdf)
¶
Convert a mapping set dataframe to a JSON object.
Source code in src/sssom/writers.py
to_ontoportal_json(msdf)
¶
Convert a mapping set dataframe to a list of ontoportal mapping JSON objects.
Source code in src/sssom/writers.py
get_writer_function(*, output_format=None, output)
¶
Get appropriate writer function based on file format.
:param output: Output file :param output_format: Output file format, defaults to None
:returns: Type of writer function
:raises ValueError: Unknown output format
Source code in src/sssom/writers.py
write_tables(sssom_dict, output_dir)
¶
Write table from MappingSetDataFrame object.
:param sssom_dict: Dictionary of MappingSetDataframes :param output_dir: The directory in which the derived SSSOM files are written