From 0b15495ea76685b030b23a28c9d3d638357dcbda Mon Sep 17 00:00:00 2001 From: "Ricardo H. Ramirez G" Date: Thu, 7 Feb 2013 22:28:26 +0000 Subject: [PATCH 1/6] Updated for active record 3.2 (self.table_name and self.primary_key instead of the set_table_name and set_primary_key) --- Rakefile | 1 + lib/ensembl/core/activerecord.rb | 112 ++++++++++----------- lib/ensembl/core/transcript.rb | 4 +- lib/ensembl/variation/activerecord.rb | 64 ++++++------ lib/ensembl/variation/variation_feature.rb | 4 +- ruby-ensembl-api.gemspec | 5 +- 6 files changed, 96 insertions(+), 94 deletions(-) diff --git a/Rakefile b/Rakefile index 7905809..50bdcd0 100644 --- a/Rakefile +++ b/Rakefile @@ -71,6 +71,7 @@ namespace :test do desc "Run tests for release 60" task :release60 do Dir.glob("test/unit/release_60/**/*.rb").each do |name| + puts "About to run... #{name}" ruby name end end diff --git a/lib/ensembl/core/activerecord.rb b/lib/ensembl/core/activerecord.rb index 22bafef..20fab27 100644 --- a/lib/ensembl/core/activerecord.rb +++ b/lib/ensembl/core/activerecord.rb @@ -192,7 +192,7 @@ def project(coord_system_name) # puts coord_system.name + " is the toplevel coordinate system." # end class CoordSystem < DBConnection - set_primary_key 'coord_system_id' + self.primary_key ='coord_system_id' has_many :seq_regions @@ -350,7 +350,7 @@ def name_with_version # puts gene.biotype # end class SeqRegion < DBConnection - set_primary_key 'seq_region_id' + self.primary_key ='seq_region_id' belongs_to :coord_system has_many :simple_features @@ -520,8 +520,8 @@ def subsequence(start, stop) # puts gene.biotype # end class AssemblyLink < DBConnection - set_table_name 'assembly' - set_primary_key nil + self.table_name = 'assembly' + self.primary_key =nil # See http://blog.hasmanythrough.com/2006/4/21/self-referential-through belongs_to :asm_seq_region, :foreign_key => 'asm_seq_region_id', :class_name => 'SeqRegion' @@ -544,7 +544,7 @@ class AssemblyLink < DBConnection class AssemblyException < DBConnection include Sliceable - set_primary_key 'assembly_exception_id' + self.primary_key ='assembly_exception_id' belongs_to :seq_region end @@ -559,7 +559,7 @@ class AssemblyException < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class MetaCoord < DBConnection - set_primary_key nil + self.primary_key =nil end # The Meta class describes meta data of the database. These include information @@ -572,7 +572,7 @@ class MetaCoord < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class Meta < DBConnection - set_primary_key nil + self.primary_key =nil end # The Analysis class describes an analysis. @@ -585,7 +585,7 @@ class Meta < DBConnection # repeat_masker_analysis = Analysis.find_by_logic_name('RepeatMask') # puts repeat_masker_analysis.to_yaml class Analysis < DBConnection - set_primary_key 'analysis_id' + self.primary_key ='analysis_id' has_many :genes has_many :dna_align_features @@ -609,7 +609,7 @@ class Analysis < DBConnection # descr = AnalysisDescription.find(3) # puts descr.to_yaml class AnalysisDescription < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :analysis end @@ -625,7 +625,7 @@ class AnalysisDescription < DBConnection # seq_region = SeqRegion.find(1) # puts seq_region.dna.sequence class Dna < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :seq_region end @@ -646,7 +646,7 @@ class Dna < DBConnection class Exon < DBConnection include Sliceable - set_primary_key 'exon_id' + self.primary_key ='exon_id' belongs_to :seq_region has_many :exon_transcripts @@ -700,7 +700,7 @@ def self.find_by_stable_id(stable_id) # @example # my_exon = ExonStableId.find_by_stable_id('ENSE00001494622').exon class ExonStableId < DBConnection - set_primary_key 'stable_id' + self.primary_key ='stable_id' belongs_to :exon end @@ -716,15 +716,15 @@ class ExonStableId < DBConnection # puts link.exon.to_yaml # puts link.transcript.to_yaml class ExonTranscript < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :exon belongs_to :transcript end class ExonSupportingFeature < DBConnection - set_table_name 'supporting_feature' - set_primary_key nil + self.table_name = 'supporting_feature' + self.primary_key =nil belongs_to :exon belongs_to :dna_align_feature, :class_name => "DnaAlignFeature", :foreign_key => 'feature_id' @@ -732,7 +732,7 @@ class ExonSupportingFeature < DBConnection end class TranscriptSupportingFeature < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :transcript belongs_to :dna_align_feature, :class_name => "DnaAlignFeature", :foreign_key => 'feature_id' @@ -756,7 +756,7 @@ class TranscriptSupportingFeature < DBConnection class SimpleFeature < DBConnection include Sliceable - set_primary_key 'simple_feature_id' + self.primary_key ='simple_feature_id' belongs_to :seq_region belongs_to :analysis @@ -777,7 +777,7 @@ class SimpleFeature < DBConnection # density_feature = DensityFeature.find(2716384) # puts density_feature.to_yaml class DensityFeature < DBConnection - set_primary_key 'density_feature_id' + self.primary_key ='density_feature_id' belongs_to :density_type belongs_to :seq_region @@ -795,7 +795,7 @@ class DensityFeature < DBConnection # class. See Sliceable and Slice for more information. # class DensityType < DBConnection - set_primary_key 'density_type_id' + self.primary_key ='density_type_id' has_many :density_features belongs_to :analysis @@ -814,7 +814,7 @@ class DensityType < DBConnection # puts marker.right_primer # puts marker.min_primer_dist.to_s class Marker < DBConnection - set_primary_key 'marker_id' + self.primary_key ='marker_id' has_many :marker_features has_many :marker_synonyms @@ -884,7 +884,7 @@ def self.find_all_by_name(name) # puts marker.marker_synonym.source # puts marker.marker_synonym.name class MarkerSynonym < DBConnection - set_primary_key 'marker_synonym_id' + self.primary_key ='marker_synonym_id' belongs_to :marker end @@ -907,7 +907,7 @@ class MarkerSynonym < DBConnection class MarkerFeature < DBConnection include Sliceable - set_primary_key 'marker_feature_id' + self.primary_key ='marker_feature_id' belongs_to :marker belongs_to :seq_region @@ -929,7 +929,7 @@ class MarkerFeature < DBConnection class MiscFeature < DBConnection include Sliceable - set_primary_key 'misc_feature_id' + self.primary_key ='misc_feature_id' belongs_to :seq_region has_one :misc_feature_misc_set @@ -968,7 +968,7 @@ def self.find_all_by_attrib_type_value(code, value) # puts marker.marker_feature.seq_region_start.to_s # puts marker.marker_feature.seq_region_end.to_s class MiscAttrib < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :misc_feature belongs_to :attrib_type @@ -990,7 +990,7 @@ def to_s # feature_set = MiscFeature.find(1) # puts feature_set.features.length.to_s class MiscSet < DBConnection - set_primary_key 'misc_set_id' + self.primary_key ='misc_set_id' has_many :misc_feature_misc_sets has_many :misc_features, :through => :misc_feature_misc_set @@ -1007,7 +1007,7 @@ class MiscSet < DBConnection # @example # # TODO class MiscFeatureMiscSet < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :misc_feature belongs_to :misc_set @@ -1029,7 +1029,7 @@ class MiscFeatureMiscSet < DBConnection class Gene < DBConnection include Sliceable - set_primary_key 'gene_id' + self.primary_key ='gene_id' belongs_to :seq_region has_one :gene_stable_id @@ -1152,7 +1152,7 @@ def canonical_transcript # @example # my_gene = GeneStableId.find_by_stable_id('ENSBTAG00000011670').gene class GeneStableId < DBConnection - set_primary_key 'stable_id' + self.primary_key ='stable_id' belongs_to :gene end @@ -1172,7 +1172,7 @@ class GeneStableId < DBConnection # puts mapping.chromosome_name + "\t" + mapping.position.to_s # end class MarkerMapLocation < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :map belongs_to :marker @@ -1190,7 +1190,7 @@ class MarkerMapLocation < DBConnection # map = Map.find_by_name('MARC') # puts map.markers.length.to_s class Map < DBConnection - set_primary_key 'map_id' + self.primary_key ='map_id' has_many :marker_map_locations has_many :markers, :through => :marker_map_locations @@ -1211,7 +1211,7 @@ def name # repeat = RepeatFeature.find(29) # puts repeat.repeat_consensus.repeat_name + "\t" + repeat.repeat_consensus.repeat_consensus class RepeatConsensus < DBConnection - set_primary_key 'repeat_consensus_id' + self.primary_key ='repeat_consensus_id' has_many :repeat_features end @@ -1233,7 +1233,7 @@ class RepeatConsensus < DBConnection class RepeatFeature < DBConnection include Sliceable - set_primary_key 'repeat_feature_id' + self.primary_key ='repeat_feature_id' belongs_to :repeat_consensus belongs_to :seq_region @@ -1252,7 +1252,7 @@ class RepeatFeature < DBConnection # puts attrib.attrib_type.name + "\t" + attrib.value.to_s # end class SeqRegionAttrib < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :seq_region belongs_to :attrib_type @@ -1268,7 +1268,7 @@ class SeqRegionAttrib < DBConnection # @example # #TODO class GeneAttrib < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :gene belongs_to :attrib_type @@ -1285,7 +1285,7 @@ class GeneAttrib < DBConnection # @example # #TODO class AttribType < DBConnection - set_primary_key 'attrib_type_id' + self.primary_key ='attrib_type_id' has_many :seq_region_attribs has_many :seq_regions, :through => :seq_region_attrib @@ -1309,7 +1309,7 @@ class AttribType < DBConnection # transcript_stable_id = TranscriptStableId.find_by_stable_id('ENSBTAT00000015494') # puts transcript_stable_id.transcript.to_yaml class TranscriptStableId < DBConnection - set_primary_key 'stable_id' + self.primary_key ='stable_id' belongs_to :transcript end @@ -1327,7 +1327,7 @@ class TranscriptStableId < DBConnection # puts attr.attrib_type.name + "\t" + attr.value # end class TranscriptAttrib < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :transcript belongs_to :attrib_type @@ -1353,7 +1353,7 @@ class TranscriptAttrib < DBConnection class DnaAlignFeature < DBConnection include Sliceable - set_primary_key 'dna_align_feature_id' + self.primary_key ='dna_align_feature_id' belongs_to :seq_region belongs_to :analysis @@ -1373,7 +1373,7 @@ class DnaAlignFeature < DBConnection # @example # #TODO class Translation < DBConnection - set_primary_key 'translation_id' + self.primary_key ='translation_id' belongs_to :transcript has_many :translation_stable_ids @@ -1431,7 +1431,7 @@ def self.find_by_stable_id(stable_id) # stable_id = TranslationStableId.find_by_name('ENSBTAP00000015494') # puts stable_id.to_yaml class TranslationStableId < DBConnection - set_primary_key 'stable_id' + self.primary_key ='stable_id' belongs_to :translation end @@ -1450,7 +1450,7 @@ class TranslationStableId < DBConnection # puts attr.attr_type.name + "\t" + attr.value # end class TranslationAttrib < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :translation belongs_to :attrib_type @@ -1470,7 +1470,7 @@ class TranslationAttrib < DBConnection # puts xref.display_label + "\t" + xref.description # end class Xref < DBConnection - set_primary_key 'xref_id' + self.primary_key ='xref_id' belongs_to :external_db has_many :external_synonyms @@ -1495,7 +1495,7 @@ def to_s # puts ox.to_yaml # end class ObjectXref < DBConnection - set_primary_key 'object_xref_id' + self.primary_key ='object_xref_id' belongs_to :gene, :class_name => "Gene", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Gene'"] belongs_to :transcript, :class_name => "Transcript", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Transcript'"] @@ -1512,7 +1512,7 @@ class ObjectXref < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class GoXref < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :xref end @@ -1529,7 +1529,7 @@ class GoXref < DBConnection # embl_db = ExternalDb.find_by_db_name('EMBL') # puts embl_db.xrefs.length.to_s class ExternalDb < DBConnection - set_primary_key 'external_db_id' + self.primary_key ='external_db_id' has_many :xrefs @@ -1582,7 +1582,7 @@ def self.find_by_display_label(label) # xref = Xref.find(185185) # puts xref.external_synonyms[0].synonyms class ExternalSynonym < DBConnection - set_primary_key nil + self.primary_key =nil belongs_to :xref end @@ -1604,7 +1604,7 @@ class ExternalSynonym < DBConnection class Karyotype < DBConnection include Sliceable - set_primary_key 'karyotype_id' + self.primary_key ='karyotype_id' belongs_to :seq_region end @@ -1627,7 +1627,7 @@ class Karyotype < DBConnection class OligoFeature < DBConnection include Sliceable - set_primary_key 'oligo_feature_id' + self.primary_key ='oligo_feature_id' belongs_to :seq_region belongs_to :oligo_probe @@ -1645,7 +1645,7 @@ class OligoFeature < DBConnection # probe = OligoProbe.find_by_name('373:434;') # puts probe.probeset + "\t" + probe.oligo_array.name class OligoProbe < DBConnection - set_primary_key 'oligo_probe_id' + self.primary_key ='oligo_probe_id' has_many :oligo_features belongs_to :oligo_array @@ -1663,7 +1663,7 @@ class OligoProbe < DBConnection # array = OligoArray.find_by_name_and_type('Bovine','AFFY') # puts array.oligo_probes.length class OligoArray < DBConnection - set_primary_key 'oligo_array_id' + self.primary_key ='oligo_array_id' has_many :oligo_probes end @@ -1684,7 +1684,7 @@ class OligoArray < DBConnection class PredictionExon < DBConnection include Sliceable - set_primary_key 'prediction_exon_id' + self.primary_key ='prediction_exon_id' belongs_to :prediction_transcript belongs_to :seq_region @@ -1707,7 +1707,7 @@ class PredictionExon < DBConnection class PredictionTranscript < DBConnection include Sliceable - set_primary_key 'prediction_transcript_id' + self.primary_key ='prediction_transcript_id' has_many :prediction_exons belongs_to :seq_region @@ -1731,7 +1731,7 @@ class PredictionTranscript < DBConnection class ProteinFeature < DBConnection include Sliceable - set_primary_key 'protein_feature_id' + self.primary_key ='protein_feature_id' belongs_to :translation belongs_to :analysis @@ -1757,7 +1757,7 @@ class ProteinFeature < DBConnection class ProteinAlignFeature < DBConnection include Sliceable - set_primary_key 'protein_align_feature_id' + self.primary_key ='protein_align_feature_id' belongs_to :seq_region belongs_to :analysis @@ -1777,7 +1777,7 @@ class ProteinAlignFeature < DBConnection # factor = RegulatoryFactor.find_by_name('crtHsap8070') # puts factor.to_yaml class RegulatoryFactor < DBConnection - set_primary_key 'regulatory_factor_id' + self.primary_key ='regulatory_factor_id' has_many :regulatory_features end @@ -1802,7 +1802,7 @@ class RegulatoryFactor < DBConnection class RegulatoryFeature < DBConnection include Sliceable - set_primary_key 'regulatory_feature_id' + self.primary_key ='regulatory_feature_id' belongs_to :seq_region belongs_to :analysis diff --git a/lib/ensembl/core/transcript.rb b/lib/ensembl/core/transcript.rb index d4493cc..d6551b8 100644 --- a/lib/ensembl/core/transcript.rb +++ b/lib/ensembl/core/transcript.rb @@ -72,8 +72,8 @@ def initialize(exon_1, exon_2) class Transcript < DBConnection include Sliceable - set_table_name 'transcript' - set_primary_key 'transcript_id' + self.primary_key = 'transcript' + self.primary_key = 'transcript_id' belongs_to :gene belongs_to :seq_region diff --git a/lib/ensembl/variation/activerecord.rb b/lib/ensembl/variation/activerecord.rb index fb5d154..956c24e 100644 --- a/lib/ensembl/variation/activerecord.rb +++ b/lib/ensembl/variation/activerecord.rb @@ -23,7 +23,7 @@ module Variation # allele = Allele.find(1) # puts allele.to_yaml class Allele < DBConnection - set_primary_key 'allele_id' + self.primary_key = 'allele_id' belongs_to :sample belongs_to :variation belongs_to :population @@ -42,7 +42,7 @@ class Allele < DBConnection # allele_group = AlleleGroup.find(1) # puts allele_group.to_yaml class AlleleGroup < DBConnection - set_primary_key 'allele_group_id' + self.primary_key = 'allele_group_id' belongs_to :variation_group belongs_to :source belongs_to :sample @@ -66,7 +66,7 @@ class AlleleGroupAllele < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class AttribType < DBConnection - set_primary_key "attrib_type_id" + self.primary_key = "attrib_type_id" end # Store information on associated studies @@ -75,7 +75,7 @@ class AttribType < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class AssociateStudy < DBConnection - set_primary_key "study1_id" + self.primary_key = "study1_id" belongs_to :study end @@ -91,7 +91,7 @@ class ConsequenceMapping < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class FailedDescription < DBConnection - set_primary_key "failed_description_id" + self.primary_key = "failed_description_id" has_many :failed_variations end @@ -99,7 +99,7 @@ class FailedDescription < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class FailedVariation < DBConnection - set_primary_key "failed_variation_id" + self.primary_key = "failed_variation_id" belongs_to :failed_description belongs_to :variation end @@ -108,11 +108,11 @@ class FailedVariation < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class FeatureType < DBConnection - set_primary_key "feature_type_id" + self.primary_key = "feature_type_id" end class Meta < DBConnection - set_primary_key "meta_id" + self.primary_key = "meta_id" end class MetaCoord < DBConnection @@ -120,7 +120,7 @@ class MetaCoord < DBConnection end class Phenotype < DBConnection - set_primary_key "phenotype_id" + self.primary_key = "phenotype_id" has_many :variation_annotations end @@ -130,7 +130,7 @@ class Phenotype < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class Sample < DBConnection - set_primary_key "sample_id" + self.primary_key = "sample_id" has_one :individual has_one :sample_synonym has_many :individual_genotype_multiple_bp @@ -158,7 +158,7 @@ class IndividualPopulation < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class Individual < DBConnection - set_primary_key "sample_id" + self.primary_key = "sample_id" belongs_to :sample has_one :individual_type has_many :individual_populations, :foreign_key => "individual_sample_id" @@ -172,7 +172,7 @@ class IndividualGenotypeMultipleBp < DBConnection end class IndividualType < DBConnection - set_primary_key "invidual_type_id" + self.primary_key = "invidual_type_id" belongs_to :individual end @@ -187,7 +187,7 @@ class ReadCoverage < DBConnection class Population < DBConnection belongs_to :sample - set_primary_key "sample_id" + self.primary_key = "sample_id" has_many :population_genotypes, :foreign_key => "sample_id" has_many :individual_populations, :foreign_key => "population_sample_id" has_many :individuals, :through => :individual_populations @@ -215,7 +215,7 @@ class PopulationStructure < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class PopulationGenotype < DBConnection - set_primary_key "population_genotype_id" + self.primary_key = "population_genotype_id" belongs_to :variation belongs_to :population belongs_to :subsnp_handle @@ -228,7 +228,7 @@ class PopulationGenotype < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class ProteinInfo < DBConnection - set_primary_key "protein_info_id" + self.primary_key = "protein_info_id" belongs_to :transcript_variation has_many :protein_positions end @@ -239,7 +239,7 @@ class ProteinInfo < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class PolyphenPrediction < DBConnection - set_primary_key "polyphen_prediction_id" + self.primary_key = "polyphen_prediction_id" belongs_to :protein_position end @@ -249,7 +249,7 @@ class PolyphenPrediction < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class ProteinPosition < DBConnection - set_primary_key "protein_position_id" + self.primary_key = "protein_position_id" belongs_to :protein_info has_many :polyphen_predictions has_many :sift_predictions @@ -264,7 +264,7 @@ class ProteinPosition < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class SampleSynonym < DBConnection - set_primary_key "sample_synonym_id" + self.primary_key = "sample_synonym_id" belongs_to :source belongs_to :sample belongs_to :population @@ -277,7 +277,7 @@ class SampleSynonym < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class Source < DBConnection - set_primary_key "source_id" + self.primary_key = "source_id" has_many :sample_synonyms has_many :allele_groups has_many :variations @@ -299,7 +299,7 @@ def somatic_status # workaround as ActiveRecord do not parse SET field in MySQL # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class StructuralVariation < DBConnection - set_primary_key "structural_variation_id" + self.primary_key = "structural_variation_id" belongs_to :source belongs_to :seq_region has_many :supporting_structural_variations @@ -319,7 +319,7 @@ def sv_class class SeqRegion < DBConnection - set_primary_key "seq_region_id" + self.primary_key = "seq_region_id" has_many :variation_features has_many :structural_variations end @@ -330,7 +330,7 @@ class SeqRegion < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class SupportingStructuralVariation < DBConnection - set_primary_key "supporting_structural_variation_id" + self.primary_key = "supporting_structural_variation_id" belongs_to :structural_variation end @@ -340,7 +340,7 @@ class SupportingStructuralVariation < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class SubsnpHandle < DBConnection - set_primary_key "subsnp_id" + self.primary_key = "subsnp_id" has_many :individual_genotype_multiple_bps, :foreign_key => "subsnp_id" has_many :population_genotypes, :foreign_key => "subsnp_id" has_many :alleles, :foreign_key => "subsnp_id" @@ -353,7 +353,7 @@ class SubsnpHandle < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class SiftPrediction < DBConnection - set_primary_key "sift_prediction_id" + self.primary_key = "sift_prediction_id" belongs_to :protein_position end @@ -363,7 +363,7 @@ class SiftPrediction < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class Study < DBConnection - set_primary_key "study_id" + self.primary_key = "study_id" has_many :associate_studies, :foreign_key => "study1_id" has_many :structural_variations has_many :variation_annotations @@ -399,7 +399,7 @@ def study_type # end # class Variation < DBConnection - set_primary_key "variation_id" + self.primary_key = "variation_id" belongs_to :source has_many :variation_synonyms has_one :flanking_sequence @@ -428,7 +428,7 @@ def self.fetch_all_by_source(source) # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class VariationSynonym < DBConnection - set_primary_key "variation_synonym_id" + self.primary_key = "variation_synonym_id" belongs_to :variation belongs_to :source belongs_to :subsnp_handle @@ -441,7 +441,7 @@ class VariationSynonym < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class VariationGroup < DBConnection - set_primary_key "variation_group_id" + self.primary_key = "variation_group_id" belongs_to :source has_one :variation_group_variation has_one :httag @@ -467,12 +467,12 @@ class VariationGroupVariation < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class VariationGroupFeature < DBConnection - set_primary_key "variation_group_feature_id" + self.primary_key = "variation_group_feature_id" belongs_to :variation_group end class VariationAnnotation < DBConnection - set_primary_key "variation_annotation_id" + self.primary_key = "variation_annotation_id" belongs_to :variation belongs_to :phenotype belongs_to :source @@ -484,7 +484,7 @@ class VariationAnnotation < DBConnection # See the general documentation of the Ensembl module for # more information on what this means and what methods are available. class VariationSet < DBConnection - set_primary_key "variation_set_id" + self.primary_key = "variation_set_id" has_many :variation_set_variations has_many :variations, :through => :variation_set_variations end @@ -527,7 +527,7 @@ class TaggedVariationFeature < DBConnection end class Httag < DBConnection - set_primary_key "httag_id" + self.primary_key = "httag_id" belongs_to :variation_group belongs_to :source end diff --git a/lib/ensembl/variation/variation_feature.rb b/lib/ensembl/variation/variation_feature.rb index dd41bb7..2a8936b 100644 --- a/lib/ensembl/variation/variation_feature.rb +++ b/lib/ensembl/variation/variation_feature.rb @@ -32,7 +32,7 @@ module Variation # up_region,down_region = vf.flanking_seq (returns two Ensembl::Core::Slice) # class VariationFeature < DBConnection - set_primary_key "variation_feature_id" + self.primary_key = "variation_feature_id" belongs_to :variation has_many :tagged_variation_features has_many :samples, :through => :tagged_variation_features @@ -328,7 +328,7 @@ def check_near_exons(feature,exons_ranges) # end # class TranscriptVariation < DBConnection - set_primary_key "transcript_variation_id" + self.primary_key = "transcript_variation_id" belongs_to :variation_feature validates_inclusion_of :consequence_type, :in => ['ESSENTIAL_SPLICE_SITE', 'STOP_GAINED', diff --git a/ruby-ensembl-api.gemspec b/ruby-ensembl-api.gemspec index 40f80b5..bf55e3c 100644 --- a/ruby-ensembl-api.gemspec +++ b/ruby-ensembl-api.gemspec @@ -17,8 +17,9 @@ Gem::Specification.new do |s| s.test_files = ["test/unit/release_60/core/test_gene.rb","test/unit/release_60/core/test_slice.rb","test/unit/release_60/core/test_transform.rb","test/unit/release_60/core/test_project_human.rb","test/unit/release_60/core/test_transcript.rb","test/unit/release_60/variation/test_activerecord.rb","test/unit/release_60/variation/test_consequence.rb","test/unit/release_60/variation/test_variation.rb","test/unit/test_connection.rb","test/unit/test_releases.rb"] s.add_dependency("bio", [">=1"]) - s.add_dependency("activerecord") - + s.add_dependency("activerecord", [">=3.2"]) + s.add_dependency("activerecord-mysql-adapter") + s.add_dependency("mysql",["=2.8.1"]) s.require_path = "lib" s.bindir = "bin" From 9d41bc0f89839b648b8ed62d3c1d6d18aee79773 Mon Sep 17 00:00:00 2001 From: "Ricardo H. Ramirez G" Date: Thu, 7 Feb 2013 22:41:01 +0000 Subject: [PATCH 2/6] Modified the unit test for the active recrod in the variation module to rounr the frequency to two decimals. --- test/unit/release_60/variation/test_activerecord.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/release_60/variation/test_activerecord.rb b/test/unit/release_60/variation/test_activerecord.rb index 82a99c8..e5007dd 100644 --- a/test/unit/release_60/variation/test_activerecord.rb +++ b/test/unit/release_60/variation/test_activerecord.rb @@ -29,7 +29,7 @@ def teardown def test_allele allele = Allele.find(1) assert_equal('T', allele.allele) - assert_equal(0.04, allele.frequency) + assert_equal(0.04, allele.frequency.round(2)) end def test_sample From d64556fdac8463771e8e2205fa335e445c2319c8 Mon Sep 17 00:00:00 2001 From: "Ricardo H. Ramirez G" Date: Thu, 7 Feb 2013 23:37:36 +0000 Subject: [PATCH 3/6] Added test with database 69, which doesent have the stable_id views --- lib/ensembl/variation/variation_feature62.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ensembl/variation/variation_feature62.rb b/lib/ensembl/variation/variation_feature62.rb index 0ff4f66..d3d4523 100644 --- a/lib/ensembl/variation/variation_feature62.rb +++ b/lib/ensembl/variation/variation_feature62.rb @@ -32,7 +32,7 @@ module Variation # up_region,down_region = vf.flanking_seq (returns two Ensembl::Core::Slice) # class VariationFeature < DBConnection - set_primary_key "variation_feature_id" + self.primary_key = "variation_feature_id" belongs_to :variation has_many :tagged_variation_features has_many :samples, :through => :tagged_variation_features @@ -389,7 +389,7 @@ def check_near_exons(feature,exons_ranges) # end # class TranscriptVariation < DBConnection - set_primary_key "transcript_variation_id" + self.primary_key = "transcript_variation_id" belongs_to :variation_feature validates_inclusion_of :consequence_types, :in => ['intergenic_variant', 'splice_acceptor_variant', From bda8a06b340e86bf3cf44c23f14da93fa798cf44 Mon Sep 17 00:00:00 2001 From: homonecloco Date: Mon, 11 Feb 2013 12:03:50 +0000 Subject: [PATCH 4/6] Added function to retrieve the release version, to be able to decide on how to query --- lib/ensembl/db_connection.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ensembl/db_connection.rb b/lib/ensembl/db_connection.rb index 07d6b06..8fab69d 100644 --- a/lib/ensembl/db_connection.rb +++ b/lib/ensembl/db_connection.rb @@ -53,6 +53,12 @@ def self.get_info end end + def self.release + return @release if @release + @release = self.get_info[6] + @release + end + # Method to retrieve the name of a database, using species, release and connection parameters # passed by the user. def self.get_name_from_db(db_type,species,release,args) From 9d00d677cd9a3c8da73b2be351a8e98332fddfaa Mon Sep 17 00:00:00 2001 From: homonecloco Date: Mon, 11 Feb 2013 17:38:10 +0000 Subject: [PATCH 5/6] Support for the databases without the stable_id tables (core release 65 and after) Issue #20 --- Rakefile | 7 ++ lib/ensembl/core/activerecord.rb | 200 +++++++++++++++++-------------- lib/ensembl/core/transcript.rb | 32 ++--- lib/ensembl/db_connection.rb | 12 ++ 4 files changed, 149 insertions(+), 102 deletions(-) diff --git a/Rakefile b/Rakefile index 50bdcd0..aa6d50c 100644 --- a/Rakefile +++ b/Rakefile @@ -61,6 +61,13 @@ namespace :test do end end + desc "Run tests for release 70" + task :release70 do + Dir.glob("test/unit/release_70/**/*.rb").each do |name| + ruby name + end + end + desc "Run tests for release 62" task :release62 do Dir.glob("test/unit/release_62/**/*.rb").each do |name| diff --git a/lib/ensembl/core/activerecord.rb b/lib/ensembl/core/activerecord.rb index 20fab27..a29dc61 100644 --- a/lib/ensembl/core/activerecord.rb +++ b/lib/ensembl/core/activerecord.rb @@ -85,22 +85,22 @@ module Sliceable # @return [Ensembl::Core::Slice] Ensembl::Core::Slice object def slice start, stop, strand = nil, nil, nil - - if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_start') + + if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_start') start = self.seq_region_start end - if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_end') + if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_end') stop = self.seq_region_end end - if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_strand') + if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_strand') strand = self.seq_region_strand - else #FIXME: we shouldn't do this, but can't #project if no strand given + else #FIXME: we shouldn't do this, but can't #project if no strand given strand = 1 end - + return Ensembl::Core::Slice.new(self.seq_region, start, stop, strand) end - + # The Sliceable#seq method takes the coordinates on a reference, transforms # onto the seqlevel coordinate system if necessary, and retrieves the # sequence. @@ -109,7 +109,7 @@ def slice def seq return self.slice.seq end - + # The Sliceable#start method is a convenience method and returns # self.seq_region_start. # @@ -117,7 +117,7 @@ def seq def start return self.seq_region_start end - + # The Sliceable#stop method is a convenience method and returns # self.seq_region_end. # @@ -125,7 +125,7 @@ def start def stop return self.seq_region_end end - + # The Sliceable#strand method is a convenience method and returns # self.seq_region_strand. # @@ -133,7 +133,7 @@ def stop def strand return self.seq_region_strand end - + # The Sliceable#length method returns the length of the feature (based on # seq_region_start and seq_region_end. # @@ -141,7 +141,7 @@ def strand def length return self.stop - self.start + 1 end - + # The Sliceable#project method is used to transfer coordinates from one # coordinate system to another. Suppose you have a feature on a # contig in human (let's say on contig AC000031.6.1.38703) and you @@ -215,13 +215,13 @@ def toplevel? # @return [Boolean] True if coord_system is seqlevel, else false. def seqlevel? if Collection.check # When usign multi-species databases - return true if self == CoordSystem.find_by_sql("SELECT * FROM coord_system WHERE attrib LIKE '%sequence_level%' AND species_id = #{self.species_id}")[0] + return true if self == CoordSystem.find_by_sql("SELECT * FROM coord_system WHERE attrib LIKE '%sequence_level%' AND species_id = #{self.species_id}")[0] else - return true if self == CoordSystem.find_seqlevel + return true if self == CoordSystem.find_seqlevel end return false end - + # The CoordSystem#find_toplevel class method returns the toplevel coordinate # system. # @@ -245,7 +245,7 @@ def find_toplevel end return Ensembl::SESSION.toplevel_coord_system end - + # The CoordSystem#find_seqlevel class method returns the seqlevel coordinate # system. # @@ -269,7 +269,7 @@ def find_seqlevel end return Ensembl::SESSION.seqlevel_coord_system end - + # The CoordSystem#find_level class method returns the seqlevel coordinate # system corresponding to the name passed. # @@ -282,7 +282,7 @@ def find_level(coord_system_name) return CoordSystem.find_by_name(coord_system_name) end end - + # The CoordSystem#find_default_by_name class method returns the # coordinate system by that name with the lowest rank. Normally, a lower # rank means a 'bigger' coordinate system. The 'chromosome' typically has @@ -301,7 +301,7 @@ def self.find_default_by_name(name) return all_coord_systems_with_name.select{|cs| cs.attrib =~ /default_version/}[0] end end - + # The CoordSystem#name_with_version returns a string containing the name # and version of the coordinate system. If no version is available, then # just the name is returned @@ -314,7 +314,7 @@ def name_with_version return [name, version].join(':') end end - + ## Calculate the shortest path between a source coordinate system and a ## target coordinate system. This can be done by looking for the ## 'assembly.mapping' records in the meta_coord table. @@ -380,7 +380,7 @@ class SeqRegion < DBConnection has_many :cmp_seq_regions, :through => :asm_links_as_asm alias attribs seq_region_attribs - + # The SeqRegion#slice method returns a slice object that covers the whole # of the seq_region. # @@ -388,7 +388,7 @@ class SeqRegion < DBConnection def slice return Ensembl::Core::Slice.new(self) end - + # The SeqRegion#assembled_seq_regions returns the sequence regions on which # the current region is assembled. For example, calling this method on a # contig sequence region, it might return the chromosome that that contig @@ -402,13 +402,13 @@ def assembled_seq_regions(coord_system_name = nil) return self.asm_seq_regions else answer = Array.new - coord_system = CoordSystem.find_by_name(coord_system_name) + coord_system = CoordSystem.find_by_name(coord_system_name) self.asm_seq_regions.each do |asr| if asr.coord_system_id == coord_system.id answer.push(asr) end end - return answer + return answer end end @@ -422,17 +422,17 @@ def assembled_seq_regions(coord_system_name = nil) # @param [String] coord_system_name Name of coordinate system # @return [Array] Array of SeqRegion objects def component_seq_regions(coord_system_name = nil) - if coord_system_name.nil? + if coord_system_name.nil? return self.cmp_seq_regions else answer = Array.new - coord_system = CoordSystem.find_by_name(coord_system_name) + coord_system = CoordSystem.find_by_name(coord_system_name) self.cmp_seq_regions.each do |csr| if csr.coord_system_id == coord_system.id answer.push(csr) end end - return answer + return answer end end @@ -474,7 +474,7 @@ def assembly_links_as_component(coord_system = nil) if coord_system.nil? return self.asm_links_as_cmp else - return self.asm_links_as_cmp.select{|alac| alac.asm_seq_region.coord_system_id == coord_system.id} + return self.asm_links_as_cmp.select{|alac| alac.asm_seq_region.coord_system_id == coord_system.id} end end @@ -496,7 +496,7 @@ def sequence # @param [Integer] stop Stop position # @return [String] DNA sequence def subsequence(start, stop) - return self.seq.slice(start - 1, (stop - start) + 1) + return self.seq.slice(start - 1, (stop - start) + 1) end alias subseq subsequence @@ -543,9 +543,9 @@ class AssemblyLink < DBConnection # This class should normally not be used directly by the user. class AssemblyException < DBConnection include Sliceable - + self.primary_key ='assembly_exception_id' - + belongs_to :seq_region end @@ -662,7 +662,11 @@ class Exon < DBConnection has_many :protein_align_features, :through => :exon_supporting_features, :conditions => ["feature_type = 'protein_align_feature'"] def stable_id + unless self.class.has_stable_id_table? + return read_attribute(:stable_id) + end return self.exon_stable_id.stable_id + end # The Exon#seq method returns the sequence of the exon. @@ -674,20 +678,26 @@ def seq seq_region = self.seq_region Ensembl::SESSION.seq_regions[seq_region.id] = seq_region end - slice = Ensembl::Core::Slice.new(seq_region, seq_region_start, seq_region_end, seq_region_strand) + slice = Ensembl::Core::Slice.new(seq_region, seq_region_start, seq_region_end, seq_region_strand) return slice.seq end - - + + def self.find_by_stable_id(stable_id) - exon_stable_id = ExonStableId.find_by_stable_id(stable_id) - if exon_stable_id.nil? - return nil - else - return exon_stable_id.exon - end + + unless has_stable_id_table? + result = find(:first, :conditions => ["stable_id = ?" , stable_id]) + return result + end + exon_stable_id = ExonStableId.find_by_stable_id(stable_id) + if exon_stable_id.nil? + return nil + else + return exon_stable_id.exon + end + end - + end # The ExonStableId class provides an interface to the exon_stable_id @@ -701,7 +711,7 @@ def self.find_by_stable_id(stable_id) # my_exon = ExonStableId.find_by_stable_id('ENSE00001494622').exon class ExonStableId < DBConnection self.primary_key ='stable_id' - + belongs_to :exon end @@ -725,15 +735,15 @@ class ExonTranscript < DBConnection class ExonSupportingFeature < DBConnection self.table_name = 'supporting_feature' self.primary_key =nil - + belongs_to :exon belongs_to :dna_align_feature, :class_name => "DnaAlignFeature", :foreign_key => 'feature_id' belongs_to :protein_align_feature, :class_name => "ProteinAlignFeature", :foreign_key => 'feature_id' end - + class TranscriptSupportingFeature < DBConnection self.primary_key =nil - + belongs_to :transcript belongs_to :dna_align_feature, :class_name => "DnaAlignFeature", :foreign_key => 'feature_id' belongs_to :protein_align_feature, :class_name => "ProteinAlignFeature", :foreign_key => 'feature_id' @@ -831,7 +841,7 @@ def self.inheritance_column # marker = Marker.find(1) # puts marker.name --> 58017,D29149 def name - self.marker_synonyms.collect{|ms| ms.name}.join(',') + self.marker_synonyms.collect{|ms| ms.name}.join(',') end # The Marker#find_by_name class method returns one marker with this name. @@ -851,12 +861,12 @@ def self.find_by_name(name) # # @return [Array] Empty array or array of Marker objects def self.find_all_by_name(name) - marker_synonyms = Ensembl::Core::MarkerSynonym.find_all_by_name(name) + marker_synonyms = Ensembl::Core::MarkerSynonym.find_all_by_name(name) answers = Array.new - marker_synonyms.each do |ms| + marker_synonyms.each do |ms| answers.push(Ensembl::Core::Marker.find_all_by_marker_id(ms.marker_id)) end - answers.flatten! + answers.flatten! return answers end @@ -868,7 +878,7 @@ def self.find_all_by_name(name) # return output.join("\n") # #end - + end # The MarkerSynonym class provides an interface to the marker_synonym @@ -938,19 +948,19 @@ class MiscFeature < DBConnection has_many :misc_attribs alias attribs misc_attribs - + def self.find_by_attrib_type_value(code, value) return self.find_all_by_attrib_type_value(code, value)[0] end - + def self.find_all_by_attrib_type_value(code, value) code_id = AttribType.find_by_code(code) - misc_attribs = MiscAttrib.find_all_by_attrib_type_id_and_value(code_id, value) + misc_attribs = MiscAttrib.find_all_by_attrib_type_id_and_value(code_id, value) answers = Array.new - misc_attribs.each do |ma| + misc_attribs.each do |ma| answers.push(MiscFeature.find_all_by_misc_feature_id(ma.misc_feature_id)) end - answers.flatten! + answers.flatten! return answers end end @@ -972,7 +982,7 @@ class MiscAttrib < DBConnection belongs_to :misc_feature belongs_to :attrib_type - + def to_s return self.attrib_type.code + ":" + self.value.to_s end @@ -1040,7 +1050,7 @@ class Gene < DBConnection has_many :transcripts belongs_to :analysis - + has_many :object_xrefs, :foreign_key => 'ensembl_id', :conditions => "ensembl_object_type = 'Gene'" has_many :xrefs, :through => :object_xrefs @@ -1049,8 +1059,11 @@ class Gene < DBConnection # The Gene#stable_id method returns the stable_id of the gene (i.e. the # ENSG id). def stable_id - return self.gene_stable_id.stable_id - + unless self.class.has_stable_id_table? + read_attribute(:stable_id) + else + return self.gene_stable_id.stable_id + end end # The Gene#display_label method returns the default name of the gene. @@ -1065,16 +1078,16 @@ def display_label # and returns an array of the corresponding Gene objects. If the name is # not found, it returns an empty array. def self.find_all_by_name(name) - answer = Array.new + answer = Array.new xrefs = Ensembl::Core::Xref.find_all_by_display_label(name) xrefs.each do |xref| answer.push(Ensembl::Core::Gene.find_by_display_xref_id(xref.xref_id)) end - + answer.reject!{|a| a.nil?} - return answer + return answer end - + # The Gene#find_by_name class method searches the Xrefs for that name # and returns one Gene objects (even if there should be more). If the name is # not found, it returns nil. @@ -1086,13 +1099,17 @@ def self.find_by_name(name) return all_names[0] end end - + # The Gene#find_by_stable_id class method fetches a Gene object based on # its stable ID (i.e. the "ENSG" accession number). If the name is # not found, it returns nil. def self.find_by_stable_id(stable_id) result = nil - if stable_id.kind_of? Array + if not self.has_stable_id_table? + result = Gene.where({:stable_id => stable_id }) + result = result.first unless stable_id.kind_of? Array + result = result.map{|gene| gene} if stable_id.kind_of? Array + elsif stable_id.kind_of? Array gene_stable_ids = GeneStableId.where({:stable_id => stable_id}) result = (gene_stable_ids.size == 0) ? nil : gene_stable_ids.map {|id| id.gene} else @@ -1101,7 +1118,7 @@ def self.find_by_stable_id(stable_id) end return result end - + # The Gene#all_xrefs method is a convenience method in that it combines # three methods into one. It collects all xrefs for the gene itself, plus # all xrefs for all transcripts for the gene, and all xrefs for all @@ -1118,13 +1135,13 @@ def all_xrefs answer.flatten! return answer end - + # The Gene#go_terms method returns all GO terms associated with a gene. def go_terms go_db_id = ExternalDb.find_by_db_name('GO').id return self.all_xrefs.select{|x| x.external_db_id == go_db_id}.collect{|x| x.dbprimary_acc}.uniq end - + # The Gene#hgnc returns the HGNC symbol for the gene. def hgnc hgnc_db_id = ExternalDb.find_by_db_name('HGNC_curated_gene').id @@ -1134,12 +1151,12 @@ def hgnc end end - + # The Gene#canonical_transcript returns the longest transcript for that gene. # def canonical_transcript - ct = self.transcripts.sort {|a,b| b.seq.length <=> a.seq.length} - return ct[0] + ct = self.transcripts.sort {|a,b| b.seq.length <=> a.seq.length} + return ct[0] end # The GeneStableId class provides an interface to the gene_stable_id @@ -1176,7 +1193,7 @@ class MarkerMapLocation < DBConnection belongs_to :map belongs_to :marker - + end # The Map class provides an interface to the map @@ -1196,7 +1213,7 @@ class Map < DBConnection has_many :markers, :through => :marker_map_locations def name - return self.map_name + return self.map_name end end @@ -1357,7 +1374,7 @@ class DnaAlignFeature < DBConnection belongs_to :seq_region belongs_to :analysis - + has_many :exon_supporting_features has_many :protein_supporting_features end @@ -1380,22 +1397,25 @@ class Translation < DBConnection has_many :translation_attribs has_many :protein_features - + has_one :translation_stable_id - + has_many :object_xrefs, :foreign_key => 'ensembl_id', :conditions => "ensembl_object_type = 'Translation'" has_many :xrefs, :through => :object_xrefs - + belongs_to :start_exon, :class_name => 'Exon', :foreign_key => 'start_exon_id' belongs_to :end_exon, :class_name => 'Exon', :foreign_key => 'end_exon_id' alias attribs translation_attribs - + # The Translation#stable_id method returns the stable ID of the translation. # # @return [String] Ensembl stable ID def stable_id - return self.translation_stable_id.stable_id + unless self.class.has_stable_id_table? + return read_attribute(:stable_id) + end + return self.translation_stable_id.stable_id end # The Translation#display_label method returns the default name of the translation. @@ -1410,6 +1430,10 @@ def display_label # object based on its stable ID (i.e. the "ENSP" accession number). If the # name is not found, it returns nil. def self.find_by_stable_id(stable_id) + unless has_stable_id_table? + result = find(:first, :conditions => ["stable_id = ?" , stable_id]) + return result + end translation_stable_id = TranslationStableId.find_by_stable_id(stable_id) if translation_stable_id.nil? return nil @@ -1476,7 +1500,7 @@ class Xref < DBConnection has_many :external_synonyms has_many :genes - + def to_s return self.external_db.db_name.to_s + ":" + self.display_label end @@ -1496,14 +1520,14 @@ def to_s # end class ObjectXref < DBConnection self.primary_key ='object_xref_id' - + belongs_to :gene, :class_name => "Gene", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Gene'"] belongs_to :transcript, :class_name => "Transcript", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Transcript'"] belongs_to :translation, :class_name => "Translation", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Translation'"] belongs_to :xref has_one :go_xref end - + # The GoXref class provides an interface to the # go_xref table. This table contains the evidence codes for those object_refs # that are GO terms. @@ -1513,7 +1537,7 @@ class ObjectXref < DBConnection # more information on what this means and what methods are available. class GoXref < DBConnection self.primary_key =nil - + belongs_to :xref end @@ -1542,15 +1566,15 @@ def self.inheritance_column # one. If no databases are found with this name, this method returns an # empty array. def self.find_all_by_display_label(label) - answer = Array.new + answer = Array.new xrefs = Xref.find_all_by_display_label(label) - xrefs.each do |xref| + xrefs.each do |xref| answer.push(self.class.find_by_xref_id(xref.xref_id)) end return answer end - + # The ExternalDb#find_by_display_label method returns a # database that has this label. If no databases are found with this name, # this method returns nil. @@ -1564,7 +1588,7 @@ def self.find_by_display_label(label) end end - + end # The ExternalSynonym class provides an interface to the @@ -1761,7 +1785,7 @@ class ProteinAlignFeature < DBConnection belongs_to :seq_region belongs_to :analysis - + has_many :exon_supporting_features has_many :transcript_supporting_features end diff --git a/lib/ensembl/core/transcript.rb b/lib/ensembl/core/transcript.rb index d6551b8..b99e223 100644 --- a/lib/ensembl/core/transcript.rb +++ b/lib/ensembl/core/transcript.rb @@ -125,6 +125,9 @@ def introns # # @return [String] Ensembl stable ID of the transcript. def stable_id + unless self.class.has_stable_id_table? + return read_attribute(:stable_id) + end return self.transcript_stable_id.stable_id end @@ -141,29 +144,30 @@ def display_label # array is returned. def self.find_all_by_stable_id(stable_id) answer = Array.new - transcript_stable_id_objects = Ensembl::Core::TranscriptStableId.find_all_by_stable_id(stable_id) - transcript_stable_id_objects.each do |transcript_stable_id_object| - answer.push(Ensembl::Core::Transcript.find(transcript_stable_id_object.transcript_id)) + + if not has_stable_id_table? + #result = find(:first, :conditions => ["stable_id = ?" , stable_id]) + answer = where({:stable_id => stable_id }) + + else + transcript_stable_id_objects = Ensembl::Core::TranscriptStableId.find_all_by_stable_id(stable_id) + transcript_stable_id_objects.each do |transcript_stable_id_object| + answer.push(Ensembl::Core::Transcript.find(transcript_stable_id_object.transcript_id)) + end end - return answer end - # The Transcript#find_all_by_stable_id class method returns a - # transcripts with the given stable_id. If none was found, nil is returned. - def self.find_by_stable_id(stable_id) - all = self.find_all_by_stable_id(stable_id) - if all.length == 0 - return nil - else - return all[0] - end - end + # The Transcript#find_by_stable_id class method fetches a Transcript object based on # its stable ID (i.e. the "ENST" accession number). If the name is # not found, it returns nil. def self.find_by_stable_id(stable_id) + unless has_stable_id_table? + result = find(:first, :conditions => ["stable_id = ?" , stable_id]) + return result + end transcript_stable_id = TranscriptStableId.find_by_stable_id(stable_id) if transcript_stable_id.nil? return nil diff --git a/lib/ensembl/db_connection.rb b/lib/ensembl/db_connection.rb index 8fab69d..75a0ea0 100644 --- a/lib/ensembl/db_connection.rb +++ b/lib/ensembl/db_connection.rb @@ -53,12 +53,20 @@ def self.get_info end end + #Retrieves the Release of the database. This doesn't work with Ensemble Genomes that have a different naming convention. def self.release return @release if @release @release = self.get_info[6] @release end + #Figures out if the database where it is connected has stable_id tables (Removed from version 65). + def self.has_stable_id_table? + @@has_stable_id = self.connection.table_exists? ('gene_stable_id') unless @@has_stable_id_defined + @@has_stable_id_defined = true + @@has_stable_id + end + # Method to retrieve the name of a database, using species, release and connection parameters # passed by the user. def self.get_name_from_db(db_type,species,release,args) @@ -91,6 +99,9 @@ def self.get_name_from_db(db_type,species,release,args) end def self.generic_connect(db_type, species, release, args = {}) + #Clears the variables that check if certain fetures are available + @@has_stable_id_defined = false + # check which release is used and load the correct VariationFeature version require (release < 62) ? File.dirname(__FILE__) + '/variation/variation_feature.rb' : File.dirname(__FILE__) + '/variation/variation_feature62.rb' @@ -101,6 +112,7 @@ def self.generic_connect(db_type, species, release, args = {}) if args[:ensembl_genomes] then args[:port] = EG_PORT args[:host] = EG_HOST + end if args[:port].nil? then args[:port] = ( release > 47 ) ? 5306 : 3306 From ed5461aefad6bdf9edae3abe207dc063aa9944b2 Mon Sep 17 00:00:00 2001 From: homonecloco Date: Mon, 11 Feb 2013 17:39:55 +0000 Subject: [PATCH 6/6] Support for the databases without the stable_id tables (core release 65 and after) Issue #20 --- test/unit/release_70/core/test_stable_id.rb | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 test/unit/release_70/core/test_stable_id.rb diff --git a/test/unit/release_70/core/test_stable_id.rb b/test/unit/release_70/core/test_stable_id.rb new file mode 100644 index 0000000..d08af99 --- /dev/null +++ b/test/unit/release_70/core/test_stable_id.rb @@ -0,0 +1,72 @@ +# +# = test/unit/release_62/core/test_gene.rb - Unit test for Ensembl::Core +# +# Copyright:: Copyright (C) 20013 Ricardo H. Ramirez G +# +# License:: Ruby's +# +# $Id: + +require 'pathname' +libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s +$:.unshift(libpath) unless $:.include?(libpath) + +require 'test/unit' +require 'ensembl' + +include Ensembl::Core + +class TestStableId < Test::Unit::TestCase + + def setup + Ensembl::Core::DBConnection.ensemblgenomes_connect("arabidopsis_thaliana",70, {:database => "arabidopsis_thaliana_core_17_70_10" }) + end + + def teardown + DBConnection.remove_connection + end + + def test_gene + ids = %w(AT1G32045 AT3G18710 AT4G25880 AT1G71695 AT5G41480) + genes = Gene.find_by_stable_id(ids) + assert_equal(5,genes.size) + #We can't assure the order. + assert_equal("AT1G32045", genes[0].stable_id) + + + gene = Gene.find_by_stable_id("AT3G18710") + genes = Gene.find_by_stable_id(ids) + assert_equal("AT3G18710",gene.stable_id) + + end + + def test_exon + exon = Exon.find_by_stable_id("AT4G25880-E.2") + assert_equal("AT4G25880-E.2", exon.stable_id) + end + + #No test for operon/operon_transcript + + + def test_translation + translation = Translation.find_by_stable_id("AT3G18710.1") + assert_equal("AT3G18710.1", translation.stable_id) + + end + + def test_transcript + transcript = Transcript.find_by_stable_id("AT3G18710.1") + assert_equal("AT3G18710.1", transcript.stable_id) + + ids = %w(AT4G25880.2 AT3G18710.1 AT4G25880.3) + transcripts = Transcript.find_all_by_stable_id(ids) + assert_equal(3, transcripts.size) + assert_equal("AT3G18710.1", transcript.stable_id) + + end + + + +# exon, gene, operon, operon_transcript, translation and transcript + +end \ No newline at end of file