Bio-Chaos

 view release on metacpan or  search on metacpan

xsl/chado-insert-macros.xsl  view on Meta::CPAN

<?xml version="1.0" encoding="utf-8"?>

<!-- Creates macros for repeated cv, cvterm and organism elements -->

<!-- All macros must be fully expanded before using this -->

<!-- Macro IDs correspond to unique key constraints in chado db -->
<!-- UK constraints are combined using double-underscore: '__' -->

<!-- NOTES: This transform uses some fairly advanced XSL concepts -->
<!-- (this is necessary for determining uniqueness of cvterms) -->

<!-- If you are inexperienced with XSL you may wish to look at -->
<!-- some of the other XSL files in this directory -->

<!-- AUTHOR: Chris Mungall  cjm at fruitfly dot org  -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output indent="yes" method="xml"/>

  <!-- INDEXES -->
  <!-- create an index of every element by its database unique key -->

  <!-- ORGANISM INDEX -->
  <xsl:key name="k-organism_id" match="//organism_id[*]" use="concat(organism/genus,'__',organism/species)"/>
  <!-- DB INDEX -->
  <xsl:key name="k-db_id" match="//db_id[*]" use="db/name"/>
  <!-- CV INDEX -->
  <xsl:key name="k-cv_id" match="//cv_id[*]" use="cv/name"/>
  <!-- CVTERM-BY-TYPE_ID INDEX -->
  <xsl:key name="k-type_id" match="//type_id[*]" use="concat(cvterm/cv_id/cv/name,'__',cvterm/name)"/>

  <!-- UNIQUE NODESETS -->
  <!-- create a unique instance of each macroifyable element -->
  
  <!-- DISTINCT ORGANISMs -->
  <xsl:variable 
    name="u-organism_id"
    select="//organism_id[generate-id(.)=generate-id(key('k-organism_id',concat(organism/genus,'__',organism/species))[1])]"/>

  <!-- DISTINCT CVTERMs (by type_id) -->
  <xsl:variable 
    name="u-type_id"
    select="//type_id[generate-id(.)=generate-id(key('k-type_id',concat(cvterm/cv_id/cv/name,'__',cvterm/name))[1])]"/>

  <!-- DISTINCT CVs -->
  <xsl:variable 
    name="u-cv_id"
    select="//cv_id[generate-id(.)=generate-id(key('k-cv_id',cv/name)[1])]"/>

  <!-- DISTINCT DBs -->
  <xsl:variable 
    name="u-db_id"
    select="//db_id[generate-id(.)=generate-id(key('k-db_id',db/name)[1])]"/>

  <!-- ** TEMPLATES ** -->

  <!-- INITIAL MATCH -->
  <xsl:template match="/chado">
    <xsl:if test="count(//*[@id])">
      <xsl:message terminate="yes">
        The input already includes macros; if you wish to convert
        a partially macro-ized file you must first expand them
        using chado-expand-macros.xsl
      </xsl:message>



( run in 0.812 second using v1.01-cache-2.11-cpan-5a3173703d6 )