Class: Ensembl::Variation::Variation
- Inherits:
-
ModelBase
- Object
- ActiveRecord::Base
- Connection
- ModelBase
- Ensembl::Variation::Variation
- Defined in:
- lib/ensembl/variation/activerecord.rb
Class Method Summary collapse
- .find_all_by_name(name) ⇒ Object
-
.find_by_name(name) ⇒ Object
Find Variation by also using VariationSynonyms @name: name of the variation @return: [Variation].
Instance Method Summary collapse
- #all_phenotype_features ⇒ Object
- #genes ⇒ Object
- #genotype_code_ids ⇒ Object
-
#genotype_codes ⇒ Object
Unique genotype codes from individual_genotypes.
-
#genotype_counts ⇒ Object
Genotype counts for each population “CSHL-HAPMAP:HapMap-YRI”=>“C|T”=>1}.
- #individual_genotype_ids ⇒ Object
-
#individual_genotypes ⇒ Object
Individual and genotype_code id’s related to variation Example: [[1,2],,[<individual_id>,<genotype_code_id>]].
-
#individual_populations ⇒ Object
IndividualPopulations from individual_genotypes.
- #phenotype_features ⇒ Object
-
#phenotype_features_hash ⇒ Object
Made because of the need to cut down database queries { phenotype_feature_id => { :phenotype=> “Phenotype description” , :phenotype_id => _ , :p_value => _ , :odds_ratio => _, :risk_allele => _ }, phenotype_feature_id => { :phenotype=> “Phenotype description” , :phenotype_id => _ , :p_value => _ , :odds_ratio => _, :risk_allele => _ }}.
- #positions ⇒ Object
- #synonym_names ⇒ Object
Methods included from PrimaryKeyOverrides
Methods included from TableNameOverrides
Class Method Details
.find_all_by_name(name) ⇒ Object
604 605 606 607 608 609 610 611 |
# File 'lib/ensembl/variation/activerecord.rb', line 604 def self.find_all_by_name(name) v_ids = where(name: name).pluck(:variation_id) v_ids = variation_synonyms.where(name: name).pluck(:variation_id) if v_ids.nil? return nil if v_ids.nil? where(variation_id: v_ids).order(:name) end |
.find_by_name(name) ⇒ Object
Find Variation by also using VariationSynonyms @name: name of the variation @return: [Variation]
596 597 598 599 600 601 602 |
# File 'lib/ensembl/variation/activerecord.rb', line 596 def self.find_by_name(name) v = self.find_by(name: name) return v unless v.nil? vs = VariationSynonym.eager_load(:variation).find_by(name: name) return vs.variation unless vs.nil? nil end |
Instance Method Details
#all_phenotype_features ⇒ Object
506 507 508 509 510 |
# File 'lib/ensembl/variation/activerecord.rb', line 506 def all_phenotype_features object_ids = synonym_names object_ids<<name PhenotypeFeature.eager_load(:phenotype).where(object_id: object_ids, type: 'Variation') end |
#genes ⇒ Object
613 614 615 |
# File 'lib/ensembl/variation/activerecord.rb', line 613 def genes variation_genenames.pluck(:gene_name) end |
#genotype_code_ids ⇒ Object
583 584 585 |
# File 'lib/ensembl/variation/activerecord.rb', line 583 def genotype_code_ids @genotype_code_ids||=individual_genotypes.values.uniq end |
#genotype_codes ⇒ Object
Unique genotype codes from individual_genotypes
589 590 591 |
# File 'lib/ensembl/variation/activerecord.rb', line 589 def genotype_codes @genotype_codes||=GenotypeCode.genotypes_hash_for(genotype_code_ids) end |
#genotype_counts ⇒ Object
Genotype counts for each population “CSHL-HAPMAP:HapMap-YRI”=>“C|T”=>1}
557 558 559 560 561 562 563 |
# File 'lib/ensembl/variation/activerecord.rb', line 557 def genotype_counts counts = Hash.new{ |hsh,k| hsh[k] = Hash.new 0 } individual_populations.pluck('population.name',:individual_id).map{|ip| [ip[0],genotype_codes[individual_genotypes[ip[1]]]] }.each{|r| counts[r[0]][r[1]]+=1} return counts end |
#individual_genotype_ids ⇒ Object
573 574 575 |
# File 'lib/ensembl/variation/activerecord.rb', line 573 def individual_genotype_ids individual_genotypes.keys end |
#individual_genotypes ⇒ Object
Individual and genotype_code id’s related to variation Example:
- [1,2],,[<individual_id>,<genotype_code_id>]
569 570 571 |
# File 'lib/ensembl/variation/activerecord.rb', line 569 def individual_genotypes @individual_genotypes||=compressed_genotype_vars.map{|cgv| cgv.unpacked_genotypes }.flatten(1).to_h end |
#individual_populations ⇒ Object
IndividualPopulations from individual_genotypes
579 580 581 |
# File 'lib/ensembl/variation/activerecord.rb', line 579 def individual_populations IndividualPopulation.where(individual_id: individual_genotype_ids) end |
#phenotype_features ⇒ Object
502 503 504 |
# File 'lib/ensembl/variation/activerecord.rb', line 502 def phenotype_features PhenotypeFeature.eager_load(:phenotype).where(object_id_column: name, type: 'Variation') end |
#phenotype_features_hash ⇒ Object
Made because of the need to cut down database queries { phenotype_feature_id =>
{ :phenotype=> "Phenotype description" ,
:phenotype_id => _ ,
:p_value => _ ,
:odds_ratio => _,
:risk_allele => _ },
phenotype_feature_id =>
{ :phenotype=> "Phenotype description" ,
:phenotype_id => _ ,
:p_value => _ ,
:odds_ratio => _,
:risk_allele => _ }}
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/ensembl/variation/activerecord.rb', line 526 def phenotype_features_hash # Do enable two level inserts hsh[:first][:second] hash=Hash.new{ |hsh,key| hsh[key] = Hash.new {} } all_phenotype_features .joins(:phenotype) .pluck( :phenotype_feature_id, 'phenotype.description', :phenotype_id) .each{ |r| hash[r[0]][:phenotype]=r[1]; hash[r[0]][:phenotype_id]=r[2]} PhenotypeFeatureAttrib .where(phenotype_feature_id: hash.keys) .pluck( 'phenotype_feature_attrib.phenotype_feature_id', 'phenotype_feature_attrib.value', 'phenotype_feature_attrib.attrib_type_id') .each{ |v| hash[v[0]][AttribType.symbol(v[2])]=v[1] } hash end |
#positions ⇒ Object
617 618 619 |
# File 'lib/ensembl/variation/activerecord.rb', line 617 def positions variation_features.includes(:seq_region).pluck('seq_region.name',:seq_region_start,:seq_region_end,:seq_region_strand).map{|r| Ensembl::Helpers::VariationPosition.new(r)} end |
#synonym_names ⇒ Object
550 551 552 |
# File 'lib/ensembl/variation/activerecord.rb', line 550 def synonym_names variation_synonyms.map{|vs| vs.name} end |