<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="miqas">
		<xs:annotation>
			<xs:documentation>Minimal Information about QTL and Association Studies (http://miqas.sourceforge.net)</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:all>
			    <xs:element name="specification_version" fixed="1.0"/>
			    <xs:element name="title"/>
			    <xs:element name="description" minOccurs="0"/>
			    <xs:element name="contact" type="contact"/>
			    <xs:element name="references" minOccurs="0">
			        <xs:complexType>
			                <xs:sequence>
			                        <xs:element name="reference" type="reference" maxOccurs="unbounded"/>
			                    </xs:sequence>
			            </xs:complexType>
			    </xs:element>
			    <xs:element name="related_results">
			        <xs:complexType>
			                <xs:sequence>
			                        <xs:element name="related_result" maxOccurs="unbounded" type="related_result"/>
			                    </xs:sequence>
			            </xs:complexType>
			    </xs:element>
			    <xs:element name="traits">
			        <xs:complexType>
			                <xs:sequence>
			                        <xs:element name="trait" type="trait" maxOccurs="unbounded"/>
			                    </xs:sequence>
			            </xs:complexType>
			    </xs:element>
			    <xs:element name="population" type="population"></xs:element>
			    <xs:element name="individuals" minOccurs="0">
			        <xs:complexType>
			                <xs:sequence>
			                        <xs:element name="individual" type="individual" maxOccurs="unbounded"></xs:element>
			                    </xs:sequence>
			            </xs:complexType>
			    </xs:element>
			    <xs:element name="markers">
			        <xs:complexType>
			                <xs:sequence>
			                        <xs:element name="marker" type="marker" maxOccurs="unbounded"/>
			                    </xs:sequence>
			            </xs:complexType>
			    </xs:element>
			    <xs:element name="phenotypes" type="grid" minOccurs="0"></xs:element>
			    <xs:element name="genotypes" type="grid" minOccurs="0"></xs:element>
			    <xs:element name="analyses">
			        <xs:complexType>
			                <xs:sequence>
			                        <xs:element name="analysis" type="analysis" maxOccurs="unbounded"></xs:element>
			                    </xs:sequence>
			            </xs:complexType>
			    </xs:element>
			    <xs:element name="linkage_map" minOccurs="0">
			        <xs:complexType>
			                <xs:sequence>
			                        <xs:element name="linkage_group" type="linkage_group" maxOccurs="unbounded"/>
			                    </xs:sequence>
			            </xs:complexType>
			    </xs:element>
			    <xs:element name="results">
			        <xs:complexType>
			                <xs:choice>
			                        <xs:sequence>
			                                <xs:element name="qtl" type="qtl" maxOccurs="unbounded"></xs:element>
			                            </xs:sequence>
			                            <xs:sequence>
			                                <xs:element name="associated_marker" type="associated_marker" maxOccurs="unbounded"></xs:element>
			                            </xs:sequence>
			                    </xs:choice>
			            </xs:complexType>
			    </xs:element>
			</xs:all>
		</xs:complexType>
	</xs:element>
 <xs:complexType name="trait">
  <xs:all>
   <xs:element name="name" type="xs:string" nillable="false"></xs:element>
   <xs:element name="description" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="unit" type="xs:string"></xs:element>
   <xs:element name="ontology_terms" minOccurs="0">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="ontology_term" type="accession" maxOccurs="unbounded"></xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
  </xs:all>
  <xs:attribute name="id" type="xs:ID" use="required"/>
 </xs:complexType>
 <xs:complexType name="marker">
  <xs:all>
   <xs:element name="names" minOccurs="0">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="name" type="xs:string" maxOccurs="unbounded"></xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
   <xs:element name="accessions">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="accession" type="accession" maxOccurs="unbounded"></xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
   <xs:element name="alleles" minOccurs="0">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="allele" type="allele" maxOccurs="unbounded"></xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
  </xs:all>
  <xs:attribute name="id" type="xs:ID" use="required"/>
 </xs:complexType>
 <xs:complexType name="accession">
  <xs:all>
   <xs:element name="authority" type="xs:string"></xs:element>
   <xs:element name="identifier" type="xs:string"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="allele">
  <xs:all>
   <xs:element name="code" type="xs:string"></xs:element>
   <xs:element name="value" type="xs:string"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="mapping">
  <xs:all>
   <xs:element name="marker_ref" type="xs:IDREF">
    <xs:annotation>
     <xs:documentation>References a marker ID from the markers element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="position" type="xs:decimal"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="linkage_group">
  <xs:all>
   <xs:element name="name" minOccurs="0"/>
   <xs:element name="mappings">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="mapping" type="mapping" maxOccurs="unbounded"></xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
  </xs:all>
  <xs:attribute name="id" type="xs:ID"/>
 </xs:complexType>
 <xs:complexType name="contact">
  <xs:all>
   <xs:element name="email" type="xs:string"></xs:element>
   <xs:element name="first_name" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="last_name" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="phone" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="address" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="affiliation" type="xs:string" minOccurs="0"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="reference">
  <xs:all>
   <xs:element name="pmid" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="authors" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="title" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="journal" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="issue" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="number" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="year" type="xs:short" minOccurs="0"></xs:element>
   <xs:element name="pages" type="xs:string" minOccurs="0"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="related_result">
  <xs:all>
   <xs:element name="accession" type="accession"></xs:element>
   <xs:element name="relationship" type="xs:string"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="individual">
  <xs:all>
   <xs:element name="sex" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="father_ref" type="xs:IDREF" minOccurs="0">
    <xs:annotation>
     <xs:documentation>References another individual ID from the individuals element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="mother_ref" type="xs:IDREF" minOccurs="0">
    <xs:annotation>
     <xs:documentation>References another individual ID from the individuals element.</xs:documentation>
    </xs:annotation>
   </xs:element>
  </xs:all>
  <xs:attribute name="id" type="xs:ID"/>
 </xs:complexType>
 <xs:complexType name="analysis">
  <xs:all>
   <xs:element name="traits">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="trait_ref" type="xs:IDREF" maxOccurs="unbounded">
       <xs:annotation>
        <xs:documentation>References an ID from the traits element.</xs:documentation>
       </xs:annotation>
      </xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
   <xs:element name="genetic_model" type="xs:string"></xs:element>
   <xs:element name="software" type="xs:string"></xs:element>
   <xs:element name="approach" type="xs:string" minOccurs="0"></xs:element>
   <xs:element name="assumptions" minOccurs="0">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="assumption" maxOccurs="unbounded" type="xs:string"></xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
   <xs:element name="fixed_effects" minOccurs="0">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="fixed_effect" type="xs:string" maxOccurs="unbounded"></xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
   <xs:element name="covariates" minOccurs="0">
    <xs:complexType>
     <xs:sequence>
      <xs:element name="covariate" maxOccurs="unbounded">
       <xs:complexType>
        <xs:choice>
         <xs:element name="trait_ref" type="xs:IDREF">
          <xs:annotation>
           <xs:documentation>References an trait ID from the traits element.</xs:documentation>
          </xs:annotation>
         </xs:element>
         <xs:element name="qtl_ref" type="xs:IDREF">
          <xs:annotation>
           <xs:documentation>References an QTL ID from the results element.</xs:documentation>
          </xs:annotation>
         </xs:element>
        </xs:choice>
       </xs:complexType>
      </xs:element>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
  </xs:all>
  <xs:attribute name="id" type="xs:ID"/>
 </xs:complexType>
 <xs:complexType name="qtl">
  <xs:all>
   <xs:element name="analysis_ref" type="xs:IDREF">
    <xs:annotation>
     <xs:documentation>References an analysis ID from the analyses element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="trait_ref" type="xs:IDREF">
    <xs:annotation>
     <xs:documentation>References an trait ID from the traits element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="linkage_group_ref" type="xs:IDREF">
    <xs:annotation>
     <xs:documentation>References a linkage_group ID from the linkage_map element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="region" type="qtl_region"></xs:element>
   <xs:element name="confidence_interval" type="confidence_interval" minOccurs="0"></xs:element>
   <xs:element name="statistical_significance" type="xs:string"></xs:element>
   <xs:element name="proportion_explained" type="xs:string"></xs:element>
   <xs:element name="significance" type="significance" minOccurs="0"></xs:element>
  </xs:all>
  <xs:attribute name="id" type="xs:ID"/>
 </xs:complexType>
 <xs:complexType name="qtl_region">
  <xs:all>
   <xs:element name="start" type="xs:decimal"></xs:element>
   <xs:element name="stop" type="xs:decimal"></xs:element>
   <xs:element name="peak" type="xs:decimal" minOccurs="0"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="confidence_interval">
  <xs:all>
   <xs:element name="start" type="xs:decimal"></xs:element>
   <xs:element name="stop" type="xs:decimal"></xs:element>
   <xs:element name="method" type="xs:string"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="significance">
  <xs:all>
   <xs:element name="term" type="xs:string"></xs:element>
   <xs:element name="criterion" type="xs:string"></xs:element>
  </xs:all>
 </xs:complexType>
 <xs:complexType name="associated_marker">
  <xs:all>
   <xs:element name="analysis_ref" type="xs:IDREF">
    <xs:annotation>
     <xs:documentation>References an analysis ID from the analyses element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="trait_ref" type="xs:IDREF">
    <xs:annotation>
     <xs:documentation>References a trait ID from the traits element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="marker_ref" type="xs:IDREF">
    <xs:annotation>
     <xs:documentation>References a marker ID from the markers element.</xs:documentation>
    </xs:annotation>
   </xs:element>
   <xs:element name="statistical_significance" type="xs:string"></xs:element>
   <xs:element name="proportion_explained" type="xs:string"></xs:element>
  </xs:all>
  <xs:attribute name="id" type="xs:ID"/>
 </xs:complexType>
    <xs:complexType name="grid">
        <xs:annotation>
            <xs:documentation>The grid-based section is flat text, but follows strict rules regarding its
content. As its contents can not be validated using the XML, this will have to
be done at the application level.

Format:
* Header: The header is a delimiter-separated list of titles for each column in the
values element. The first thing should be "individual_id", followed by the list
of e.g. trait_ids for phenotypic data or marker_ids for genotypic data. These
IDs should correspond to a trait id in the traits element (for phenotypes) or 
a marker ID in the markers element (for genotypes). If this is not the case, 
this section is invalid. The line should end with the delimiter.
* Values: The values for phenotype recordings must be in the unit
as recorded in the traits section; the values for genotype recordings must be 
one of the values for the marker allele. The same marker id should appear once 
for each allele; for diploid organisms, there should therefore be two columns 
for each marker. Each line should end with the delimiter.

Typical issues with this section:
  * The individual_id is missing.
  * An individual ID is not defined in the individuals element.
  * Any of the lines does not end with the delimiter.
  * For phenotypes:
    * A trait ID is not defined in the traits element.
    * Values for the traits are not in the units as described in the traits
      element.
  * For genotypes:
    * A marker ID is not defined in the markers element.
    * Values for the markers are not mentioned as alleles in the marker 
      element.

Example for phenotypic data (suppose ind_1 to ind_5 are individual IDs and 
birth_weight, carcass_weight and fat_depth are valid trait IDs):
 <delimiter>;</delimiter>
 <header>individual_id;birth_weight;carcass_weight;fat_depth;</header>
 <values>
 ind_1;67800;382100;19;
 ind_2;75400;283100;24;
 ind_3;69800;235500;29;
 ind_4;64800;318260;18;
 ind_5;65800;291700;19;
 </values>

Example for genotypic data (suppose ind_1 to ind_5 are individual IDs and m_1 
to m_4 are marker IDs):
 <delimiter>;</delimiter>
 <header>individual_id;m_1;m_1;m_2;m_2;m_3;m_3;m_4;m_4;</header>
 <values>
 ind_1;1;4;4;7;1;2;1;2;
 ind_2;1;4;4;3;1;1;1;2;
 ind_3;0;0;0;0;1;3;1;4;
 ind_4;1;2;2;2;1;1;2;2;
 ind_5;1;1;1;2;3;3;2;3;
 </values>
</xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="delimiter" type="xs:string"></xs:element>
            <xs:element name="header" type="xs:string"></xs:element>
            <xs:element name="values" type="xs:string"></xs:element>
        </xs:all>
    </xs:complexType>
    <xs:complexType name="population">
        <xs:all>
            <xs:element name="species" type="xs:string"></xs:element>
            <xs:element name="description" type="xs:string"></xs:element>
            <xs:element name="source" type="xs:string"></xs:element>
            <xs:element name="structure" type="xs:string"></xs:element>
        </xs:all>
    </xs:complexType>
</xs:schema>
