Skip to content

API

Here the API is documented.

libsbgnpy

Arc dataclass

Bases: Sbgnbase

The arc element describes an SBGN arc between two SBGN nodes. It contains: For PD: an optional stoichiometry marker, For ER: an optional cardinality marker, zero or more ports (influence targets), and zero or more outcomes, a mandatory source and target (glyph or port), a geometric description of its whole path, from start to end. This path can involve any number of straight lines or quadratic/cubic Bezier curves.

:ivar glyph: In PD, an arc can contain a single optional sub-glyph. This glyph must be a stoichiometry marker (square with a numeric label) In ER, an arc can contain several sub-glyphs. This can be zero or one cardinality glyphs (e.g. cis or trans), plus zero to many outcome glyphs (black dot) :ivar port: Ports are only allowed in ER. :ivar start: The start element represents the starting point of the arc's path. It is unique and mandatory. :ivar next: The next element represents the next point in the arc's path. Between the start and the end of the path, there can be any number (even zero) of next elements (intermediate points). They are read consecutively: start, next, next, ..., next, end. When the path from the previous point to this point is not straight, this element also contains a list of control points (between 1 and 2) describing a Bezier curve (quadratic if 1 control point, cubic if 2) between the previous point and this point. :ivar end: The end element represents the ending point of the arc's path. It is unique and mandatory. When the path from the previous point to this point is not straight, this element also contains a list of control points (between 1 and 2) describing a Bezier curve (quadratic if 1 control point, cubic if 2) between the previous point and this point. :ivar class_value: The class attribute defines the semantic of the arc, and influences: the way that arc should be rendered, the overall syntactic validity of the map. The various classes encompass all possible types of SBGN arcs: production and consumption arcs, all types of modification arcs, logic arcs, equivalence arcs. To express a reversible reaction, use production arcs on both sides of the Process Node. :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. :ivar source: The source attribute can refer: either to the id of a glyph, or to the id of a port on a glyph. :ivar target: The target attribute can refer: either to the id of a glyph, or to the id of a port on a glyph.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Arc(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The arc element describes an SBGN arc between two SBGN nodes. It contains:
    <ns1:ul>
    <ns1:li>For PD: an optional stoichiometry marker,</ns1:li>
    <ns1:li>For ER: an optional cardinality marker,
    zero or more ports (influence targets), and zero or more outcomes,
    </ns1:li>
    <ns1:li>a mandatory source and target (glyph or port),</ns1:li>
    <ns1:li>a geometric description of its whole path, from start to end.</ns1:li>
    </ns1:ul>
    <ns1:p>
    </ns1:p>
    This path can involve any number of straight lines or quadratic/cubic Bezier
    curves.
    </ns1:p>

    :ivar glyph: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In PD,
        an arc can contain a single optional sub-glyph. This glyph must
        be a stoichiometry marker (square with a numeric label) </ns1:p>
        <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In ER, an arc
        can contain several sub-glyphs. This can be zero or one
        cardinality glyphs (e.g. cis or trans), plus zero to many
        outcome glyphs (black dot) </ns1:p>
    :ivar port: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> Ports
        are only allowed in ER. </ns1:p>
    :ivar start: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        start element represents the starting point of the arc's path.
        It is unique and mandatory. </ns1:p>
    :ivar next: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The next
        element represents the next point in the arc's path. Between the
        start and the end of the path, there can be any number (even
        zero) of next elements (intermediate points). They are read
        consecutively: start, next, next, ..., next, end. When the path
        from the previous point to this point is not straight, this
        element also contains a list of control points (between 1 and 2)
        describing a Bezier curve (quadratic if 1 control point, cubic
        if 2) between the previous point and this point. </ns1:p>
    :ivar end: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The end
        element represents the ending point of the arc's path. It is
        unique and mandatory. When the path from the previous point to
        this point is not straight, this element also contains a list of
        control points (between 1 and 2) describing a Bezier curve
        (quadratic if 1 control point, cubic if 2) between the previous
        point and this point. </ns1:p>
    :ivar class_value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The class attribute defines the semantic of the arc, and
        influences: <ns1:ul> <ns1:li>the way that arc should be
        rendered,</ns1:li> <ns1:li>the overall syntactic validity of the
        map.</ns1:li> </ns1:ul> </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The various classes
        encompass all possible types of SBGN arcs: <ns1:ul>
        <ns1:li>production and consumption arcs,</ns1:li> <ns1:li>all
        types of modification arcs,</ns1:li> <ns1:li>logic
        arcs,</ns1:li> <ns1:li>equivalence arcs.</ns1:li> </ns1:ul> To
        express a reversible reaction, use production arcs on both sides
        of the Process Node. </ns1:p>
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter.
        </ns1:p>
    :ivar source: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        source attribute can refer: <ns1:ul> <ns1:li>either to the id of
        a glyph,</ns1:li> <ns1:li>or to the id of a port on a
        glyph.</ns1:li> </ns1:ul> </ns1:p>
    :ivar target: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        target attribute can refer: <ns1:ul> <ns1:li>either to the id of
        a glyph,</ns1:li> <ns1:li>or to the id of a port on a
        glyph.</ns1:li> </ns1:ul> </ns1:p>
    """

    class Meta:
        name = "arc"
        namespace = "http://sbgn.org/libsbgn/0.3"

    glyph: list[Glyph] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    port: list[Port] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    start: Optional["Arc.Start"] = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    next: list["Arc.Next"] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    end: Optional["Arc.End"] = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    class_value: Optional[ArcClass] = field(
        default=None,
        metadata={
            "name": "class",
            "type": "Attribute",
            "required": True,
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    source: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    target: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

    @dataclass
    class Start:
        x: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        y: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

    @dataclass
    class Next:
        point: list[Point] = field(
            default_factory=list,
            metadata={
                "type": "Element",
                "max_occurs": 2,
            },
        )
        x: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        y: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

    @dataclass
    class End:
        point: list[Point] = field(
            default_factory=list,
            metadata={
                "type": "Element",
                "max_occurs": 2,
            },
        )
        x: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        y: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

Arcgroup dataclass

Bases: Sbgnbase

The arc group describes a set of arcs and glyphs that together have a relation. For example For ER: interaction arcs around an interaction glyph, ... Note that, in spite of the name, an arcgroup contains both arcs and glyphs.

:ivar glyph: An arcgroup can contain glyphs. For example, in an interaction arcgroup, there must be one interaction glyph. :ivar arc: An arcgroup can have multiple arcs. They are all assumed to form a single hyperarc-like structure. :ivar class_value: The class attribute defines the semantic of the arcgroup.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Arcgroup(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The arc group describes a set of arcs and glyphs that together have a relation.
    For example
    <ns1:ul>
    <ns1:li>For ER: interaction arcs around an interaction glyph,</ns1:li>
    <ns1:li>...</ns1:li>
    </ns1:ul>
    Note that, in spite of the name, an arcgroup contains both arcs and glyphs.
    </ns1:p>

    :ivar glyph: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> An
        arcgroup can contain glyphs. For example, in an interaction
        arcgroup, there must be one interaction glyph. </ns1:p>
    :ivar arc: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> An
        arcgroup can have multiple arcs. They are all assumed to form a
        single hyperarc-like structure. </ns1:p>
    :ivar class_value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The class attribute defines the semantic of the arcgroup.
        </ns1:p>
    """

    class Meta:
        name = "arcgroup"
        namespace = "http://sbgn.org/libsbgn/0.3"

    glyph: list[Glyph] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    arc: list[Arc] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    class_value: Optional[ArcgroupClass] = field(
        default=None,
        metadata={
            "name": "class",
            "type": "Attribute",
            "required": True,
        },
    )

Bbox dataclass

Bases: Sbgnbase

The bbox element describes a rectangle. This rectangle is defined by: PointAttributes corresponding to the 2D coordinates of the top left corner, width and height attributes. The rectangle corresponds to the outer bounding box of a shape. The shape itself can be irregular (for instance in the case of some compartments). In the case of process nodes, the bounding box only concerns the central glyph (square, or circle), the input/output ports are not included, and neither are the lines connecting them to the central glyph. A bbox is required for all glyphs, and is optional for labels.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Bbox(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The bbox element describes a rectangle. This rectangle is defined by:
    <ns1:ul>
    <ns1:li>
    PointAttributes corresponding to the 2D coordinates of the top left
    corner,
    </ns1:li>
    <ns1:li>width and height attributes.</ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The rectangle corresponds to the outer bounding box of a shape.
    The shape itself can be irregular
    (for instance in the case of some compartments).
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    In the case of process nodes,
    the bounding box only concerns the central glyph (square, or circle),
    the input/output ports are not included, and neither are the lines connecting
    them to the central glyph.
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    A bbox is required for all glyphs, and is optional for labels.
    </ns1:p>"""

    class Meta:
        name = "bbox"
        namespace = "http://sbgn.org/libsbgn/0.3"

    x: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    y: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    w: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    h: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Glyph dataclass

Bases: Sbgnbase

The glyph element is: either a stand-alone, high-level SBGN glyph (EPN, PN, compartment, etc), or a sub-glyph (state variable, unit of information, inside of a complex, ...) In the first case, it appears directly in the glyph list of the map. In the second case, it is a child of another glyph element.

:ivar label: :ivar state: The state element should only be used for state variables. It replaces the label element used for other glyphs. It describes the text to be drawn inside the state variable. A state must have a value, a variable, or both. If it has both, they are rendered as a concatenated string with @ in between. :ivar clone: The clone element (which is optional) means the glyph carries a clone marker. It can contain an optional label. :ivar callout: The callout element is only used for glyphs with class annotation. It contains the coordinate of the point where the annotation points to, as well as a reference to the element that is pointed to. :ivar entity: The entity is only used in activity flow diagrams. It can only be used on a unit of information glyph on a biological activity glyph, where it is compulsory. It is used to indicate the shape of this unit of information. :ivar bbox: The bbox element is mandatory and unique: exactly one per glyph. It defines the outer bounding box of the glyph. The actual shape of the glyph can be irregular (for instance in the case of some compartments) In the case of process nodes, the bounding box only concerns the central glyph (square, or circle): the input/output ports are not included, and neither are the lines connecting them to the central glyph. :ivar glyph: A glyph element can contain any number of children glyph elements. In practice, this should only happen in the following cases: a compartment with unit of information children, an EPN with states variables and/or unit of information children, a complex, with state variables, unit of info, and/or EPN children. :ivar port: :ivar class_value: The class attribute defines the semantic of the glyph, and influences: the way that glyph should be rendered, the overall syntactic validity of the map. The various classes encompass the following PD SBGN elements: Entity Pool Nodes (EPN), Process Nodes (PN), Logic Operator Nodes, Sub-glyphs on Nodes (State Variable, Unit of Information), Sub-glyphs on Arcs (Stoichiometry Label), Other glyphs (Compartment, Submap, Tag, Terminal). And the following ER SBGN elements Entities (Entity, Outcome) Other (Annotation, Phenotype) Auxiliary on glyps (Existence, Location) Auxiliary on arcs (Cardinality) Delay operator implicit xor :ivar orientation: The orientation attribute is used to express how to draw asymmetric glyphs. In PD, the orientation of Process Nodes is either horizontal or vertical. It refers to an (imaginary) line connecting the two in/out sides of the PN. In PD, the orientation of Tags and Terminals can be left, right, up or down. It refers to the direction the arrow side of the glyph is pointing at. :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. It is recommended to generate meaningless IDs (e.g. "glyph1234") and avoid IDs with a meaning (e.g. "epn_ethanol") :ivar compartment_ref: Reference to the ID of the compartment that this glyph is part of. Only use this if there is at least one explicit compartment present in the diagram. Compartments are only used in PD and AF, and thus this attribute as well. For PD, this should be used only for EPN's. For AF, this should be used only for Activity Nodes. In case there are no compartments, entities that can have a location, such as EPN's, are implicit member of an invisible compartment that encompasses the whole map. In that case, this attribute must be omitted. :ivar compartment_order: The compartment order attribute can be used to define a drawing order for compartments. It enables tools to draw compartments in the correct order especially in the case of overlapping compartments. Compartments are only used in PD and AF, and thus this attribute as well. The attribute is of type float, the attribute value has not to be unique. Compartments with higher compartment order are drawn on top. The attribute is optional and should only be used for compartments. :ivar map_ref: This attribute is only used on a submap glyph. It is required. Reference to the ID of the map which provides the content of the submap. If no map is available providing the content of the submap an omitted process should be used instead of the submap. Submaps are only used in PD and AF, and thus this attribute as well. :ivar tag_ref: This attribute is only used on a terminal glyph. It is required. Reference to the ID of a tag on a map providing the content of a submap. The terminal glyph is defined as sub-glyph of this submap. Submaps and therefore terminals are only used in PD and AF, and thus this attribute as well.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Glyph(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The glyph element is:
    <ns1:ul>
    <ns1:li>either a stand-alone, high-level SBGN glyph
    (EPN, PN, compartment, etc),
    </ns1:li>
    <ns1:li>or a sub-glyph
    (state variable, unit of information, inside of a complex, ...)
    </ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    In the first case, it appears directly in the glyph list of the map.
    In the second case, it is a child of another glyph element.
    </ns1:p>

    :ivar label:
    :ivar state: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        state element should only be used for state variables. It
        replaces the label element used for other glyphs. It describes
        the text to be drawn inside the state variable. </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> A state must have a
        value, a variable, or both. If it has both, they are rendered as
        a concatenated string with @ in between. </ns1:p>
    :ivar clone: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        clone element (which is optional) means the glyph carries a
        clone marker. It can contain an optional label. </ns1:p>
    :ivar callout: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        callout element is only used for glyphs with class annotation.
        It contains the coordinate of the point where the annotation
        points to, as well as a reference to the element that is pointed
        to. </ns1:p>
    :ivar entity: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        entity is only used in activity flow diagrams. It can only be
        used on a unit of information glyph on a biological activity
        glyph, where it is compulsory. It is used to indicate the shape
        of this unit of information. </ns1:p>
    :ivar bbox: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The bbox
        element is mandatory and unique: exactly one per glyph. It
        defines the outer bounding box of the glyph. The actual shape of
        the glyph can be irregular (for instance in the case of some
        compartments) </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In the case of process
        nodes, the bounding box only concerns the central glyph (square,
        or circle): the input/output ports are not included, and neither
        are the lines connecting them to the central glyph. </ns1:p>
    :ivar glyph: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> A glyph
        element can contain any number of children glyph elements. In
        practice, this should only happen in the following cases:
        <ns1:ul> <ns1:li>a compartment with unit of information
        children,</ns1:li> <ns1:li> an EPN with states variables and/or
        unit of information children, </ns1:li> <ns1:li> a complex, with
        state variables, unit of info, and/or EPN children. </ns1:li>
        </ns1:ul> </ns1:p>
    :ivar port:
    :ivar class_value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The class attribute defines the semantic of the glyph, and
        influences: <ns1:ul> <ns1:li>the way that glyph should be
        rendered,</ns1:li> <ns1:li>the overall syntactic validity of the
        map.</ns1:li> </ns1:ul> </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The various classes
        encompass the following PD SBGN elements: <ns1:ul>
        <ns1:li>Entity Pool Nodes (EPN),</ns1:li> <ns1:li>Process Nodes
        (PN),</ns1:li> <ns1:li>Logic Operator Nodes,</ns1:li>
        <ns1:li>Sub-glyphs on Nodes (State Variable, Unit of
        Information),</ns1:li> <ns1:li>Sub-glyphs on Arcs (Stoichiometry
        Label),</ns1:li> <ns1:li>Other glyphs (Compartment, Submap, Tag,
        Terminal).</ns1:li> </ns1:ul> And the following ER SBGN elements
        <ns1:ul> <ns1:li>Entities (Entity, Outcome)</ns1:li>
        <ns1:li>Other (Annotation, Phenotype)</ns1:li> <ns1:li>Auxiliary
        on glyps (Existence, Location)</ns1:li> <ns1:li>Auxiliary on
        arcs (Cardinality)</ns1:li> <ns1:li>Delay operator</ns1:li>
        <ns1:li>implicit xor</ns1:li> </ns1:ul> </ns1:p>
    :ivar orientation: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The orientation attribute is used to express how to draw
        asymmetric glyphs. In PD, the orientation of Process Nodes is
        either horizontal or vertical. It refers to an (imaginary) line
        connecting the two in/out sides of the PN. In PD, the
        orientation of Tags and Terminals can be left, right, up or
        down. It refers to the direction the arrow side of the glyph is
        pointing at. </ns1:p>
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter. It
        is recommended to generate meaningless IDs (e.g. "glyph1234")
        and avoid IDs with a meaning (e.g. "epn_ethanol") </ns1:p>
    :ivar compartment_ref: <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> Reference to the ID of
        the compartment that this glyph is part of. Only use this if
        there is at least one explicit compartment present in the
        diagram. Compartments are only used in PD and AF, and thus this
        attribute as well. For PD, this should be used only for EPN's.
        For AF, this should be used only for Activity Nodes. </ns1:p>
        <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In case there
        are no compartments, entities that can have a location, such as
        EPN's, are implicit member of an invisible compartment that
        encompasses the whole map. In that case, this attribute must be
        omitted. </ns1:p>
    :ivar compartment_order: <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The compartment order
        attribute can be used to define a drawing order for
        compartments. It enables tools to draw compartments in the
        correct order especially in the case of overlapping
        compartments. Compartments are only used in PD and AF, and thus
        this attribute as well. </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The attribute is of
        type float, the attribute value has not to be unique.
        Compartments with higher compartment order are drawn on top. The
        attribute is optional and should only be used for compartments.
        </ns1:p>
    :ivar map_ref: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> This
        attribute is only used on a submap glyph. It is required.
        </ns1:p> <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Reference to the ID of the map which provides the content of the
        submap. If no map is available providing the content of the
        submap an omitted process should be used instead of the submap.
        Submaps are only used in PD and AF, and thus this attribute as
        well. </ns1:p>
    :ivar tag_ref: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> This
        attribute is only used on a terminal glyph. It is required.
        </ns1:p> <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Reference to the ID of a tag on a map providing the content of a
        submap. The terminal glyph is defined as sub-glyph of this
        submap. Submaps and therefore terminals are only used in PD and
        AF, and thus this attribute as well. </ns1:p>
    """

    class Meta:
        name = "glyph"
        namespace = "http://sbgn.org/libsbgn/0.3"

    label: Optional[Label] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    state: Optional["Glyph.State"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    clone: Optional["Glyph.Clone"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    callout: Optional["Glyph.Callout"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    entity: Optional["Glyph.Entity"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    bbox: Optional[Bbox] = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    glyph: list["Glyph"] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    port: list[Port] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    class_value: Optional[GlyphClass] = field(
        default=None,
        metadata={
            "name": "class",
            "type": "Attribute",
            "required": True,
        },
    )
    orientation: GlyphOrientation = field(
        default=GlyphOrientation.HORIZONTAL,
        metadata={
            "type": "Attribute",
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    compartment_ref: Optional[str] = field(
        default=None,
        metadata={
            "name": "compartmentRef",
            "type": "Attribute",
        },
    )
    compartment_order: Optional[float] = field(
        default=None,
        metadata={
            "name": "compartmentOrder",
            "type": "Attribute",
        },
    )
    map_ref: Optional[str] = field(
        default=None,
        metadata={
            "name": "mapRef",
            "type": "Attribute",
        },
    )
    tag_ref: Optional[str] = field(
        default=None,
        metadata={
            "name": "tagRef",
            "type": "Attribute",
        },
    )

    @dataclass
    class Clone:
        label: Optional[Label] = field(
            default=None,
            metadata={
                "type": "Element",
            },
        )

    @dataclass
    class Callout:
        point: Optional[Point] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        target: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )

    @dataclass
    class Entity:
        name: Optional[EntityName] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

    @dataclass
    class State:
        """
        :ivar value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
            value attribute represents the state of the variable. It can
            be: <ns1:ul> <ns1:li> either from a predefined set of string
            (P, S, etc.) which correspond to specific SBO terms (cf.
            SBGN specs), </ns1:li> <ns1:li> or any arbitrary string.
            </ns1:li> </ns1:ul> </ns1:p>
        :ivar variable: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
            The variable attribute describes the site where the
            modification described by the value attribute occurs. It is:
            <ns1:ul> <ns1:li> optional when there is only one state
            variable on the parent EPN, </ns1:li> <ns1:li> required when
            there is more than one state variable the parent EPN.
            </ns1:li> </ns1:ul> </ns1:p>
        """

        value: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )
        variable: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )

State dataclass

:ivar value: The value attribute represents the state of the variable. It can be: either from a predefined set of string (P, S, etc.) which correspond to specific SBO terms (cf. SBGN specs), or any arbitrary string. :ivar variable: The variable attribute describes the site where the modification described by the value attribute occurs. It is: optional when there is only one state variable on the parent EPN, required when there is more than one state variable the parent EPN.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class State:
    """
    :ivar value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        value attribute represents the state of the variable. It can
        be: <ns1:ul> <ns1:li> either from a predefined set of string
        (P, S, etc.) which correspond to specific SBO terms (cf.
        SBGN specs), </ns1:li> <ns1:li> or any arbitrary string.
        </ns1:li> </ns1:ul> </ns1:p>
    :ivar variable: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The variable attribute describes the site where the
        modification described by the value attribute occurs. It is:
        <ns1:ul> <ns1:li> optional when there is only one state
        variable on the parent EPN, </ns1:li> <ns1:li> required when
        there is more than one state variable the parent EPN.
        </ns1:li> </ns1:ul> </ns1:p>
    """

    value: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    variable: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )

Label dataclass

Bases: Sbgnbase

The label element describes the text accompanying a glyph. The text attribute is mandatory. Its position can be specified by a bbox (optional). Tools are free to display the text in any style (font, font-size, etc.)

:ivar bbox: :ivar text: Multi- line labels are allowed. Line breaks are encoded as &#xA; as specified by the XML standard.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Label(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The label element describes the text accompanying a glyph.
    The text attribute is mandatory.
    Its position can be specified by a bbox (optional).
    Tools are free to display the text in any style (font, font-size, etc.)
    </ns1:p>

    :ivar bbox:
    :ivar text: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> Multi-
        line labels are allowed. Line breaks are encoded as &amp;#xA; as
        specified by the XML standard. </ns1:p>
    """

    class Meta:
        name = "label"
        namespace = "http://sbgn.org/libsbgn/0.3"

    bbox: Optional[Bbox] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    text: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Map dataclass

Bases: Sbgnbase

The map element describes a single SBGN PD map. It contains a list of glyph elements and a list of arc elements. These lists can be of any size (possibly empty).

:ivar bbox: The bbox element on a map is not mandatory, it allows the application to define a canvas, and at the same time define a whitespace margin around the glyphs. If a bbox is defined on a map, all glyphs and arcs must be inside this bbox, otherwise they could be clipped off by applications. :ivar glyph: :ivar arc: :ivar arcgroup: :ivar version: Version of the map: URI identifier that gives the language, level and version defined by SBGN. Different languages/levels/versions have different restrictions on the usage of sub-elements (that are not encoded in this schema but must be validated with an external validator) :ivar language: Language of the map: one of three sublanguages defined by SBGN. Different languages have different restrictions on the usage of sub-elements (that are not encoded in this schema but must be validated with an external validator) :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. It is recommended to generate meaningless IDs (e.g. "map1234") and avoid IDs with a meaning (e.g. "MAPK cascade")

Source code in src/libsbgnpy/sbgn.py
 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
@dataclass
class Map(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The map element describes a single SBGN PD map.
    It contains a list of glyph elements and a list of arc elements.
    These lists can be of any size (possibly empty).
    </ns1:p>

    :ivar bbox: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The bbox
        element on a map is not mandatory, it allows the application to
        define a canvas, and at the same time define a whitespace margin
        around the glyphs. </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> If a bbox is defined on
        a map, all glyphs and arcs must be inside this bbox, otherwise
        they could be clipped off by applications. </ns1:p>
    :ivar glyph:
    :ivar arc:
    :ivar arcgroup:
    :ivar version: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Version of the map: URI identifier that gives the language,
        level and version defined by SBGN. Different
        languages/levels/versions have different restrictions on the
        usage of sub-elements (that are not encoded in this schema but
        must be validated with an external validator) </ns1:p>
    :ivar language: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Language of the map: one of three sublanguages defined by SBGN.
        Different languages have different restrictions on the usage of
        sub-elements (that are not encoded in this schema but must be
        validated with an external validator) </ns1:p>
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter. It
        is recommended to generate meaningless IDs (e.g. "map1234") and
        avoid IDs with a meaning (e.g. "MAPK cascade") </ns1:p>
    """

    class Meta:
        name = "map"
        namespace = "http://sbgn.org/libsbgn/0.3"

    bbox: Optional[Bbox] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    glyph: list[Glyph] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    arc: list[Arc] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    arcgroup: list[Arcgroup] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    version: Optional[MapVersion] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    language: Optional[MapLanguage] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Point dataclass

Bases: Sbgnbase

The point element is characterized by PointAttributes, which describe absolute 2D cartesian coordinates. Namely: x (horizontal, from left to right), y (vertical, from top to bottom). The origin is located in the top-left corner of the map. There is no unit: proportions must be preserved, but the maps can be drawn at any scale. In the test files examples, to obtain a drawing similar to the reference .png file, values in the corresponding .sbgn file should be read as pixels.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Point(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The point element is characterized by PointAttributes,
    which describe absolute 2D cartesian coordinates. Namely:
    <ns1:ul>
    <ns1:li>x (horizontal, from left to right),</ns1:li>
    <ns1:li>y (vertical, from top to bottom).</ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The origin is located in the top-left corner of the map.
    There is no unit:
    proportions must be preserved, but the maps can be drawn at any scale.
    In the test files examples, to obtain a drawing similar to the reference
    *.png file, values in the corresponding *.sbgn file should be read as pixels.
    </ns1:p>"""

    class Meta:
        name = "point"
        namespace = "http://sbgn.org/libsbgn/0.3"

    x: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    y: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Port dataclass

Bases: Sbgnbase

The port element describes an anchor point to which arcs can refer as a source or target. It consists of: absolute 2D cartesian coordinates (PointAttribute), a unique id attribute. Two port elements are required for process nodes. They represent the extremity of the two "arms" which protrude on both sides of the core of the glyph (= square or circle shape). Other glyphs don't need ports (but can use them if desired).

:ivar x: :ivar y: :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. Port IDs often contain the ID of their glyph, followed by a local port number (e.g. glyph4.1, glyph4.2, etc.) However, this style convention is not mandatory, and IDs should never be interpreted as carrying any meaning.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Port(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The port element describes an anchor point to which arcs can refer
    as a source or target. It consists of:
    <ns1:ul>
    <ns1:li>absolute 2D cartesian coordinates (PointAttribute),</ns1:li>
    <ns1:li>a unique id attribute.</ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    Two port elements are required for process nodes. They represent
    the extremity of the two "arms" which protrude on both sides of the
    core of the glyph (= square or circle shape).
    Other glyphs don't need ports (but can use them if desired).
    </ns1:p>

    :ivar x:
    :ivar y:
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter. Port
        IDs often contain the ID of their glyph, followed by a local
        port number (e.g. glyph4.1, glyph4.2, etc.) However, this style
        convention is not mandatory, and IDs should never be interpreted
        as carrying any meaning. </ns1:p>
    """

    class Meta:
        name = "port"
        namespace = "http://sbgn.org/libsbgn/0.3"

    x: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    y: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Sbgn dataclass

Bases: Sbgnbase

The sbgn element is the root of any SBGNML document. Currently each document must contain exactly one map element.

Source code in src/libsbgnpy/sbgn.py
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
@dataclass
class Sbgn(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The sbgn element is the root of any SBGNML document.
    Currently each document must contain exactly one map element.
    </ns1:p>"""

    class Meta:
        name = "sbgn"
        namespace = "http://sbgn.org/libsbgn/0.3"

    map: list[Map] = field(
        default_factory=list,
        metadata={
            "type": "Element",
            "min_occurs": 1,
        },
    )

Sbgnbase dataclass

The SBGNBase type is the base type of all main components in SBGN. It supports attaching notes and extensions to components, with metadata and annotations encoded in the extension element.

Source code in src/libsbgnpy/sbgn.py
 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
@dataclass
class Sbgnbase:
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The SBGNBase type is the base type of all main components in SBGN.
    It supports attaching notes and extensions to components, with
    metadata and annotations encoded in the extension element.
    </ns1:p>"""

    class Meta:
        name = "SBGNBase"

    notes: Optional["Sbgnbase.Notes"] = field(
        default=None,
        metadata={
            "type": "Element",
            "namespace": "http://sbgn.org/libsbgn/0.3",
        },
    )
    extension: Optional["Sbgnbase.Extension"] = field(
        default=None,
        metadata={
            "type": "Element",
            "namespace": "http://sbgn.org/libsbgn/0.3",
        },
    )

    @dataclass
    class Notes:
        """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The notes element stores notes.
        </ns1:p>"""

        w3_org_1999_xhtml_element: list[object] = field(
            default_factory=list,
            metadata={
                "type": "Wildcard",
                "namespace": "http://www.w3.org/1999/xhtml",
                "process_contents": "skip",
            },
        )

    @dataclass
    class Extension:
        """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The extension element stores extension information like
        render information, metadata or annotations.
        </ns1:p>"""

        any_element: list[object] = field(
            default_factory=list,
            metadata={
                "type": "Wildcard",
                "namespace": "##any",
                "process_contents": "skip",
            },
        )

Extension dataclass

The extension element stores extension information like render information, metadata or annotations.

Source code in src/libsbgnpy/sbgn.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@dataclass
class Extension:
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The extension element stores extension information like
    render information, metadata or annotations.
    </ns1:p>"""

    any_element: list[object] = field(
        default_factory=list,
        metadata={
            "type": "Wildcard",
            "namespace": "##any",
            "process_contents": "skip",
        },
    )

Notes dataclass

The notes element stores notes.

Source code in src/libsbgnpy/sbgn.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@dataclass
class Notes:
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The notes element stores notes.
    </ns1:p>"""

    w3_org_1999_xhtml_element: list[object] = field(
        default_factory=list,
        metadata={
            "type": "Wildcard",
            "namespace": "http://www.w3.org/1999/xhtml",
            "process_contents": "skip",
        },
    )

read_render_from_string(xml_str)

Read RenderInformation from string.

Source code in src/libsbgnpy/io.py
106
107
108
109
def read_render_from_string(xml_str: str) -> RenderInformation:
    """Read RenderInformation from string."""
    parser = XmlParser()
    return parser.from_string(xml_str, RenderInformation)

read_sbgn_from_file(f)

Read an sbgn file (without validating against the schema).

:param silence: display no information :param f: file to read :return: parsed SBGN :rtype:

Source code in src/libsbgnpy/io.py
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
def read_sbgn_from_file(f: Path) -> Sbgn:
    """Read an sbgn file (without validating against the schema).

    :param silence: display no information
    :param f: file to read
    :return: parsed SBGN
    :rtype:
    """
    with open(f, "r", encoding="utf-8") as f_in:
        xml_str = f_in.read()
        # upconverting for fixing reading
        xml_str = xml_str.replace(
            "http://sbgn.org/libsbgn/0.1", "http://sbgn.org/libsbgn/0.3"
        )
        xml_str = xml_str.replace(
            "http://sbgn.org/libsbgn/0.2", "http://sbgn.org/libsbgn/0.3"
        )

    parser = XmlParser()
    try:
        sbgn = parser.from_string(xml_str, Sbgn)
    except xsdata.exceptions.ParserError as err:
        logger.error(f"Could not parse SBGN file: '{f}'")
        logger.error(err)
        logger.error(f"\n{xml_str}")

    # sbgn = parser.parse(f, Sbgn)
    return sbgn

render_sbgn(sbgn, image_file, file_format='png')

Render given sbgn object to image.

Supports the following file_formats: "png" The image file must end in .file_format, e.g. in '.png'

Performs a request analogue to: curl -X POST -F file=@"BorisEJB.xml" http://sysbioapps.spdns.org/Layout/GenerateImage -o out.png

:param sbgn: sbgn object :param image_file: image to create :return: None

Source code in src/libsbgnpy/image.py
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
def render_sbgn(sbgn: libsbgn.Sbgn, image_file: Path, file_format: str = "png") -> None:
    """Render given sbgn object to image.

    Supports the following file_formats: "png"
    The image file must end in .file_format, e.g. in '.png'

    Performs a request analogue to:
    curl -X POST -F file=@"BorisEJB.xml" http://sysbioapps.spdns.org/Layout/GenerateImage -o out.png

    :param sbgn: sbgn object
    :param image_file: image to create
    :return: None
    """
    if file_format != "png":
        raise ValueError("Only png rendering supported.")

    if not str(image_file).endswith(f".{file_format}"):
        raise ValueError(
            "The filename must end in <.file_format>, e.g. for png it must end in <.png>."
        )

    # Create temporary file for request
    with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp_dir:
        f_in: Path = Path(tmp_dir) / "render.sbgn"
        io.write_sbgn_to_file(sbgn, f_in)

        # Call webservice for rendering
        files = [
            ("file", open(f_in, "rb")),
        ]
        r = requests.post(f"{RENDER_URL}/GenerateImage", files=files)

        r.raise_for_status()

        with open(image_file, "wb") as fd:
            for chunk in r.iter_content(chunk_size=128):
                fd.write(chunk)
            fd.close()

        print("SBGN rendered:", image_file)

validate_xsd(f)

Validate SBGN file against XSD schema.

:param f: file to validate :return: Returns None if valid, the error log otherwise.

Source code in src/libsbgnpy/validator.py
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
def validate_xsd(f: Path) -> Any:
    """Validate SBGN file against XSD schema.

    :param f: file to validate
    :return: Returns None if valid, the error log otherwise.
    """
    xmlschema_doc = etree.parse(XSD_SCHEMA)
    xmlschema = etree.XMLSchema(xmlschema_doc)

    # with open(f, "r") as f_in:
    #     xml_str = f_in.read()
    #     # upconverting for fixing reading
    #     xml_str = xml_str.replace(
    #         "http://sbgn.org/libsbgn/0.1", "http://sbgn.org/libsbgn/0.3"
    #     )
    #     xml_str = xml_str.replace(
    #         "http://sbgn.org/libsbgn/0.2", "http://sbgn.org/libsbgn/0.3"
    #     )
    #
    # with tempfile.TemporaryFile(mode='w') as f_tmp:
    #   f_tmp.write(xml_str)

    doc = etree.parse(f)
    is_valid = xmlschema.validate(doc)
    if not is_valid:
        log = xmlschema.error_log
        sys.stderr.write(str(log) + "\n")
        return log

    return None

write_render_to_string(render_info)

Write RenderInformation to string.

Source code in src/libsbgnpy/io.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def write_render_to_string(render_info: RenderInformation) -> str:
    """Write RenderInformation to string."""
    config = SerializerConfig(
        indent="  ",
        xml_declaration=False,
    )
    context = XmlContext()
    serializer = XmlSerializer(context=context, config=config)
    xml_str = serializer.render(
        render_info,
        ns_map={
            # None: "http://www.sbml.org/sbml/level3/version1/render/version1"
        },
    )
    # FIXME: there must be a better solution to get rid of the namespaces
    xml_str = xml_str.replace("ns0:", "")
    xml_str = xml_str.replace(":ns0", "")
    # remove the xml header
    # xml_str = xml_str.replace('<?xml version="1.0" encoding="UTF-8"?>\n', "")
    return xml_str

write_sbgn_to_file(sbgn, f)

Write sbgn object to file.

:param sbgn: SBGN object :param f: file to write :return: None

Source code in src/libsbgnpy/io.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def write_sbgn_to_file(sbgn: Sbgn, f: Path) -> None:
    """Write sbgn object to file.

    :param sbgn: SBGN object
    :param f: file to write
    :return: None
    """
    # config = SerializerConfig(indent="  ")
    # context = XmlContext()
    # serializer = XmlSerializer(context=context, config=config)
    xml_str: str = write_sbgn_to_string(sbgn)

    with open(f, "w", encoding="utf-8") as f:
        f.write(xml_str)

write_sbgn_to_string(sbgn)

Write SBGN to string.

:param sbgn: sbgn object :return: SBGN xml string

Source code in src/libsbgnpy/io.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def write_sbgn_to_string(sbgn: Sbgn) -> str:
    """Write SBGN to string.

    :param sbgn: sbgn object
    :return: SBGN xml string
    """
    config = SerializerConfig(indent="  ")
    context = XmlContext()
    serializer = XmlSerializer(context=context, config=config)

    # bugfix for handling escapes in extensions
    xml_str = serializer.render(sbgn, ns_map={None: "http://sbgn.org/libsbgn/0.3"})
    xml_str = xml_str.replace("&lt;", "<")
    xml_str = xml_str.replace("&gt;", ">")

    return xml_str

libsbgnpy.sbgn

Arc dataclass

Bases: Sbgnbase

The arc element describes an SBGN arc between two SBGN nodes. It contains: For PD: an optional stoichiometry marker, For ER: an optional cardinality marker, zero or more ports (influence targets), and zero or more outcomes, a mandatory source and target (glyph or port), a geometric description of its whole path, from start to end. This path can involve any number of straight lines or quadratic/cubic Bezier curves.

:ivar glyph: In PD, an arc can contain a single optional sub-glyph. This glyph must be a stoichiometry marker (square with a numeric label) In ER, an arc can contain several sub-glyphs. This can be zero or one cardinality glyphs (e.g. cis or trans), plus zero to many outcome glyphs (black dot) :ivar port: Ports are only allowed in ER. :ivar start: The start element represents the starting point of the arc's path. It is unique and mandatory. :ivar next: The next element represents the next point in the arc's path. Between the start and the end of the path, there can be any number (even zero) of next elements (intermediate points). They are read consecutively: start, next, next, ..., next, end. When the path from the previous point to this point is not straight, this element also contains a list of control points (between 1 and 2) describing a Bezier curve (quadratic if 1 control point, cubic if 2) between the previous point and this point. :ivar end: The end element represents the ending point of the arc's path. It is unique and mandatory. When the path from the previous point to this point is not straight, this element also contains a list of control points (between 1 and 2) describing a Bezier curve (quadratic if 1 control point, cubic if 2) between the previous point and this point. :ivar class_value: The class attribute defines the semantic of the arc, and influences: the way that arc should be rendered, the overall syntactic validity of the map. The various classes encompass all possible types of SBGN arcs: production and consumption arcs, all types of modification arcs, logic arcs, equivalence arcs. To express a reversible reaction, use production arcs on both sides of the Process Node. :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. :ivar source: The source attribute can refer: either to the id of a glyph, or to the id of a port on a glyph. :ivar target: The target attribute can refer: either to the id of a glyph, or to the id of a port on a glyph.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Arc(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The arc element describes an SBGN arc between two SBGN nodes. It contains:
    <ns1:ul>
    <ns1:li>For PD: an optional stoichiometry marker,</ns1:li>
    <ns1:li>For ER: an optional cardinality marker,
    zero or more ports (influence targets), and zero or more outcomes,
    </ns1:li>
    <ns1:li>a mandatory source and target (glyph or port),</ns1:li>
    <ns1:li>a geometric description of its whole path, from start to end.</ns1:li>
    </ns1:ul>
    <ns1:p>
    </ns1:p>
    This path can involve any number of straight lines or quadratic/cubic Bezier
    curves.
    </ns1:p>

    :ivar glyph: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In PD,
        an arc can contain a single optional sub-glyph. This glyph must
        be a stoichiometry marker (square with a numeric label) </ns1:p>
        <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In ER, an arc
        can contain several sub-glyphs. This can be zero or one
        cardinality glyphs (e.g. cis or trans), plus zero to many
        outcome glyphs (black dot) </ns1:p>
    :ivar port: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> Ports
        are only allowed in ER. </ns1:p>
    :ivar start: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        start element represents the starting point of the arc's path.
        It is unique and mandatory. </ns1:p>
    :ivar next: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The next
        element represents the next point in the arc's path. Between the
        start and the end of the path, there can be any number (even
        zero) of next elements (intermediate points). They are read
        consecutively: start, next, next, ..., next, end. When the path
        from the previous point to this point is not straight, this
        element also contains a list of control points (between 1 and 2)
        describing a Bezier curve (quadratic if 1 control point, cubic
        if 2) between the previous point and this point. </ns1:p>
    :ivar end: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The end
        element represents the ending point of the arc's path. It is
        unique and mandatory. When the path from the previous point to
        this point is not straight, this element also contains a list of
        control points (between 1 and 2) describing a Bezier curve
        (quadratic if 1 control point, cubic if 2) between the previous
        point and this point. </ns1:p>
    :ivar class_value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The class attribute defines the semantic of the arc, and
        influences: <ns1:ul> <ns1:li>the way that arc should be
        rendered,</ns1:li> <ns1:li>the overall syntactic validity of the
        map.</ns1:li> </ns1:ul> </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The various classes
        encompass all possible types of SBGN arcs: <ns1:ul>
        <ns1:li>production and consumption arcs,</ns1:li> <ns1:li>all
        types of modification arcs,</ns1:li> <ns1:li>logic
        arcs,</ns1:li> <ns1:li>equivalence arcs.</ns1:li> </ns1:ul> To
        express a reversible reaction, use production arcs on both sides
        of the Process Node. </ns1:p>
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter.
        </ns1:p>
    :ivar source: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        source attribute can refer: <ns1:ul> <ns1:li>either to the id of
        a glyph,</ns1:li> <ns1:li>or to the id of a port on a
        glyph.</ns1:li> </ns1:ul> </ns1:p>
    :ivar target: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        target attribute can refer: <ns1:ul> <ns1:li>either to the id of
        a glyph,</ns1:li> <ns1:li>or to the id of a port on a
        glyph.</ns1:li> </ns1:ul> </ns1:p>
    """

    class Meta:
        name = "arc"
        namespace = "http://sbgn.org/libsbgn/0.3"

    glyph: list[Glyph] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    port: list[Port] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    start: Optional["Arc.Start"] = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    next: list["Arc.Next"] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    end: Optional["Arc.End"] = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    class_value: Optional[ArcClass] = field(
        default=None,
        metadata={
            "name": "class",
            "type": "Attribute",
            "required": True,
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    source: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    target: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

    @dataclass
    class Start:
        x: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        y: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

    @dataclass
    class Next:
        point: list[Point] = field(
            default_factory=list,
            metadata={
                "type": "Element",
                "max_occurs": 2,
            },
        )
        x: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        y: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

    @dataclass
    class End:
        point: list[Point] = field(
            default_factory=list,
            metadata={
                "type": "Element",
                "max_occurs": 2,
            },
        )
        x: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        y: Optional[float] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

Arcgroup dataclass

Bases: Sbgnbase

The arc group describes a set of arcs and glyphs that together have a relation. For example For ER: interaction arcs around an interaction glyph, ... Note that, in spite of the name, an arcgroup contains both arcs and glyphs.

:ivar glyph: An arcgroup can contain glyphs. For example, in an interaction arcgroup, there must be one interaction glyph. :ivar arc: An arcgroup can have multiple arcs. They are all assumed to form a single hyperarc-like structure. :ivar class_value: The class attribute defines the semantic of the arcgroup.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Arcgroup(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The arc group describes a set of arcs and glyphs that together have a relation.
    For example
    <ns1:ul>
    <ns1:li>For ER: interaction arcs around an interaction glyph,</ns1:li>
    <ns1:li>...</ns1:li>
    </ns1:ul>
    Note that, in spite of the name, an arcgroup contains both arcs and glyphs.
    </ns1:p>

    :ivar glyph: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> An
        arcgroup can contain glyphs. For example, in an interaction
        arcgroup, there must be one interaction glyph. </ns1:p>
    :ivar arc: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> An
        arcgroup can have multiple arcs. They are all assumed to form a
        single hyperarc-like structure. </ns1:p>
    :ivar class_value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The class attribute defines the semantic of the arcgroup.
        </ns1:p>
    """

    class Meta:
        name = "arcgroup"
        namespace = "http://sbgn.org/libsbgn/0.3"

    glyph: list[Glyph] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    arc: list[Arc] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    class_value: Optional[ArcgroupClass] = field(
        default=None,
        metadata={
            "name": "class",
            "type": "Attribute",
            "required": True,
        },
    )

Bbox dataclass

Bases: Sbgnbase

The bbox element describes a rectangle. This rectangle is defined by: PointAttributes corresponding to the 2D coordinates of the top left corner, width and height attributes. The rectangle corresponds to the outer bounding box of a shape. The shape itself can be irregular (for instance in the case of some compartments). In the case of process nodes, the bounding box only concerns the central glyph (square, or circle), the input/output ports are not included, and neither are the lines connecting them to the central glyph. A bbox is required for all glyphs, and is optional for labels.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Bbox(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The bbox element describes a rectangle. This rectangle is defined by:
    <ns1:ul>
    <ns1:li>
    PointAttributes corresponding to the 2D coordinates of the top left
    corner,
    </ns1:li>
    <ns1:li>width and height attributes.</ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The rectangle corresponds to the outer bounding box of a shape.
    The shape itself can be irregular
    (for instance in the case of some compartments).
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    In the case of process nodes,
    the bounding box only concerns the central glyph (square, or circle),
    the input/output ports are not included, and neither are the lines connecting
    them to the central glyph.
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    A bbox is required for all glyphs, and is optional for labels.
    </ns1:p>"""

    class Meta:
        name = "bbox"
        namespace = "http://sbgn.org/libsbgn/0.3"

    x: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    y: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    w: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    h: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Glyph dataclass

Bases: Sbgnbase

The glyph element is: either a stand-alone, high-level SBGN glyph (EPN, PN, compartment, etc), or a sub-glyph (state variable, unit of information, inside of a complex, ...) In the first case, it appears directly in the glyph list of the map. In the second case, it is a child of another glyph element.

:ivar label: :ivar state: The state element should only be used for state variables. It replaces the label element used for other glyphs. It describes the text to be drawn inside the state variable. A state must have a value, a variable, or both. If it has both, they are rendered as a concatenated string with @ in between. :ivar clone: The clone element (which is optional) means the glyph carries a clone marker. It can contain an optional label. :ivar callout: The callout element is only used for glyphs with class annotation. It contains the coordinate of the point where the annotation points to, as well as a reference to the element that is pointed to. :ivar entity: The entity is only used in activity flow diagrams. It can only be used on a unit of information glyph on a biological activity glyph, where it is compulsory. It is used to indicate the shape of this unit of information. :ivar bbox: The bbox element is mandatory and unique: exactly one per glyph. It defines the outer bounding box of the glyph. The actual shape of the glyph can be irregular (for instance in the case of some compartments) In the case of process nodes, the bounding box only concerns the central glyph (square, or circle): the input/output ports are not included, and neither are the lines connecting them to the central glyph. :ivar glyph: A glyph element can contain any number of children glyph elements. In practice, this should only happen in the following cases: a compartment with unit of information children, an EPN with states variables and/or unit of information children, a complex, with state variables, unit of info, and/or EPN children. :ivar port: :ivar class_value: The class attribute defines the semantic of the glyph, and influences: the way that glyph should be rendered, the overall syntactic validity of the map. The various classes encompass the following PD SBGN elements: Entity Pool Nodes (EPN), Process Nodes (PN), Logic Operator Nodes, Sub-glyphs on Nodes (State Variable, Unit of Information), Sub-glyphs on Arcs (Stoichiometry Label), Other glyphs (Compartment, Submap, Tag, Terminal). And the following ER SBGN elements Entities (Entity, Outcome) Other (Annotation, Phenotype) Auxiliary on glyps (Existence, Location) Auxiliary on arcs (Cardinality) Delay operator implicit xor :ivar orientation: The orientation attribute is used to express how to draw asymmetric glyphs. In PD, the orientation of Process Nodes is either horizontal or vertical. It refers to an (imaginary) line connecting the two in/out sides of the PN. In PD, the orientation of Tags and Terminals can be left, right, up or down. It refers to the direction the arrow side of the glyph is pointing at. :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. It is recommended to generate meaningless IDs (e.g. "glyph1234") and avoid IDs with a meaning (e.g. "epn_ethanol") :ivar compartment_ref: Reference to the ID of the compartment that this glyph is part of. Only use this if there is at least one explicit compartment present in the diagram. Compartments are only used in PD and AF, and thus this attribute as well. For PD, this should be used only for EPN's. For AF, this should be used only for Activity Nodes. In case there are no compartments, entities that can have a location, such as EPN's, are implicit member of an invisible compartment that encompasses the whole map. In that case, this attribute must be omitted. :ivar compartment_order: The compartment order attribute can be used to define a drawing order for compartments. It enables tools to draw compartments in the correct order especially in the case of overlapping compartments. Compartments are only used in PD and AF, and thus this attribute as well. The attribute is of type float, the attribute value has not to be unique. Compartments with higher compartment order are drawn on top. The attribute is optional and should only be used for compartments. :ivar map_ref: This attribute is only used on a submap glyph. It is required. Reference to the ID of the map which provides the content of the submap. If no map is available providing the content of the submap an omitted process should be used instead of the submap. Submaps are only used in PD and AF, and thus this attribute as well. :ivar tag_ref: This attribute is only used on a terminal glyph. It is required. Reference to the ID of a tag on a map providing the content of a submap. The terminal glyph is defined as sub-glyph of this submap. Submaps and therefore terminals are only used in PD and AF, and thus this attribute as well.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Glyph(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The glyph element is:
    <ns1:ul>
    <ns1:li>either a stand-alone, high-level SBGN glyph
    (EPN, PN, compartment, etc),
    </ns1:li>
    <ns1:li>or a sub-glyph
    (state variable, unit of information, inside of a complex, ...)
    </ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    In the first case, it appears directly in the glyph list of the map.
    In the second case, it is a child of another glyph element.
    </ns1:p>

    :ivar label:
    :ivar state: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        state element should only be used for state variables. It
        replaces the label element used for other glyphs. It describes
        the text to be drawn inside the state variable. </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> A state must have a
        value, a variable, or both. If it has both, they are rendered as
        a concatenated string with @ in between. </ns1:p>
    :ivar clone: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        clone element (which is optional) means the glyph carries a
        clone marker. It can contain an optional label. </ns1:p>
    :ivar callout: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        callout element is only used for glyphs with class annotation.
        It contains the coordinate of the point where the annotation
        points to, as well as a reference to the element that is pointed
        to. </ns1:p>
    :ivar entity: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        entity is only used in activity flow diagrams. It can only be
        used on a unit of information glyph on a biological activity
        glyph, where it is compulsory. It is used to indicate the shape
        of this unit of information. </ns1:p>
    :ivar bbox: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The bbox
        element is mandatory and unique: exactly one per glyph. It
        defines the outer bounding box of the glyph. The actual shape of
        the glyph can be irregular (for instance in the case of some
        compartments) </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In the case of process
        nodes, the bounding box only concerns the central glyph (square,
        or circle): the input/output ports are not included, and neither
        are the lines connecting them to the central glyph. </ns1:p>
    :ivar glyph: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> A glyph
        element can contain any number of children glyph elements. In
        practice, this should only happen in the following cases:
        <ns1:ul> <ns1:li>a compartment with unit of information
        children,</ns1:li> <ns1:li> an EPN with states variables and/or
        unit of information children, </ns1:li> <ns1:li> a complex, with
        state variables, unit of info, and/or EPN children. </ns1:li>
        </ns1:ul> </ns1:p>
    :ivar port:
    :ivar class_value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The class attribute defines the semantic of the glyph, and
        influences: <ns1:ul> <ns1:li>the way that glyph should be
        rendered,</ns1:li> <ns1:li>the overall syntactic validity of the
        map.</ns1:li> </ns1:ul> </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The various classes
        encompass the following PD SBGN elements: <ns1:ul>
        <ns1:li>Entity Pool Nodes (EPN),</ns1:li> <ns1:li>Process Nodes
        (PN),</ns1:li> <ns1:li>Logic Operator Nodes,</ns1:li>
        <ns1:li>Sub-glyphs on Nodes (State Variable, Unit of
        Information),</ns1:li> <ns1:li>Sub-glyphs on Arcs (Stoichiometry
        Label),</ns1:li> <ns1:li>Other glyphs (Compartment, Submap, Tag,
        Terminal).</ns1:li> </ns1:ul> And the following ER SBGN elements
        <ns1:ul> <ns1:li>Entities (Entity, Outcome)</ns1:li>
        <ns1:li>Other (Annotation, Phenotype)</ns1:li> <ns1:li>Auxiliary
        on glyps (Existence, Location)</ns1:li> <ns1:li>Auxiliary on
        arcs (Cardinality)</ns1:li> <ns1:li>Delay operator</ns1:li>
        <ns1:li>implicit xor</ns1:li> </ns1:ul> </ns1:p>
    :ivar orientation: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The orientation attribute is used to express how to draw
        asymmetric glyphs. In PD, the orientation of Process Nodes is
        either horizontal or vertical. It refers to an (imaginary) line
        connecting the two in/out sides of the PN. In PD, the
        orientation of Tags and Terminals can be left, right, up or
        down. It refers to the direction the arrow side of the glyph is
        pointing at. </ns1:p>
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter. It
        is recommended to generate meaningless IDs (e.g. "glyph1234")
        and avoid IDs with a meaning (e.g. "epn_ethanol") </ns1:p>
    :ivar compartment_ref: <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> Reference to the ID of
        the compartment that this glyph is part of. Only use this if
        there is at least one explicit compartment present in the
        diagram. Compartments are only used in PD and AF, and thus this
        attribute as well. For PD, this should be used only for EPN's.
        For AF, this should be used only for Activity Nodes. </ns1:p>
        <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> In case there
        are no compartments, entities that can have a location, such as
        EPN's, are implicit member of an invisible compartment that
        encompasses the whole map. In that case, this attribute must be
        omitted. </ns1:p>
    :ivar compartment_order: <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The compartment order
        attribute can be used to define a drawing order for
        compartments. It enables tools to draw compartments in the
        correct order especially in the case of overlapping
        compartments. Compartments are only used in PD and AF, and thus
        this attribute as well. </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The attribute is of
        type float, the attribute value has not to be unique.
        Compartments with higher compartment order are drawn on top. The
        attribute is optional and should only be used for compartments.
        </ns1:p>
    :ivar map_ref: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> This
        attribute is only used on a submap glyph. It is required.
        </ns1:p> <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Reference to the ID of the map which provides the content of the
        submap. If no map is available providing the content of the
        submap an omitted process should be used instead of the submap.
        Submaps are only used in PD and AF, and thus this attribute as
        well. </ns1:p>
    :ivar tag_ref: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> This
        attribute is only used on a terminal glyph. It is required.
        </ns1:p> <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Reference to the ID of a tag on a map providing the content of a
        submap. The terminal glyph is defined as sub-glyph of this
        submap. Submaps and therefore terminals are only used in PD and
        AF, and thus this attribute as well. </ns1:p>
    """

    class Meta:
        name = "glyph"
        namespace = "http://sbgn.org/libsbgn/0.3"

    label: Optional[Label] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    state: Optional["Glyph.State"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    clone: Optional["Glyph.Clone"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    callout: Optional["Glyph.Callout"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    entity: Optional["Glyph.Entity"] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    bbox: Optional[Bbox] = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    glyph: list["Glyph"] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    port: list[Port] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    class_value: Optional[GlyphClass] = field(
        default=None,
        metadata={
            "name": "class",
            "type": "Attribute",
            "required": True,
        },
    )
    orientation: GlyphOrientation = field(
        default=GlyphOrientation.HORIZONTAL,
        metadata={
            "type": "Attribute",
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    compartment_ref: Optional[str] = field(
        default=None,
        metadata={
            "name": "compartmentRef",
            "type": "Attribute",
        },
    )
    compartment_order: Optional[float] = field(
        default=None,
        metadata={
            "name": "compartmentOrder",
            "type": "Attribute",
        },
    )
    map_ref: Optional[str] = field(
        default=None,
        metadata={
            "name": "mapRef",
            "type": "Attribute",
        },
    )
    tag_ref: Optional[str] = field(
        default=None,
        metadata={
            "name": "tagRef",
            "type": "Attribute",
        },
    )

    @dataclass
    class Clone:
        label: Optional[Label] = field(
            default=None,
            metadata={
                "type": "Element",
            },
        )

    @dataclass
    class Callout:
        point: Optional[Point] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        target: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )

    @dataclass
    class Entity:
        name: Optional[EntityName] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )

    @dataclass
    class State:
        """
        :ivar value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
            value attribute represents the state of the variable. It can
            be: <ns1:ul> <ns1:li> either from a predefined set of string
            (P, S, etc.) which correspond to specific SBO terms (cf.
            SBGN specs), </ns1:li> <ns1:li> or any arbitrary string.
            </ns1:li> </ns1:ul> </ns1:p>
        :ivar variable: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
            The variable attribute describes the site where the
            modification described by the value attribute occurs. It is:
            <ns1:ul> <ns1:li> optional when there is only one state
            variable on the parent EPN, </ns1:li> <ns1:li> required when
            there is more than one state variable the parent EPN.
            </ns1:li> </ns1:ul> </ns1:p>
        """

        value: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )
        variable: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )

State dataclass

:ivar value: The value attribute represents the state of the variable. It can be: either from a predefined set of string (P, S, etc.) which correspond to specific SBO terms (cf. SBGN specs), or any arbitrary string. :ivar variable: The variable attribute describes the site where the modification described by the value attribute occurs. It is: optional when there is only one state variable on the parent EPN, required when there is more than one state variable the parent EPN.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class State:
    """
    :ivar value: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The
        value attribute represents the state of the variable. It can
        be: <ns1:ul> <ns1:li> either from a predefined set of string
        (P, S, etc.) which correspond to specific SBO terms (cf.
        SBGN specs), </ns1:li> <ns1:li> or any arbitrary string.
        </ns1:li> </ns1:ul> </ns1:p>
    :ivar variable: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The variable attribute describes the site where the
        modification described by the value attribute occurs. It is:
        <ns1:ul> <ns1:li> optional when there is only one state
        variable on the parent EPN, </ns1:li> <ns1:li> required when
        there is more than one state variable the parent EPN.
        </ns1:li> </ns1:ul> </ns1:p>
    """

    value: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    variable: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )

Label dataclass

Bases: Sbgnbase

The label element describes the text accompanying a glyph. The text attribute is mandatory. Its position can be specified by a bbox (optional). Tools are free to display the text in any style (font, font-size, etc.)

:ivar bbox: :ivar text: Multi- line labels are allowed. Line breaks are encoded as &#xA; as specified by the XML standard.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Label(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The label element describes the text accompanying a glyph.
    The text attribute is mandatory.
    Its position can be specified by a bbox (optional).
    Tools are free to display the text in any style (font, font-size, etc.)
    </ns1:p>

    :ivar bbox:
    :ivar text: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> Multi-
        line labels are allowed. Line breaks are encoded as &amp;#xA; as
        specified by the XML standard. </ns1:p>
    """

    class Meta:
        name = "label"
        namespace = "http://sbgn.org/libsbgn/0.3"

    bbox: Optional[Bbox] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    text: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Map dataclass

Bases: Sbgnbase

The map element describes a single SBGN PD map. It contains a list of glyph elements and a list of arc elements. These lists can be of any size (possibly empty).

:ivar bbox: The bbox element on a map is not mandatory, it allows the application to define a canvas, and at the same time define a whitespace margin around the glyphs. If a bbox is defined on a map, all glyphs and arcs must be inside this bbox, otherwise they could be clipped off by applications. :ivar glyph: :ivar arc: :ivar arcgroup: :ivar version: Version of the map: URI identifier that gives the language, level and version defined by SBGN. Different languages/levels/versions have different restrictions on the usage of sub-elements (that are not encoded in this schema but must be validated with an external validator) :ivar language: Language of the map: one of three sublanguages defined by SBGN. Different languages have different restrictions on the usage of sub-elements (that are not encoded in this schema but must be validated with an external validator) :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. It is recommended to generate meaningless IDs (e.g. "map1234") and avoid IDs with a meaning (e.g. "MAPK cascade")

Source code in src/libsbgnpy/sbgn.py
 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
@dataclass
class Map(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The map element describes a single SBGN PD map.
    It contains a list of glyph elements and a list of arc elements.
    These lists can be of any size (possibly empty).
    </ns1:p>

    :ivar bbox: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The bbox
        element on a map is not mandatory, it allows the application to
        define a canvas, and at the same time define a whitespace margin
        around the glyphs. </ns1:p> <ns1:p
        xmlns:ns1="http://sbgn.org/libsbgn/0.3"> If a bbox is defined on
        a map, all glyphs and arcs must be inside this bbox, otherwise
        they could be clipped off by applications. </ns1:p>
    :ivar glyph:
    :ivar arc:
    :ivar arcgroup:
    :ivar version: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Version of the map: URI identifier that gives the language,
        level and version defined by SBGN. Different
        languages/levels/versions have different restrictions on the
        usage of sub-elements (that are not encoded in this schema but
        must be validated with an external validator) </ns1:p>
    :ivar language: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        Language of the map: one of three sublanguages defined by SBGN.
        Different languages have different restrictions on the usage of
        sub-elements (that are not encoded in this schema but must be
        validated with an external validator) </ns1:p>
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter. It
        is recommended to generate meaningless IDs (e.g. "map1234") and
        avoid IDs with a meaning (e.g. "MAPK cascade") </ns1:p>
    """

    class Meta:
        name = "map"
        namespace = "http://sbgn.org/libsbgn/0.3"

    bbox: Optional[Bbox] = field(
        default=None,
        metadata={
            "type": "Element",
        },
    )
    glyph: list[Glyph] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    arc: list[Arc] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    arcgroup: list[Arcgroup] = field(
        default_factory=list,
        metadata={
            "type": "Element",
        },
    )
    version: Optional[MapVersion] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    language: Optional[MapLanguage] = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Point dataclass

Bases: Sbgnbase

The point element is characterized by PointAttributes, which describe absolute 2D cartesian coordinates. Namely: x (horizontal, from left to right), y (vertical, from top to bottom). The origin is located in the top-left corner of the map. There is no unit: proportions must be preserved, but the maps can be drawn at any scale. In the test files examples, to obtain a drawing similar to the reference .png file, values in the corresponding .sbgn file should be read as pixels.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Point(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The point element is characterized by PointAttributes,
    which describe absolute 2D cartesian coordinates. Namely:
    <ns1:ul>
    <ns1:li>x (horizontal, from left to right),</ns1:li>
    <ns1:li>y (vertical, from top to bottom).</ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The origin is located in the top-left corner of the map.
    There is no unit:
    proportions must be preserved, but the maps can be drawn at any scale.
    In the test files examples, to obtain a drawing similar to the reference
    *.png file, values in the corresponding *.sbgn file should be read as pixels.
    </ns1:p>"""

    class Meta:
        name = "point"
        namespace = "http://sbgn.org/libsbgn/0.3"

    x: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    y: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Port dataclass

Bases: Sbgnbase

The port element describes an anchor point to which arcs can refer as a source or target. It consists of: absolute 2D cartesian coordinates (PointAttribute), a unique id attribute. Two port elements are required for process nodes. They represent the extremity of the two "arms" which protrude on both sides of the core of the glyph (= square or circle shape). Other glyphs don't need ports (but can use them if desired).

:ivar x: :ivar y: :ivar id: The xsd:ID type is an alphanumeric identifier, starting with a letter. Port IDs often contain the ID of their glyph, followed by a local port number (e.g. glyph4.1, glyph4.2, etc.) However, this style convention is not mandatory, and IDs should never be interpreted as carrying any meaning.

Source code in src/libsbgnpy/sbgn.py
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
@dataclass
class Port(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The port element describes an anchor point to which arcs can refer
    as a source or target. It consists of:
    <ns1:ul>
    <ns1:li>absolute 2D cartesian coordinates (PointAttribute),</ns1:li>
    <ns1:li>a unique id attribute.</ns1:li>
    </ns1:ul>
    </ns1:p>
    <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    Two port elements are required for process nodes. They represent
    the extremity of the two "arms" which protrude on both sides of the
    core of the glyph (= square or circle shape).
    Other glyphs don't need ports (but can use them if desired).
    </ns1:p>

    :ivar x:
    :ivar y:
    :ivar id: <ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3"> The xsd:ID
        type is an alphanumeric identifier, starting with a letter. Port
        IDs often contain the ID of their glyph, followed by a local
        port number (e.g. glyph4.1, glyph4.2, etc.) However, this style
        convention is not mandatory, and IDs should never be interpreted
        as carrying any meaning. </ns1:p>
    """

    class Meta:
        name = "port"
        namespace = "http://sbgn.org/libsbgn/0.3"

    x: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    y: Optional[float] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    id: Optional[str] = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )

Sbgn dataclass

Bases: Sbgnbase

The sbgn element is the root of any SBGNML document. Currently each document must contain exactly one map element.

Source code in src/libsbgnpy/sbgn.py
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
@dataclass
class Sbgn(Sbgnbase):
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The sbgn element is the root of any SBGNML document.
    Currently each document must contain exactly one map element.
    </ns1:p>"""

    class Meta:
        name = "sbgn"
        namespace = "http://sbgn.org/libsbgn/0.3"

    map: list[Map] = field(
        default_factory=list,
        metadata={
            "type": "Element",
            "min_occurs": 1,
        },
    )

Sbgnbase dataclass

The SBGNBase type is the base type of all main components in SBGN. It supports attaching notes and extensions to components, with metadata and annotations encoded in the extension element.

Source code in src/libsbgnpy/sbgn.py
 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
@dataclass
class Sbgnbase:
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The SBGNBase type is the base type of all main components in SBGN.
    It supports attaching notes and extensions to components, with
    metadata and annotations encoded in the extension element.
    </ns1:p>"""

    class Meta:
        name = "SBGNBase"

    notes: Optional["Sbgnbase.Notes"] = field(
        default=None,
        metadata={
            "type": "Element",
            "namespace": "http://sbgn.org/libsbgn/0.3",
        },
    )
    extension: Optional["Sbgnbase.Extension"] = field(
        default=None,
        metadata={
            "type": "Element",
            "namespace": "http://sbgn.org/libsbgn/0.3",
        },
    )

    @dataclass
    class Notes:
        """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The notes element stores notes.
        </ns1:p>"""

        w3_org_1999_xhtml_element: list[object] = field(
            default_factory=list,
            metadata={
                "type": "Wildcard",
                "namespace": "http://www.w3.org/1999/xhtml",
                "process_contents": "skip",
            },
        )

    @dataclass
    class Extension:
        """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
        The extension element stores extension information like
        render information, metadata or annotations.
        </ns1:p>"""

        any_element: list[object] = field(
            default_factory=list,
            metadata={
                "type": "Wildcard",
                "namespace": "##any",
                "process_contents": "skip",
            },
        )

Extension dataclass

The extension element stores extension information like render information, metadata or annotations.

Source code in src/libsbgnpy/sbgn.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@dataclass
class Extension:
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The extension element stores extension information like
    render information, metadata or annotations.
    </ns1:p>"""

    any_element: list[object] = field(
        default_factory=list,
        metadata={
            "type": "Wildcard",
            "namespace": "##any",
            "process_contents": "skip",
        },
    )

Notes dataclass

The notes element stores notes.

Source code in src/libsbgnpy/sbgn.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@dataclass
class Notes:
    """<ns1:p xmlns:ns1="http://sbgn.org/libsbgn/0.3">
    The notes element stores notes.
    </ns1:p>"""

    w3_org_1999_xhtml_element: list[object] = field(
        default_factory=list,
        metadata={
            "type": "Wildcard",
            "namespace": "http://www.w3.org/1999/xhtml",
            "process_contents": "skip",
        },
    )

libsbgnpy.image

Helper functions for rendering SBGN images.

Uses the webservice provided by Frank Bergmann at "http://sysbioapps.dyndns.org/Layout/GenerateImage". For documentation see http://sysbioapps.spdns.org/Layout

render_sbgn(sbgn, image_file, file_format='png')

Render given sbgn object to image.

Supports the following file_formats: "png" The image file must end in .file_format, e.g. in '.png'

Performs a request analogue to: curl -X POST -F file=@"BorisEJB.xml" http://sysbioapps.spdns.org/Layout/GenerateImage -o out.png

:param sbgn: sbgn object :param image_file: image to create :return: None

Source code in src/libsbgnpy/image.py
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
def render_sbgn(sbgn: libsbgn.Sbgn, image_file: Path, file_format: str = "png") -> None:
    """Render given sbgn object to image.

    Supports the following file_formats: "png"
    The image file must end in .file_format, e.g. in '.png'

    Performs a request analogue to:
    curl -X POST -F file=@"BorisEJB.xml" http://sysbioapps.spdns.org/Layout/GenerateImage -o out.png

    :param sbgn: sbgn object
    :param image_file: image to create
    :return: None
    """
    if file_format != "png":
        raise ValueError("Only png rendering supported.")

    if not str(image_file).endswith(f".{file_format}"):
        raise ValueError(
            "The filename must end in <.file_format>, e.g. for png it must end in <.png>."
        )

    # Create temporary file for request
    with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp_dir:
        f_in: Path = Path(tmp_dir) / "render.sbgn"
        io.write_sbgn_to_file(sbgn, f_in)

        # Call webservice for rendering
        files = [
            ("file", open(f_in, "rb")),
        ]
        r = requests.post(f"{RENDER_URL}/GenerateImage", files=files)

        r.raise_for_status()

        with open(image_file, "wb") as fd:
            for chunk in r.iter_content(chunk_size=128):
                fd.write(chunk)
            fd.close()

        print("SBGN rendered:", image_file)

libsbgnpy.render

libsbgnpy.io

Helper functions to work with SBGN.

read_render_from_string(xml_str)

Read RenderInformation from string.

Source code in src/libsbgnpy/io.py
106
107
108
109
def read_render_from_string(xml_str: str) -> RenderInformation:
    """Read RenderInformation from string."""
    parser = XmlParser()
    return parser.from_string(xml_str, RenderInformation)

read_sbgn_from_file(f)

Read an sbgn file (without validating against the schema).

:param silence: display no information :param f: file to read :return: parsed SBGN :rtype:

Source code in src/libsbgnpy/io.py
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
def read_sbgn_from_file(f: Path) -> Sbgn:
    """Read an sbgn file (without validating against the schema).

    :param silence: display no information
    :param f: file to read
    :return: parsed SBGN
    :rtype:
    """
    with open(f, "r", encoding="utf-8") as f_in:
        xml_str = f_in.read()
        # upconverting for fixing reading
        xml_str = xml_str.replace(
            "http://sbgn.org/libsbgn/0.1", "http://sbgn.org/libsbgn/0.3"
        )
        xml_str = xml_str.replace(
            "http://sbgn.org/libsbgn/0.2", "http://sbgn.org/libsbgn/0.3"
        )

    parser = XmlParser()
    try:
        sbgn = parser.from_string(xml_str, Sbgn)
    except xsdata.exceptions.ParserError as err:
        logger.error(f"Could not parse SBGN file: '{f}'")
        logger.error(err)
        logger.error(f"\n{xml_str}")

    # sbgn = parser.parse(f, Sbgn)
    return sbgn

write_render_to_string(render_info)

Write RenderInformation to string.

Source code in src/libsbgnpy/io.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def write_render_to_string(render_info: RenderInformation) -> str:
    """Write RenderInformation to string."""
    config = SerializerConfig(
        indent="  ",
        xml_declaration=False,
    )
    context = XmlContext()
    serializer = XmlSerializer(context=context, config=config)
    xml_str = serializer.render(
        render_info,
        ns_map={
            # None: "http://www.sbml.org/sbml/level3/version1/render/version1"
        },
    )
    # FIXME: there must be a better solution to get rid of the namespaces
    xml_str = xml_str.replace("ns0:", "")
    xml_str = xml_str.replace(":ns0", "")
    # remove the xml header
    # xml_str = xml_str.replace('<?xml version="1.0" encoding="UTF-8"?>\n', "")
    return xml_str

write_sbgn_to_file(sbgn, f)

Write sbgn object to file.

:param sbgn: SBGN object :param f: file to write :return: None

Source code in src/libsbgnpy/io.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def write_sbgn_to_file(sbgn: Sbgn, f: Path) -> None:
    """Write sbgn object to file.

    :param sbgn: SBGN object
    :param f: file to write
    :return: None
    """
    # config = SerializerConfig(indent="  ")
    # context = XmlContext()
    # serializer = XmlSerializer(context=context, config=config)
    xml_str: str = write_sbgn_to_string(sbgn)

    with open(f, "w", encoding="utf-8") as f:
        f.write(xml_str)

write_sbgn_to_string(sbgn)

Write SBGN to string.

:param sbgn: sbgn object :return: SBGN xml string

Source code in src/libsbgnpy/io.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def write_sbgn_to_string(sbgn: Sbgn) -> str:
    """Write SBGN to string.

    :param sbgn: sbgn object
    :return: SBGN xml string
    """
    config = SerializerConfig(indent="  ")
    context = XmlContext()
    serializer = XmlSerializer(context=context, config=config)

    # bugfix for handling escapes in extensions
    xml_str = serializer.render(sbgn, ns_map={None: "http://sbgn.org/libsbgn/0.3"})
    xml_str = xml_str.replace("&lt;", "<")
    xml_str = xml_str.replace("&gt;", ">")

    return xml_str

libsbgnpy.validator

Validation of SBGN files against the schema is implemented.

Issue

Bases: object

Describes one issue found during schematron validation. One validation run may produce multiple issues.

Source code in src/libsbgnpy/validator.py
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
class Issue(object):
    """
    Describes one issue found during schematron validation.
    One validation run may produce multiple issues.
    """

    def __init__(self, role, rule_id, diagnostic_id, message):
        self.message = message.strip()
        self.diagnostic_id = diagnostic_id
        self.rule_id = rule_id
        if role.lower() == "error":
            self.severity = Severity.ERROR
        else:
            self.severity = Severity.WARNING

    def get_severity(self):
        """Severity of the issue, i.e.: is it an error, or a warning?"""
        return self.severity

    def get_message(self):
        """Human readable description of the issue."""
        return self.message

    def get_diagnostic_id(self):
        """Identifier of the element that this issue is about."""
        return self.diagnostic_id

    def get_rule_id(self):
        """Identifier of the issue"""
        return self.rule_id

    def __str__(self):
        return "{} at diagnosticId={}; ruleId={} Message: {}".format(
            self.severity, self.diagnostic_id, self.rule_id, self.message
        )

get_diagnostic_id()

Identifier of the element that this issue is about.

Source code in src/libsbgnpy/validator.py
74
75
76
def get_diagnostic_id(self):
    """Identifier of the element that this issue is about."""
    return self.diagnostic_id

get_message()

Human readable description of the issue.

Source code in src/libsbgnpy/validator.py
70
71
72
def get_message(self):
    """Human readable description of the issue."""
    return self.message

get_rule_id()

Identifier of the issue

Source code in src/libsbgnpy/validator.py
78
79
80
def get_rule_id(self):
    """Identifier of the issue"""
    return self.rule_id

get_severity()

Severity of the issue, i.e.: is it an error, or a warning?

Source code in src/libsbgnpy/validator.py
66
67
68
def get_severity(self):
    """Severity of the issue, i.e.: is it an error, or a warning?"""
    return self.severity

validate_xsd(f)

Validate SBGN file against XSD schema.

:param f: file to validate :return: Returns None if valid, the error log otherwise.

Source code in src/libsbgnpy/validator.py
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
def validate_xsd(f: Path) -> Any:
    """Validate SBGN file against XSD schema.

    :param f: file to validate
    :return: Returns None if valid, the error log otherwise.
    """
    xmlschema_doc = etree.parse(XSD_SCHEMA)
    xmlschema = etree.XMLSchema(xmlschema_doc)

    # with open(f, "r") as f_in:
    #     xml_str = f_in.read()
    #     # upconverting for fixing reading
    #     xml_str = xml_str.replace(
    #         "http://sbgn.org/libsbgn/0.1", "http://sbgn.org/libsbgn/0.3"
    #     )
    #     xml_str = xml_str.replace(
    #         "http://sbgn.org/libsbgn/0.2", "http://sbgn.org/libsbgn/0.3"
    #     )
    #
    # with tempfile.TemporaryFile(mode='w') as f_tmp:
    #   f_tmp.write(xml_str)

    doc = etree.parse(f)
    is_valid = xmlschema.validate(doc)
    if not is_valid:
        log = xmlschema.error_log
        sys.stderr.write(str(log) + "\n")
        return log

    return None