func ParseRhea(rheaBytes []byte) (Rhea, error) {
	var err error
	// Read rheaBytes into a Rdf object
	var rdf Rdf
	err = xml.Unmarshal(rheaBytes, &rdf)
	if err != nil {
		return Rhea{}, err
	}

	// Initialize Rhea
	var rhea Rhea
	compoundParticipantMap := make(map[string]string)
	compoundMap := make(map[string]Compound)

	for _, description := range rdf.Descriptions {
		// Handle the case of a single compound -> reactive part, such as
		// <rdf:Description rdf:about="http://rdf.rhea-db.org/Compound_10594">
		// 	<rh:reactivePart rdf:resource="http://rdf.rhea-db.org/Compound_10594_rp2"/>
		// </rdf:Description>
		if (len(description.Subclass) == 0) && (description.ReactivePartXML.Resource != "") {
			compoundParticipantMap[description.ReactivePartXML.Resource] = description.About
		}
		if description.Compound.Resource != "" {
			compoundParticipantMap[description.About] = description.Compound.Resource
		}

		for _, subclass := range description.Subclass {
			switch subclass.Resource {
			case "http://rdf.rhea-db.org/BidirectionalReaction", "http://rdf.rhea-db.org/DirectionalReaction":
				newReaction := NewReaction(description, subclass)
				rhea.Reactions = append(rhea.Reactions, newReaction)
			case "http://rdf.rhea-db.org/SmallMolecule", "http://rdf.rhea-db.org/Polymer", "http://rdf.rhea-db.org/GenericPolypeptide", "http://rdf.rhea-db.org/GenericPolynucleotide", "http://rdf.rhea-db.org/GenericHeteropolysaccharide":
				newCompound := NewCompound(description, subclass)
				if subclass.Resource == "http://rdf.rhea-db.org/SmallMolecule" || subclass.Resource == "http://rdf.rhea-db.org/Polymer" {
					rhea.Compounds = append(rhea.Compounds, newCompound)
				} else {
					compoundMap[description.About] = newCompound
					compoundParticipantMap[description.ReactivePartXML.Resource] = description.About
				}
			}
		}
	}

	// Go back and get the ReactiveParts
	for _, description := range rdf.Descriptions {
		for _, subclass := range description.Subclass {
			if subclass.Resource == "http://rdf.rhea-db.org/ReactivePart" {
				newCompound, ok := compoundMap[compoundParticipantMap[description.About]]
				if ok != true {
					return Rhea{}, errors.New("Could not find " + description.About)
				}
				newCompound.ID = description.ID
				newCompound.CompoundAccession = description.About
				newCompound.Position = description.Position
				newCompound.Name = description.Name
				newCompound.HTMLName = description.HTMLName
				newCompound.Formula = description.Formula
				newCompound.Charge = description.Charge
				newCompound.ChEBI = description.ChEBI.Resource
				rhea.Compounds = append(rhea.Compounds, newCompound)
			}
		}
		for _, containsx := range description.ContainsX {
			if !strings.Contains(containsx.XMLName.Local, "contains") {
				continue
			}
			newReactionParticipant, err := NewReactionParticipant(description, containsx, compoundParticipantMap)
			if err != nil {
				return Rhea{}, err
			}
			rhea.ReactionParticipants = append(rhea.ReactionParticipants, newReactionParticipant)
		}
	}
	return rhea, nil
}
// ParseRhea parses a list of bytes into a higher-level Rhea Struct.
ParseRhea parses a list of bytes into a higher-level Rhea Struct.
// ParseRhea parses a list of bytes into a higher - level Rhea Struct .
func ParseRhea(rheaBytes []byte) (Rhea, error) {
	var err error
	var rdf Rdf
	err = xml.Unmarshal(rheaBytes, &rdf)
	if err != nil {
		return Rhea{}, err
	}
	var rhea Rhea
	compoundParticipantMap := make(map[string]string)
	compoundMap := make(map[string]Compound)
	for _, description := range rdf.Descriptions {
		if (len(description.Subclass) == 0) && (description.ReactivePartXML.Resource != "") {
			compoundParticipantMap[description.ReactivePartXML.Resource] = description.About
		}
		if description.Compound.Resource != "" {
			compoundParticipantMap[description.About] = description.Compound.Resource
		}
		for _, subclass := range description.Subclass {
			switch subclass.Resource {
			case "http://rdf.rhea-db.org/BidirectionalReaction", "http://rdf.rhea-db.org/DirectionalReaction":
				newReaction := NewReaction(description, subclass)
				rhea.Reactions = append(rhea.Reactions, newReaction)
			case "http://rdf.rhea-db.org/SmallMolecule", "http://rdf.rhea-db.org/Polymer", "http://rdf.rhea-db.org/GenericPolypeptide", "http://rdf.rhea-db.org/GenericPolynucleotide", "http://rdf.rhea-db.org/GenericHeteropolysaccharide":
				newCompound := NewCompound(description, subclass)
				if subclass.Resource == "http://rdf.rhea-db.org/SmallMolecule" || subclass.Resource == "http://rdf.rhea-db.org/Polymer" {
					rhea.Compounds = append(rhea.Compounds, newCompound)
				} else {
					compoundMap[description.About] = newCompound
					compoundParticipantMap[description.ReactivePartXML.Resource] = description.About
				}
			}
		}
	}
	for _, description := range rdf.Descriptions {
		for _, subclass := range description.Subclass {
			if subclass.Resource == "http://rdf.rhea-db.org/ReactivePart" {
				newCompound, ok := compoundMap[compoundParticipantMap[description.About]]
				if ok != true {
					return Rhea{}, errors.New("Could not find " + description.About)
				}
				newCompound.ID = description.ID
				newCompound.CompoundAccession = description.About
				newCompound.Position = description.Position
				newCompound.Name = description.Name
				newCompound.HTMLName = description.HTMLName
				newCompound.Formula = description.Formula
				newCompound.Charge = description.Charge
				newCompound.ChEBI = description.ChEBI.Resource
				rhea.Compounds = append(rhea.Compounds, newCompound)
			}
		}
		for _, containsx := range description.ContainsX {
			if !strings.Contains(containsx.XMLName.Local, "contains") {
				continue
			}
			newReactionParticipant, err := NewReactionParticipant(description, containsx, compoundParticipantMap)
			if err != nil {
				return Rhea{}, err
			}
			rhea.ReactionParticipants = append(rhea.ReactionParticipants, newReactionParticipant)
		}
	}
	return rhea, nil
}
func ParseRhea ( rheaBytes [ ] byte ) ( Rhea , error ) { var err error var rdf Rdf err = xml . Unmarshal ( rheaBytes , & rdf ) if err != nil { return Rhea { } , err } var rhea Rhea compoundParticipantMap := make ( map [ string ] string ) compoundMap := make ( map [ string ] Compound ) for _ , description := range rdf . Descriptions { if ( len ( description . Subclass ) == 0 ) && ( description . ReactivePartXML . Resource != " " ) { compoundParticipantMap [ description . ReactivePartXML . Resource ] = description . About } if description . Compound . Resource != " " { compoundParticipantMap [ description . About ] = description . Compound . Resource } for _ , subclass := range description . Subclass { switch subclass . Resource { case " " , " " : newReaction := NewReaction ( description , subclass ) rhea . Reactions = append ( rhea . Reactions , newReaction ) case " " , " " , " " , " " , " " : newCompound := NewCompound ( description , subclass ) if subclass . Resource == " " || subclass . Resource == " " { rhea . Compounds = append ( rhea . Compounds , newCompound ) } else { compoundMap [ description . About ] = newCompound compoundParticipantMap [ description . ReactivePartXML . Resource ] = description . About } } } } for _ , description := range rdf . Descriptions { for _ , subclass := range description . Subclass { if subclass . Resource == " " { newCompound , ok := compoundMap [ compoundParticipantMap [ description . About ] ] if ok != true { return Rhea { } , errors . New ( " " + description . About ) } newCompound . ID = description . ID newCompound . CompoundAccession = description . About newCompound . Position = description . Position newCompound . Name = description . Name newCompound . HTMLName = description . HTMLName newCompound . Formula = description . Formula newCompound . Charge = description . Charge newCompound . ChEBI = description . ChEBI . Resource rhea . Compounds = append ( rhea . Compounds , newCompound ) } } for _ , containsx := range description . ContainsX { if ! strings . Contains ( containsx . XMLName . Local , " " ) { continue } newReactionParticipant , err := NewReactionParticipant ( description , containsx , compoundParticipantMap ) if err != nil { return Rhea { } , err } rhea . ReactionParticipants = append ( rhea . ReactionParticipants , newReactionParticipant ) } } return rhea , nil }
ParseRhea parses a list of bytes into a higher-level Rhea Struct.
ParseRhea parses a list of bytes into a higher - level Rhea Struct .
// Read rheaBytes into a Rdf object // Initialize Rhea // Handle the case of a single compound -> reactive part, such as // <rdf:Description rdf:about="http://rdf.rhea-db.org/Compound_10594"> // 	<rh:reactivePart rdf:resource="http://rdf.rhea-db.org/Compound_10594_rp2"/> // </rdf:Description> // Go back and get the ReactiveParts