@@ -737,16 +737,94 @@ function parseEntry($lfile)
737737 fclose ($ fp );
738738 }
739739
740- // php runparser.php parser=kegg files=pathway
741740 function parseKGML ($ lfile )
742741 {
743- // read XML
744-
745- // iterate over relations
746-
747-
748- // write rdf
742+ $ pathway = simplexml_load_file ($ lfile ) or die ("Error: Cannot create object " );
743+ $ pathway_id = str_replace ("path " ,"kegg " ,$ pathway ['name ' ]);
744+ $ base_id = str_replace ("kegg " ,"kegg_resource " ,$ pathway_id ).". " ;
745+
746+ parent ::addRDF (
747+ parent ::describeIndividual ($ pathway_id , $ pathway ['title ' ], parent ::getVoc ()."Pathway " ).
748+ parent ::triplify ($ pathway_id , "rdfs:seeAlso " , $ pathway ['link ' ]).
749+ parent ::triplify ($ pathway_id , "foaf:depiction " , $ pathway ['image ' ])
750+ );
749751
752+ // get the entries
753+ foreach ($ pathway ->children () as $ type => $ item ) {
754+ if ($ type == "entry " ) {
755+ $ eid = $ base_id .$ item ['id ' ];
756+ $ entries [ "" .$ item ['id ' ]] = "" .$ item ['name ' ];
757+
758+ parent ::addRDF (
759+ parent ::describeIndividual ($ eid , $ item ['name ' ], parent ::getVoc ()."Ortholog-Group " ).
760+ parent ::describeClass (parent ::getVoc ()."Ortholog-Group " , "KEGG Ortholog Group " )
761+ );
762+ $ mids = explode (" " ,$ item ['name ' ]);
763+ foreach ($ mids AS $ mid ) {
764+ if ($ item ['type ' ] == 'path ' ) $ mid = str_replace ($ mid ,": " ,"_ " );
765+ else {
766+ $ mid = substr ($ mid , strpos ($ mid ,": " )+1 );
767+ }
768+
769+ parent ::addRDF (
770+ parent ::triplify ($ eid , parent ::getVoc ()."member " , "kegg: " .$ mid )
771+ );
772+ }
773+ }
774+ }
775+
776+ // iterate over the relations, reactions
777+ foreach ($ pathway ->children () as $ type => $ item ) {
778+ if ($ type == "relation " ) {
779+ /*
780+ <relation entry1="70" entry2="73" type="ECrel">
781+ <subtype name="compound" value="86"/>
782+ </relation>
783+ <relation entry1="26" entry2="25" type="PPrel">
784+ <subtype name="compound" value="17"/>
785+ <subtype name="activation" value="-->"/>
786+ </relation>
787+ */
788+ $ id1 = "" .$ item ['entry1 ' ]; $ id2 = "" .$ item ['entry2 ' ];$ type = "" .$ type ;
789+ $ relation_id = str_replace ("kegg " ,"kegg_resource " ,$ pathway_id ).". " .$ id1 .". " .$ id2 .". " .$ type ;
790+ $ label = $ type ." relation between " .$ entries [ $ id1 ]. " and " .$ entries [ $ id2 ];
791+
792+ parent ::addRDF (
793+ parent ::describeIndividual ($ relation_id , $ label , parent ::getVoc ()."Pathway-Relation " ).
794+ parent ::describeClass (parent ::getVoc ()."Pathway-Relation " ,"KEGG Pathway Relation " ).
795+ parent ::triplify ($ relation_id , parent ::getVoc ()."source " , $ base_id .$ id1 ).
796+ parent ::triplify ($ relation_id , parent ::getVoc ()."target " , $ base_id .$ id2 ).
797+ parent ::triplifyString ($ relation_id , parent ::getVoc ()."type " , $ item ['type ' ])
798+ );
799+ foreach ($ item ->children () as $ subtype ) {
800+ parent ::addRDF (
801+ parent ::triplifyString ($ relation_id , parent ::getVoc ()."subtype " , '' .$ subtype ['name ' ])
802+ );
803+ }
804+
805+ } else if ($ type == "reaction " ) {
806+ /* <reaction id="133" name="rn:R09085" type="irreversible">
807+ <substrate id="86" name="cpd:C00267"/>
808+ <product id="90" name="cpd:C00668"/>
809+ </reaction>
810+ */
811+ $ reaction_id = str_replace ("kegg " ,"kegg_resource " ,$ pathway_id ).". " .substr ($ item ['name ' ], strpos ($ item ['name ' ],": " )+1 );
812+ $ reaction_type = parent ::getVoc ().ucfirst ($ item ['type ' ])."-Reaction " ;
813+ parent ::addRDF (
814+ parent ::describeIndividual ($ reaction_id , $ item ['name ' ], parent ::getVoc ()."Reaction " ).
815+ parent ::describeClass (parent ::getVoc ()."Reaction " , "KEGG Reaction " ).
816+ parent ::triplify ($ reaction_id , "rdf:type " , $ reaction_type )
817+ );
818+
819+ foreach ($ item ->children () AS $ k => $ v ) {
820+ $ cid = str_replace ("cpd: " ,"kegg: " ,$ v ['name ' ]);
821+ parent ::addRDF (
822+ parent ::triplify ($ reaction_id , parent ::getVoc ().$ k , $ cid )
823+ );
824+ }
825+ }
826+ }
827+ return ;
750828 }
751829}
752830
0 commit comments