<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  targetNamespace="http://www.connectomics.ch/2010/Connectome/xmlns" 
  xmlns="http://www.connectomics.ch/2010/Connectome/xmlns" 
  elementFormDefault="qualified">

<xsd:annotation xml:lang="en">
    <xsd:documentation>
    Stephan Gerhard, Version 2.0
    </xsd:documentation>
</xsd:annotation>

<xs:element name="connectome">
  <xs:complexType>
    <xs:sequence>
      
      <!-- a flat style is adopted to store different data types within the connectome file,
           listing networks, surfaces, volumes, tracks and metadata, and using the name attribute
           to create references
      // -->
      
      <xs:element name="connectome-meta" type="metadata" minOccurs="1" maxOccurs="1">
      <xsd:annotation xml:lang="en">
        <xsd:documentation>
        Metadata about the connectome file
        </xsd:documentation>
      </xsd:annotation>
      </xs:element>
      
      <xs:element name="connectome-network" type="networkstype" minOccurs="0" maxOccurs="unbounded">
      <xsd:annotation xml:lang="en">
        <xsd:documentation>
        A list of networks. They can reference volumes, surfaces and tracks. A network datasource is created in the ConnectomeViewer.
        </xsd:documentation>
      </xsd:annotation>
      </xs:element>

      <xs:element name="connectome-surface" type="surfacestype" minOccurs="0" maxOccurs="unbounded">
      <xsd:annotation xml:lang="en">
        <xsd:documentation>
        A list of surfaces. Surface sources are in Gifti format, and can define labels. A surface datasource is created in the ConnectomeViewer.
        Networks can reference to the surface using the name attribute.
        </xsd:documentation>
      </xsd:annotation>
      </xs:element>

      <xs:element name="connectome-volume" type="volumestype" minOccurs="0" maxOccurs="unbounded">
      <xsd:annotation xml:lang="en">
        <xsd:documentation>
        A list of volumes. Volume sources are in Nifti format, and can also define segmentations. A volume datasource is created in the ConnectomeViewer.
        Networks can reference to the volume using the name attribute.
        </xsd:documentation>
      </xsd:annotation>
      </xs:element>

      <xs:element name="connectome-track" type="trackstype" minOccurs="0" maxOccurs="unbounded">
      <xsd:annotation xml:lang="en">
        <xsd:documentation>
        A list of track files. Track sources are in TrackVis format, and can also contain data. A track datasource is created in the ConnectomeViewer.
        Networks can reference to the track file using the name attribute.
        </xsd:documentation>
      </xsd:annotation>
      </xs:element>        

   </xs:sequence>
  </xs:complexType>
  
</xs:element>

<xs:complexType name="metadata">
  <xs:sequence>
   <xs:element name="generator" type="xs:string" minOccurs="1">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Software version/Converter etc. this file was generated with
      </xsd:documentation>
    </xsd:annotation>
  </xs:element>
  
   <xs:element name="initial-creator" type="xs:string" minOccurs="1">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Author(s) of the data
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>
    
   <xs:element name="creation-date" type="xs:date" minOccurs="1">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      When was the file create ?  YYYY-M-DD
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>
    
   <xs:element name="modification-date" type="xs:date" minOccurs="1">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      When was the file modified? YYYY-M-DD
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>

   <xs:element name="name" type="xs:string" minOccurs="1">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Short name of this Connectome File?
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>    
    
   <xs:element name="species" type="xs:string" minOccurs="1">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      From which species is the data? According to the ConnectomeWiki Category:Species taxonomy (case-sensitive!)
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>
    
   <xs:element name="legal-notice" type="xs:string" minOccurs="0">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Some legal notice concerning usage rights for the data.
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>
    
   <xs:element name="reference" type="xs:string" minOccurs="0">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      References to paper where the data has been published.
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>
    
   <xs:element name="url" type="xs:string" minOccurs="0">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      References to URL with further information or download location.
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>
    
   <xs:element name="description" type="xs:string" minOccurs="0">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Description of the dataset.
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>

    <xs:element name="metadata" type="moremetadatatype" minOccurs="0" maxOccurs="1">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
          If one has any kind of metadata that might be relevant for later processing, and it is not possible to annotate the
          metadata directly to networks with the network-metadata tag, it can be specified here. An example would be demographic
          data about subjects, and any data that does not fit the predefined tags in connectome-meta. See also example datasets.
          The very flexible schema of a dictionary (key/value pairs) is adopted to represent any kind of metadata. The values are strings.
        </xsd:documentation>
      </xsd:annotation>
    </xs:element>
    
  </xs:sequence>
  
   <xs:attribute name="version" type="xs:string" use="required">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Defines the version of the Connectome Schema Definition the current Connectome File is compatible with. Should be 2.0
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
</xs:complexType>  


<xs:complexType name="networkstype">

  <xs:sequence>


          <xs:element name="network-metadata" type="moremetadatatype" minOccurs="0" maxOccurs="1">
          <xsd:annotation xml:lang="en">
            <xsd:documentation>
            Often, there is particular metadata for networks one wants to use for later processing. For example one can annotate networks that represent subjects with
            information about being member of the control or test group. The very flexible schema of a dictionary (key/value pairs) is adopted to represent any kind of
            metadata. The values are strings.
           </xsd:documentation>
          </xsd:annotation>
          </xs:element>


          <xs:element name="network-surface" type="networksurfacetype" minOccurs="0" maxOccurs="unbounded">
          <xsd:annotation xml:lang="en">
            <xsd:documentation>
            Reference to the connectome-surface using the name attribute. The surface file must exist in the archive.
            A labeling of the surface can be specified using labelname refering to a connectome-surface of dtype label  with labelid, refering to the metatag in the Gifti file.
            </xsd:documentation>
          </xsd:annotation>
          </xs:element>

          
          <xs:element name="network-volume" type="networkvolumetype" minOccurs="0" maxOccurs="unbounded">
          <xsd:annotation xml:lang="en">
            <xsd:documentation>
            Reference to the connectome-volume using the name attribute. The volume file must exist in the archive.
            A segmentation of a particular volume can be specified using segmentationname refering to a connectome-volume of dtype segmentation
            in addition to the reference with the name attribute to e.g. a T1-weighted volume. The voxel dimensions have to match.
            The networks' node attribute dn_intensityvalue value must be consistent with the voxel intensityvalues in the segmentation volumes.
            </xsd:documentation>
          </xsd:annotation>
          </xs:element>
       
          <xs:element name="network-track" type="networktracktype" minOccurs="0" maxOccurs="unbounded">
          <xsd:annotation xml:lang="en">
            <xsd:documentation>
            Reference to the connectome-track using the name attribute. The track file must exist in the archive.
            </xsd:documentation>
          </xsd:annotation>
          </xs:element>
          
          <xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1">
            <xsd:annotation xml:lang="en">
             <xsd:documentation>
              Description of the network
              </xsd:documentation>
            </xsd:annotation>
          </xs:element>

  </xs:sequence>
  
  
    <xs:attribute name="name" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The short name of the network as it appears in the ConnectomeViewer TreeView as node
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="src" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The name of the network.graphml file in the archive including the relative path
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>

    <xs:attribute name="directed" type="xs:boolean">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Is the network directed? This has to match the value in the GraphML file.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
</xs:complexType>


<xs:complexType name="surfacestype">
    <xs:all>
        <xs:element name="description" type="xs:string" minOccurs="0">
         <xsd:annotation xml:lang="en">
           <xsd:documentation>
           Description of the surface(s) or labeling.
           </xsd:documentation>
         </xsd:annotation>
         </xs:element>
    </xs:all>

    <xs:attribute name="name" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Descriptive name of the surface. The name appears in the ConnectomeViewer Connectome File TreeView.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>

    <xs:attribute name="src" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The relative path to the Gifti surface file within the archive.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="fileformat" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Set to "gifti" to use the only supported Gifti format
      See http://www.nitrc.org/frs/download.php/158/gifti.xsd for schema information
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="dtype" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      What type of surface does the Gifti file contain:
      - type="label"
      The Gifti file contains surface labels. This file can be referenced
      in connectome-network with either the name attribute or in addition to another
      surface defined by name and using the labelname attribute and matching labelid. If
      referenced in such a way, the networks' nodes attribute dn_intensityvalue value
      may match the label array integers, thereby relating a network node to a surface
      patch (a region of interest defined on the surface). See also example datasets.
      - type="surfaceset"
      The Gifti file contains a set of surfaces where the metadata tag AnatomicalStructurePrimary match.
      Individual elements of the set are distinguished by the metadta tag AnatomicalStructureSecondary.
      The ConnectomeViewer creates a surface container in the Connectome File TreeView.
      The Gifti file contains information about the coordinate system used.
      - type="surfaceset+label"
      If the Gifti file contains data as described for both surfaceset and label above.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
</xs:complexType>


<xs:complexType name="volumestype">
     <xs:all>
      <xs:element name="description" type="xs:string" minOccurs="0">
      <xsd:annotation xml:lang="en">
        <xsd:documentation>
        Detailed description of the content of the Nifti file.
        </xsd:documentation>
      </xsd:annotation>
      </xs:element>
    </xs:all>
    
    <xs:attribute name="name" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Name of the volume. The name appears in the ConnectomeViewer Connectome File TreeView.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="src" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The relative path to the Nifti volume file within the archive.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="fileformat" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Set to "nifti" to use the only supported Nifti format. This implies
      also files with ending .nii.gz
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="dtype" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The Nifti file contains information about the coordinate system used.
      Set type of volume the Nifti file contains:
      - type="segmentation"
      The Nifti file contains a single volume where the voxel values are integers,
      representing a segmented Region of Interest. If this volume is referenced by
      a connectome-network, its nodes dn_intensityvalue attribute may match these
      integer values. Such a segmentation volume can referenced in a connectome-volume
      by the segmentationname attribute in addition to another, e.g. T1-weighted volume
      which is referenced by the name attribute. See also example datasets.
      - type="T1-weighted"
      The Nifti file contains a T1-weighted volume.
      - type="T2-weighted"
      The Nifti file contains a T2-weighted volume.
      - type="PD-weighted"
      The voxel values represent a proton-density weighted signal.
      - type="fMRI"
      The Nifti file contains functional MRI time series data.
      - type="probabilitymap"
      Voxel values are in the range [0,1]. Can stand for tissue probability maps.
      - type="MD"
      Diffusion-related signal. Stands for mean diffusivity.
      - type="FA"
      Diffusion-related signal. Stands for fractional anisotropy.
      - type="LD"
      Diffusion-related signal. Stands for longitudinal diffusivity.
      - type="TD"
      Diffusion-related signal. Stands for transversal diffusivity.
      
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
 
</xs:complexType>


<xs:complexType name="trackstype">

  <xs:all>
    <xs:element name="description" type="xs:string" minOccurs="0">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Description of the content of the file, e.g what tractography algorithm was used.
      </xsd:documentation>
    </xsd:annotation>
    </xs:element>
    
  </xs:all>
    <xs:attribute name="name" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Name of the track. The name appears in the ConnectomeViewer Connectome File TreeView.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="src" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The relative path to the TrackVis file within the archive.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
    <xs:attribute name="fileformat" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Set to "trackvis" to use the only supported TrackVis file format.
      The TrackVis file format allows to store any number of additional numerical
      data on the individual fibers.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    
</xs:complexType>

<xs:complexType name="moremetadatatype">
  <xs:all>
    <xs:element name="data" minOccurs="0">
    
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      A data element contains a key attribute and the value as tag
      </xsd:documentation>
    </xsd:annotation>
    
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute name="key" type="xs:string">
            <xsd:annotation xml:lang="en">
              <xsd:documentation>
              The key to be used later in the dictionary
              </xsd:documentation>
            </xsd:annotation>
            </xs:attribute>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
    
    </xs:element>
    
  </xs:all>
</xs:complexType>

<xs:complexType name="networksurfacetype">    
    <xs:attribute name="name" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The name of the surface as reference to an existing connectome-surface
      To use an atlas that is shipped with the ConnectomeViewer
      - name="template_atlas_homo_sapines_01"
      Extracted atlas from Freesurfer using fsaverage mesh
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    <xs:attribute name="labelname" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Optional together with labelid. The name of the another surface as reference to an existing connectome-surface
      that contains the label array. Always use in conjunction with labelid. This can
      be used for a separate Gifti file containing e.g. only label information.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    <xs:attribute name="labelid" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The labelid tag name that contains the labeling of the surface reference
      by name. The referenced surface file must contain NIFTI_INTENT_LABEL intent
      with the matching labelid in the metadata. Number of vertices of the
      referenced surface and the label array dimension must match (one label for
      each vertices)
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
</xs:complexType>

<xs:complexType name="networkvolumetype">    
    <xs:attribute name="name" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The name of the volume as reference to an existing connectome-volume.
      The connectome-volume can be of any dtype.
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
    <xs:attribute name="segmentationname" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      Optional. The name of a connectome-volume with dtype segmentation that specifies
      a segmentation of the volume referenced by name. The voxel dimensions have to match.
    </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
</xs:complexType>

<xs:complexType name="networktracktype">    
    <xs:attribute name="name" type="xs:string">
    <xsd:annotation xml:lang="en">
      <xsd:documentation>
      The name of the track as reference to an existing connectome-track
      </xsd:documentation>
    </xsd:annotation>
    </xs:attribute>
</xs:complexType>

</xs:schema>
