<?xml version="1.0"?>
<!--
***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1

The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is PharmGen.

The Initial Developer of the Original Code is
PharmGKB (The Pharmacogenetics and Pharmacogenetics Knowledge Base,
supported by NIH U01GM61374).
Portions created by the Initial Developer are Copyright (C) 2005
the Initial Developer. All Rights Reserved.

Contributor(s):

Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or the
GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in
which case the provisions of the GPL or the LGPL are applicable instead of
those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.

***** END LICENSE BLOCK *****
-->

<xsd:schema version="4.0"
  targetNamespace="http://www.pharmgkb.org/schema/"
  xmlns="http://www.pharmgkb.org/schema/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:sch="http://www.ascc.net/xml/schematron"
  elementFormDefault="qualified">

  <xsd:annotation>
    <xsd:documentation>
      This XML schema defines sequence related entities.
      For complete documentation, see http://preview.pharmgkb.org/schema/.
    </xsd:documentation>
  </xsd:annotation>


  <!-- Included XML Schema Files -->
  <xsd:include schemaLocation="http://preview.pharmgkb.org/schema/types.xsd" />
  <xsd:include schemaLocation="http://preview.pharmgkb.org/schema/types-sequence.xsd" />



  <!-- geneStructure -->
  <xsd:element name="geneStructure">
    <xsd:annotation>
      <xsd:documentation>
        This class defines the structure of a gene.
        See http://preview.pharmgkb.org/schema/docs/geneStructure.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:complexContent>
        <xsd:extension base="AccessionObjectClass">
          <!-- subelements -->
          <xsd:sequence>
            <xsd:element name="name" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="geneXref" type="XrefClass" minOccurs="0" maxOccurs="1" />
            <xsd:element name="featureSetXref" type="XrefClass" minOccurs="1" maxOccurs="unbounded" />
            <xsd:element name="term" type="OntologyTermClass" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="xref" type="XrefClass" minOccurs="0" maxOccurs="unbounded" />
          </xsd:sequence>
        </xsd:extension>
      </xsd:complexContent>
    </xsd:complexType>
  </xsd:element>


  <!-- spliceSet -->
  <xsd:element name="spliceSet">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a splice form for a gene.
        See http://preview.pharmgkb.org/schema/docs/spliceSet.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:complexContent>
        <xsd:extension base="AccessionObjectClass">
          <!-- subelements -->
          <xsd:sequence>
            <xsd:element name="name" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="splice" minOccurs="1" maxOccurs="unbounded">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="geneStructureXref" type="XrefClass" minOccurs="1" maxOccurs="1" />
                  <xsd:element name="featureXref" type="XrefClass" minOccurs="1" maxOccurs="unbounded" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="term" type="OntologyTermClass" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="xref" type="XrefClass" minOccurs="0" maxOccurs="unbounded" />
          </xsd:sequence>
        </xsd:extension>
      </xsd:complexContent>
    </xsd:complexType>
  </xsd:element>


  <!-- FeatureSetClass -->
  <xsd:complexType name="FeatureSetClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a set of features found on a reference sequence.
        See http://preview.pharmgkb.org/schema/docs/featureSet.html for details.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Constraints for featureSetXref">
          <sch:rule context="pgkb:featureSetXref">
            <sch:report test="not(@resource='PharmGKB') and not(@resource='local')">Resource attribute must be 'PharmGKB' or 'local'</sch:report>
            <sch:report test="@resource='PharmGKB' and
            not((starts-with(., 'PA') and floor(substring(., 3))=number(substring(., 3))) or
            floor(.)=number(.))">Cross-reference resource from PharmGKB does not appear to have a valid PharmGKB Accession ID</sch:report>
          </sch:rule>
        </sch:pattern>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="AccessionObjectClass">
        <!-- subelements -->
        <xsd:sequence>
          <xsd:element name="name" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
          <xsd:element name="feature" type="FeatureClass" minOccurs="1" maxOccurs="unbounded" />
          <xsd:element name="xref" type="XrefClass" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>


  <!-- FeatureClass -->
  <xsd:complexType name="FeatureClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a feature.
        See http://preview.pharmgkb.org/schema/docs/feature.html for details.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Required elements for FeatureClass">
          <sch:rule context="pgkb:feature">
            <sch:report test="normalize-space(pgkb:type)='Exon' and
            not(pgkb:readingFrameStartPosition)">Missing exon-specific element:  readingFrameStartPosition</sch:report>
            <sch:report test="not(normalize-space(pgkb:type)='Exon') and
            pgkb:readingFrameStartPosition">Invalid element:  readingFrameStartPosition only applies to exons</sch:report>
            <sch:report test="pgkb:readingFrameStartPosition and
            (number(pgkb:readingFrameStartPosition)&lt;number(pgkb:region/pgkb:startPosition) or
            number(pgkb:readingFrameStartPosition)&gt;number(pgkb:region/pgkb:stopPosition))">The readingFrameStartPosition must be between the startPosition and the stopPosition</sch:report>
          </sch:rule>
        </sch:pattern>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="AccessionObjectClass">
        <!-- subelements -->
        <xsd:sequence>
          <xsd:element name="name" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
          <xsd:element name="type" type="FeatureTypeEnum" minOccurs="1" maxOccurs="1" />
          <xsd:element name="coordinateSystem" type="CoordinateSystemClass" minOccurs="0" maxOccurs="1" />
          <xsd:element name="region" type="RegionClass" minOccurs="1" maxOccurs="1" />
          <xsd:element name="readingFrameStartPosition" type="xsd:integer" minOccurs="0" maxOccurs="1" />
          <xsd:element name="xref" type="XrefClass" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>


  <!-- FeatureTypeEnum -->
  <xsd:simpleType name="FeatureTypeEnum">
    <xsd:annotation>
      <xsd:documentation>
        This list of accepted feature names.
        See http://preview.pharmgkb.org/schema/docs/feature.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="3' Flanking" />
      <xsd:enumeration value="5' Flanking" />
      <xsd:enumeration value="3' UTR" />
      <xsd:enumeration value="5' UTR" />
      <xsd:enumeration value="Acceptor" />
      <xsd:enumeration value="Donor" />
      <xsd:enumeration value="Enhancer" />
      <xsd:enumeration value="Exon" />
      <xsd:enumeration value="Intron" />
      <xsd:enumeration value="Promoter" />
      <xsd:enumeration value="Regulatory Element" />
      <xsd:enumeration value="Ribosome Binding Site" />
      <xsd:enumeration value="Silencer" />
      <xsd:enumeration value="Start Codon" />
      <xsd:enumeration value="Stop Codon" />
      <xsd:enumeration value="Transcription Start Site" />
      <xsd:enumeration value="Transcription Termination Site" />
    </xsd:restriction>
  </xsd:simpleType>


</xsd:schema>