Skip to content

Instantly share code, notes, and snippets.

@rtirrell
Created June 30, 2010 06:15
Show Gist options
  • Select an option

  • Save rtirrell/458304 to your computer and use it in GitHub Desktop.

Select an option

Save rtirrell/458304 to your computer and use it in GitHub Desktop.
require "dm-core"
require "dm-timestamps"
# Note, a GSE etc could have two of the same field (i.e. Pubmed so check for that
# and make an array instead)
# child_key: set of fields identifying child model
# parent_key: set of fields identifying parent model
# GDS
# has 1 GSE
# has n GDSSubsets
# GDSSubset
# belongs_to GDS
# has n samples (GDSSubsets)
# GDSSubsetMember
# belongs_to GDSSubset
# has 1 GSM
# GSE
# # does not necessarily belong to a GDS
# has n GSMs
# GSM
# has 1 GPL
# has n measurements (
# GPL
# has n GSMs
module GEOAnnotator
module ORM
class GEO
def self.inherited(subclass)
subclass.class_eval do
include DataMapper::Resource
def self.default_repository_name; :expr_geo; end
end
end
end
class GDS < GEO
storage_names[:expr_geo] = "gds"
property :gds, Integer, :key => true
property :channel, Integer
property :gpl_organism, String
property :feature, Integer
property :pubmed, Integer
property :sample_organism, String
property :sample_type, String
property :technology, String
property :title, String
property :type, String
has 1, :gds_gse, "GDSGSE", :child_key => [:gds], :parent_key => [:gds]
has 1, :gse_object, "GSE", :through => :gds_gse
end
class GDSGSE < GEO
storage_names[:expr_geo] = "gds_gse"
belongs_to :gds_object, "GDS", :child_key => [:gds],
:parent_key => [:gds], :key => true
belongs_to :gse_object, "GSE", :child_key => [:gse],
:parent_key => [:gse]
end
class GSE < GEO
storage_names[:expr_geo] = "gse_list"
property :gse, Integer, :key => true
has n, :fields, "GSEField", :child_key => [:gse], :parent_key => [:gse]
end
class GSEField < GEO
storage_names[:expr_geo] = "gse"
property :gse, Integer, :key => true
property :field, String, :key => true
property :value, String
end
class GSEGSM < GEO
storage_names[:expr_geo] = "gse_gsm"
# parent key: parent identifies the child by
# child key: child identifies the parent by.
# if the (only) object attribute is belongs_to, :gse_object, "GSE"
# and no key information is given, [gse, gse_object_field, gse_object_gse]
# and the parent_key is gse, [gse_object_gse]
# and the child_key is gse, [gse, gse_object_field]
# and both keys are gse, [gse]
belongs_to :gse_object, "GSE", :child_key => [:gse],
:parent_key => [:gse], :key => true
belongs_to :gsm_object, "GSM", :child_key => [:gsm],
:parent_key => [:gsm], :key => true
end
class GSM < GEO
storage_names[:expr_geo] = "gsm_list"
property :gsm, Integer, :key => true
has n, :fields, "GSMField", :child_key => [:gsm]
# for has n:
# with no keys, get gsm_gsm, gsm_channel, gsm_field.
# with just child key at gsm, get [gsm, gsm_channel, gsm_field].
# with just parent key at gsm, get [gsm_gsm] (table name + field name)
# with both, get [gsm]!
# key is apparently optional here.
has n, :measurements, "GSMGeneData", :child_key => [:gsm],
:parent_key => [:gsm]#, :key => true
# this is incorrect syntax.
# has n, :platforms, "GPL", :child_key => [:gsm], :parent_key => [:gsm], :through => :gsm_gpl
# parent_key should be optional?
has n, :gsm_gpls, "GSMGPL", :child_key => [:gsm]
end
class GSMField < GEO
storage_names[:expr_geo] = "gsm"
property :gsm, Integer, :key => true
property :channel, Integer, :key => true
property :field, String, :key => true
property :value, String
end
class GSMGeneData < GEO
storage_names[:expr_geo] = "gsm_gene_data"
property :id, String, :key => true
property :val, Integer
end
class GSMGPL < GEO
storage_names[:expr_geo] = "gsm_gpl"
belongs_to :gsm_object, "GSM", :child_key => [:gsm], :parent_key => [:gsm], :key => true
belongs_to :gpl_object, "GPL", :child_key => [:gpl], :parent_key => [:gpl], :key => true
end
class GPL < GEO
storage_names[:expr_geo] = "gpl_list"
property :gpl, Integer, :key => true
has n, :fields, "GPLField", :child_key => [:gpl]
has n, :gsm_gpls, "GSMGPL", :child_key => [:gpl], :parent_key => [:gpl]
end
class GPLField < GEO
storage_names[:expr_geo] = "gpl"
property :field, String, :key => true
property :value, String, :key => true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment