lib/ensembl/variation/activerecord.rb in ensembl-0.0.4 vs lib/ensembl/variation/activerecord.rb in ensembl-0.0.5
- old
+ new
@@ -45,11 +45,10 @@
belongs_to :attrib_type
end
class AttribSet < ModelBase
belongs_to :attrib
-
end
class AttribType < ModelBase
has_many :attribs, class_name: 'Attrib'
has_many :pheotype_feature_attrib
@@ -64,10 +63,36 @@
class CompressedGenotypeVar < Connection
belongs_to :variation
belongs_to :subsnp_handle, foreign_key: 'subsnp_id'
+ def individual_genotypes
+ nil if genotypes.nil?
+
+ # To decrease number of DB queries needed
+ # FIXME: Should be in GenotypeCodes class or should use caching
+ genotype_codes=genotype_code_ids.uniq.inject({}) { |hsh, gc_id | hsh[gc_id]=GenotypeCode.find gc_id;hsh }
+
+ @igs||=unpacked_genotypes.map{|s| IndividualGenotype.new({ individual_id: s[0],genotype_code_id:s[1]})}
+ end
+
+ def unpacked_genotypes
+ unpack_genotypes.each_slice(2).map{|sl| sl }
+ end
+
+ def individual_ids
+ unpack_genotypes.select.each_with_index{|str,i| i.even?}
+ end
+
+ def genotype_code_ids
+ unpack_genotypes.select.each_with_index{|str,i| i.odd?}
+ end
+
+ protected
+ def unpack_genotypes
+ @g_unpacked||=genotypes.unpack('ww*') unless genotypes.nil?
+ end
end
class CoordSystem < ModelBase
end
@@ -93,12 +118,12 @@
has_one :failed_description
end
class GenotypeCode < ModelBase
+
belongs_to :allele_code
- belongs_to :genotype_code
end
class Individual < ModelBase
belongs_to :individual_type
@@ -175,33 +200,30 @@
end
class PhenotypeFeatureAttrib < Connection
belongs_to :attrib_type
belongs_to :phenotype_feature
-
end
class Population < ModelBase
self.extend Ensembl::SearchByName
- has_many :population_synonyms
- #has_many :synonyms, through: :population_synonyms, source: :synonym
has_many :alleles
+ has_many :population_synonyms
has_many :individual_populations
has_many :individuals, through: :individual_populations
- has_many :population_structures, foreign_key: 'super_population_id'
+ has_many :sub_population_structures, foreign_key: 'super_population_id', class_name: 'PopulationStructure'
has_many :sub_populations, through: :population_structures, source: :sub_population
- has_many :parents, through: :population_structures, source: :super_populaton#, foreign_key: 'sub_population_id'
+ has_many :super_population_structures, foreign_key: 'sub_population_id', class_name: 'PopulationStructure'
+ has_many :super_populations, through: :population_structures, source: :super_populaton
+
has_many :population_genotypes
- def parent
- ps=PopulationStructure.find_by(sub_population: id)
- ps.super_population unless ps.nil?
- end
+ scope :displayable, -> { where(display:'LD')}
def all_individual_populations
IndividualPopulation.where(population_id: sub_population_ids(self)<<id)
end
@@ -231,12 +253,12 @@
class PopulationGenotype < ModelBase
belongs_to :variation
belongs_to :population
belongs_to :subsnp_handle, foreign_key: 'subsnp_id'
-
belongs_to :genotype_code
+
has_one :allele_code, through: :genotype_code
end
class PopulationStructure < Connection
belongs_to :super_population, foreign_key: 'super_population_id', class_name: 'Population'
@@ -307,14 +329,14 @@
end
class StructuralVariationSample < ModelBase
belongs_to :structural_variation
belongs_to :individual
+ belongs_to :strain, foreign_key: 'strain_id', class_name: 'Individual'
end
class Source < ModelBase
-
end
class Study < ModelBase
has_many :associate_studies, foreign_key: 'study1_id'
has_many :associated_studies, through: :associate_studies, source: :associated_study
@@ -447,10 +469,9 @@
self.extend Ensembl::SearchByName
belongs_to :short_name, foreign_key: 'short_name_attrib_id', class_name: 'Attrib'
has_many :structural_variations
- #has_many :variation_set_structures, foreign_key: 'variation_set_super'
has_many :sub_variation_set_structures, foreign_key: 'variation_set_super', class_name: 'VariationSetStructure'
has_many :sub_variation_sets, through: :sub_variation_set_structures , source: :sub_variation_set
has_many :super_variation_set_structures, foreign_key: 'variation_set_sub', class_name: 'VariationSetStructure'
has_many :super_variation_sets, through: :super_variation_set_structures , source: :super_variation_set
\ No newline at end of file