doc/tutorials/dataimport/schema.py
changeset 8836 8a57802d40d3
child 8930 6a02be304486
equal deleted inserted replaced
8835:3612b760488b 8836:8a57802d40d3
       
     1 # -*- coding: utf-8 -*-
       
     2 # copyright 2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     3 # contact http://www.logilab.fr -- mailto:contact@logilab.fr
       
     4 #
       
     5 # This program is free software: you can redistribute it and/or modify it under
       
     6 # the terms of the GNU Lesser General Public License as published by the Free
       
     7 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     8 # any later version.
       
     9 #
       
    10 # This program is distributed in the hope that it will be useful, but WITHOUT
       
    11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
       
    13 # details.
       
    14 #
       
    15 # You should have received a copy of the GNU Lesser General Public License along
       
    16 # with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17 
       
    18 """cubicweb-diseasome schema"""
       
    19 
       
    20 from yams.buildobjs import EntityType, SubjectRelation, String, Int
       
    21 from cubicweb.schemas.base import ExternalUri
       
    22 
       
    23 
       
    24 class Disease(EntityType):
       
    25     """Disease entity definition.
       
    26 
       
    27     A Disease entity is characterized by several attributes which are 
       
    28     defined by URIs:
       
    29 
       
    30     - a name, which we define as a CubicWeb / Yams String object
       
    31     - a label, also defined as a Yams String
       
    32     - a class degree, defined as a Yams Int (that is, an integer)
       
    33     - a degree, also defined as a Yams Int
       
    34     - size, also defined as an Int
       
    35     - classes, defined as a set containing zero, one or several objects 
       
    36       identified by their URIs, that is, objects of type ``ExternalUri``
       
    37     - subtype_of, defined as a set containing zero, one or several
       
    38       objects of type ``Disease``
       
    39     - associated_genes, defined as a set containing zero, one or several
       
    40       objects of type ``Gene``, that is, of genes associated to the
       
    41       disease
       
    42     - possible_drugs, defined as a set containing zero, one or several
       
    43       objects, identified by their URIs, that is, of type ``ExternalUri``
       
    44     - omim and omim_page are identifiers in the OMIM (Online Mendelian
       
    45       Inheritance in Man) database, which contains an inventory of "human
       
    46       genes and genetic phenotypes" 
       
    47       (see http://http://www.ncbi.nlm.nih.gov/omim). Given that a disease
       
    48       only has unique omim and omim_page identifiers, when it has them,
       
    49       these attributes have been defined through relations such that
       
    50       for each disease there is at most one omim and one omim_page. 
       
    51       Each such identifier is defined through an URI, that is, through
       
    52       an ``ExternalUri`` entity.
       
    53       That is, these relations are of cardinality "?*". For optimization
       
    54       purposes, one might be tempted to defined them as inlined, by setting
       
    55       the ``inlined`` keyword argument to ``True``.
       
    56     - chromosomal_location is also defined through a relation of 
       
    57       cardinality "?*", since any disease has at most one chromosomal
       
    58       location associated to it.
       
    59     - same_as is also defined through an URI, and hence through a
       
    60       relation having ``ExternalUri`` entities as objects.
       
    61 
       
    62     For more information on this data set and the data set itself, 
       
    63     please consult http://datahub.io/dataset/fu-berlin-diseasome.
       
    64     """
       
    65     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    66     # diseasome/name
       
    67     name = String(maxsize=256, fulltextindexed=True)
       
    68     # Corresponds to http://www.w3.org/2000/01/rdf-schema#label
       
    69     label = String(maxsize=512, fulltextindexed=True)
       
    70     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    71     # diseasome/classDegree
       
    72     class_degree = Int()
       
    73     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    74     # diseasome/degree
       
    75     degree = Int()
       
    76     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    77     # diseasome/size
       
    78     size = Int()
       
    79     #Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    80     # diseasome/class
       
    81     classes = SubjectRelation('ExternalUri', cardinality='**')
       
    82     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    83     # diseasome/diseaseSubtypeOf
       
    84     subtype_of = SubjectRelation('Disease', cardinality='**')
       
    85     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    86     # diseasome/associatedGene
       
    87     associated_genes = SubjectRelation('Gene', cardinality='**')
       
    88     #Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    89     # diseasome/possibleDrug
       
    90     possible_drugs = SubjectRelation('ExternalUri', cardinality='**')
       
    91     #Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    92     # diseasome/omim
       
    93     omim = SubjectRelation('ExternalUri', cardinality='?*', inlined=True)
       
    94     #Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    95     # diseasome/omimPage
       
    96     omim_page = SubjectRelation('ExternalUri', cardinality='?*', inlined=True)
       
    97     #Corresponds to 'http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
    98     # diseasome/chromosomalLocation'
       
    99     chromosomal_location = SubjectRelation('ExternalUri', cardinality='?*',
       
   100                                            inlined=True)
       
   101     #Corresponds to http://www.w3.org/2002/07/owl#sameAs
       
   102     same_as = SubjectRelation('ExternalUri', cardinality='**')
       
   103 
       
   104 
       
   105 class Gene(EntityType):
       
   106     """Gene entity defintion.
       
   107 
       
   108     A gene is characterized by the following attributes:
       
   109 
       
   110     - label, defined through a Yams String.
       
   111     - bio2rdf_symbol, also defined as a Yams String, since it is 
       
   112       just an identifier.
       
   113     - gene_id is an URI identifying a gene, hence it is defined
       
   114       as a relation with an ``ExternalUri`` object.
       
   115     - a pair of unique identifiers in the HUGO Gene Nomenclature
       
   116       Committee (http://http://www.genenames.org/). They are defined
       
   117       as ``ExternalUri`` entities as well.
       
   118     - same_as is also defined through an URI, and hence through a
       
   119       relation having ``ExternalUri`` entities as objects.
       
   120     """
       
   121     # Corresponds to http://www.w3.org/2000/01/rdf-schema#label
       
   122     label = String(maxsize=512, fulltextindexed=True)
       
   123     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
   124     # diseasome/geneId
       
   125     gene_id = SubjectRelation('ExternalUri', cardinality='**')
       
   126     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
   127     # diseasome/hgncId
       
   128     hgnc_id = SubjectRelation('ExternalUri', cardinality='**')
       
   129     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
   130     # diseasome/hgncIdPage
       
   131     hgnc_page = SubjectRelation('ExternalUri', cardinality='**')
       
   132     # Corresponds to http://www4.wiwiss.fu-berlin.de/diseasome/resource/
       
   133     # diseasome/bio2rdfSymbol
       
   134     bio2rdf_symbol = String(maxsize=64, fulltextindexed=True)
       
   135     #Corresponds to http://www.w3.org/2002/07/owl#sameAs
       
   136     same_as = SubjectRelation('ExternalUri', cardinality='**')