<?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 all sample set and subject related entities.
      For complete documentation, see http://www.pharmgkb.org/schema/.
    </xsd:documentation>
  </xsd:annotation>


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



  <!-- studyGroup -->
  <xsd:element name="studyGroup">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a study group of subjects.
        See http://www.pharmgkb.org/schema/docs/studyGroup.html for details.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Constraints for studyGroupXref">
          <sch:rule context="pgkb:studyGroupXref">
            <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:complexType>
      <xsd:complexContent>
        <xsd:extension base="AccessionObjectClass">
          <!-- subelements -->
          <xsd:sequence>
            <xsd:element name="name" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="subjectXref" 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>


  <!-- sampleSet -->
  <xsd:element name="sampleSet">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a set of subjects for use within experiments.
        See http://www.pharmgkb.org/schema/docs/sampleSet.html for details.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Constraints for sampleSetXref">
          <sch:rule context="pgkb:sampleSetXref">
            <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:complexType>
      <xsd:complexContent>
        <xsd:extension base="AccessionObjectClass">
          <!-- subelements -->
          <xsd:sequence>
            <xsd:element name="name" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="sampleXref" 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>

  <!-- subject -->
  <xsd:element name="subject">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a subject.
        See http://www.pharmgkb.org/schema/docs/subject.html for details.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Required elements for subject">
          <sch:rule context="pgkb:subject">
            <sch:report test="not(@pharmgkbId)">Subjects must have a valid PharmGKB Accession ID</sch:report>
          </sch:rule>
        </sch:pattern>
        <sch:pattern name="Constraints for subject cross-references">
          <sch:rule context="pgkb:subjectXref">
            <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:rule context="pgkb:fatherXref">
            <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:rule context="pgkb:motherXref">
            <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:complexType>
      <xsd:complexContent>
        <xsd:extension base="AccessionObjectClass">
          <!-- subelements -->
          <xsd:sequence>
            <xsd:element name="organism" type="OrganismClass" minOccurs="0" maxOccurs="1" />
            <xsd:element name="sex" type="GenderEnum" minOccurs="0" maxOccurs="1" />
            <xsd:element name="fatherXref" type="XrefClass" minOccurs="0" maxOccurs="1" />
            <xsd:element name="motherXref" type="XrefClass" minOccurs="0" maxOccurs="1" />
            <xsd:element name="race" type="RacialCategoryClass" minOccurs="0" maxOccurs="1" />
            <xsd:element name="ethnicity" type="EthnicCategoryClass" minOccurs="0" maxOccurs="1" />
            <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>

  <!-- sample -->
  <xsd:element name="sample">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a sample from a subject.
        See http://www.pharmgkb.org/schema/docs/sample.html for details.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Required elements for sample">
          <sch:rule context="pgkb:sample">
            <sch:report test="not(@pharmgkbId)">Samples must have a valid PharmGKB Accession ID</sch:report>
            <sch:report test="not(@pharmgkbId) and
                              not(pgkb:subjectXref)">Missing element:  subjectXref</sch:report>
          </sch:rule>
        </sch:pattern>
        <sch:pattern name="Constraints for sampleXref">
          <sch:rule context="pgkb:sampleXref">
            <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:complexType>
      <xsd:complexContent>
        <xsd:extension base="AccessionObjectClass">
          <!-- subelements -->
          <xsd:sequence>
            <xsd:element name="subjectXref" type="XrefClass" minOccurs="0" maxOccurs="1" />
            <xsd:element name="timestamp" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="cellLine" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1" />
            <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>


  <!-- RacialCategoryClass -->
  <xsd:complexType name="RacialCategoryClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a race.
        See http://www.pharmgkb.org/schema/docs/race.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <!-- subelements -->
    <xsd:sequence>
      <xsd:element name="nihCategory" type="NihRacialCategoryEnum" minOccurs="1" maxOccurs="unbounded" />
      <xsd:element name="category" type="xsd:token" minOccurs="0" maxOccurs="1" />
    </xsd:sequence>
  </xsd:complexType>


  <!-- EthnicCategoryClass -->
  <xsd:complexType name="EthnicCategoryClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines an ethnicity.
        See http://www.pharmgkb.org/schema/docs/ethnicity.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <!-- subelements -->
    <xsd:sequence>
      <xsd:element name="nihCategory" type="NihEthnicCategoryEnum" minOccurs="1" maxOccurs="1" />
      <xsd:element name="category" type="xsd:token" minOccurs="0" maxOccurs="1" />
    </xsd:sequence>
  </xsd:complexType>


  <!-- NihRacialCategoryEnum -->
  <xsd:simpleType name="NihRacialCategoryEnum">
    <xsd:annotation>
      <xsd:documentation>
        The list of accepted racial categories as defined by the OMB.
        See http://www.whitehouse.gov/omb/fedreg/ombdir15.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="NA" />
      <xsd:enumeration value="Unknown" />
      <xsd:enumeration value="American Indian or Alaskan Native" />
      <xsd:enumeration value="Asian" />
      <!-- obsolete:
      <xsd:enumeration value="Asian or Pacific Islander" />
      -->
      <xsd:enumeration value="Black or African American" />
      <xsd:enumeration value="Hispanic or Latino" />
      <xsd:enumeration value="Native Hawaiian or Other Pacific Islander" />
      <xsd:enumeration value="White" />
    </xsd:restriction>
  </xsd:simpleType>


  <!-- NihEthnicCategoryEnum -->
  <xsd:simpleType name="NihEthnicCategoryEnum">
    <xsd:annotation>
      <xsd:documentation>
        The list of accepted ethinic categories as defined by the OMB.
        See http://www.whitehouse.gov/omb/fedreg/ombdir15.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="NA" />
      <xsd:enumeration value="Unknown" />
      <xsd:enumeration value="Hispanic or Latino" />
      <xsd:enumeration value="Not Hispanic or Latino" />
    </xsd:restriction>
  </xsd:simpleType>


</xsd:schema>