class Ensembl::Core::CoordSystem

The CoordSystem class describes the coordinate system to which a given SeqRegion belongs. It is an interface to the coord_system table of the Ensembl mysql database.

Two virtual coordinate systems exist for every species:

This class uses ActiveRecord to access data in the Ensembl database. See the general documentation of the Ensembl module for more information on what this means and what methods are available.

@example

coord_system = Ensembl::Core::CoordSystem.find_by_name('chromosome')
if coord_system == CoordSystem.toplevel
  puts coord_system.name + " is the toplevel coordinate system."
end

Public Class Methods

find_default_by_name(name) click to toggle source

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 rank 1. However, there might be more than one coordinate system with the name chromosome but with different version (e.g. in human, there is one for the NCBI36 and one for the NCBI35 version). The older version of these is typically given a high number and the one with the new version is the 'default' system.

@return [Ensembl::Core::CoordSystem] Coordinate system object

# File lib/bio-ensembl/core/activerecord.rb, line 296
def self.find_default_by_name(name)
  all_coord_systems_with_name = Ensembl::Core::CoordSystem.find_all_by_name(name)
  if all_coord_systems_with_name.length == 1
    return all_coord_systems_with_name[0]
  else
    return all_coord_systems_with_name.select{|cs| cs.attrib =~ /default_version/}[0]
  end
end

Public Instance Methods

find_level(coord_system_name) click to toggle source

The CoordSystem#find_level class method returns the seqlevel coordinate system corresponding to the name passed.

@param [String] coord_system_name Name of coordinate system @return [Ensembl::Core::CoordSystem] Coordinate system object

# File lib/bio-ensembl/core/activerecord.rb, line 278
def find_level(coord_system_name)
  if Collection.check # When usign multi-species databases
    return CoordSystem.find_by_sql("SELECT * FROM coord_system WHERE name = '#{coord_system_name}' AND species_id = #{self.species_id}")[0]
  else
    return CoordSystem.find_by_name(coord_system_name)
  end
end
find_seqlevel() click to toggle source

The CoordSystem#find_seqlevel class method returns the seqlevel coordinate system.

@return [Ensembl::Core::CoordSystem] Seqlevel coord_system object.

# File lib/bio-ensembl/core/activerecord.rb, line 253
def find_seqlevel
  not_cached = false
  if Ensembl::SESSION.seqlevel_coord_system.nil? 
    not_cached = true
  elsif Collection.check # When usign multi-species databases
    not_cached = true if Ensembl::SESSION.seqlevel_coord_system.species_id != self.species_id
  end
  if not_cached
    if Collection.check
      Ensembl::SESSION.seqlevel_coord_system = CoordSystem.find_by_sql("SELECT * FROM coord_system WHERE attrib LIKE '%sequence_level%' AND species_id = #{self.species_id}")[0]
    else
      Ensembl::SESSION.seqlevel_coord_system = CoordSystem.find_by_sql("SELECT * FROM coord_system WHERE attrib LIKE '%sequence_level%'")[0]
    end  
    Ensembl::SESSION.seqlevel_id = Ensembl::SESSION.seqlevel_coord_system.id
    Ensembl::SESSION.coord_system_ids[Ensembl::SESSION.seqlevel_coord_system.name] = Ensembl::SESSION.seqlevel_id
    Ensembl::SESSION.coord_systems[Ensembl::SESSION.seqlevel_id] = Ensembl::SESSION.seqlevel_coord_system
  end
  return Ensembl::SESSION.seqlevel_coord_system
end
find_toplevel() click to toggle source

The CoordSystem#find_toplevel class method returns the toplevel coordinate system.

@return [Ensembl::Core::CoordSystem] Toplevel coord_system object.

# File lib/bio-ensembl/core/activerecord.rb, line 229
def find_toplevel
  not_cached = false
  if Ensembl::SESSION.toplevel_coord_system.nil? 
    not_cached = true
  elsif Collection.check
    not_cached = true if Ensembl::SESSION.toplevel_coord_system.species_id != self.species_id
  end
  if not_cached
    if Collection.check # When usign multi-species databases
      Ensembl::SESSION.toplevel_coord_system = CoordSystem.find_by_rank_and_species_id(1,self.species_id)
    else
      Ensembl::SESSION.toplevel_coord_system = CoordSystem.find_by_rank(1)
    end
    Ensembl::SESSION.toplevel_id = Ensembl::SESSION.toplevel_coord_system.id
    Ensembl::SESSION.coord_system_ids[Ensembl::SESSION.toplevel_coord_system.name] = Ensembl::SESSION.toplevel_id
    Ensembl::SESSION.coord_systems[Ensembl::SESSION.toplevel_id] = Ensembl::SESSION.toplevel_coord_system
  end
  return Ensembl::SESSION.toplevel_coord_system
end
name_with_version() click to toggle source

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

@return [String] Name of the coordinate system if possible including version

# File lib/bio-ensembl/core/activerecord.rb, line 310
def name_with_version
  if self.version.nil?
    return name
  else
    return [name, version].join(':')
  end
end
seqlevel?() click to toggle source

The CoordSystem#seqlevel? method checks if this coordinate system is the seqlevel coordinate system or not.

@return [Boolean] True if coord_system is seqlevel, else false.

# File lib/bio-ensembl/core/activerecord.rb, line 216
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]
  else
     return true if self == CoordSystem.find_seqlevel
  end
  return false
end
toplevel?() click to toggle source

The CoordSystem#toplevel? method checks if this coordinate system is the toplevel coordinate system or not.

@return [Boolean] True if coord_system is toplevel, else false.

# File lib/bio-ensembl/core/activerecord.rb, line 203
def toplevel?
  if Collection.check # When usign multi-species databases
    return true if self == CoordSystem.find_by_rank_and_species_id(1,self.species_id)
  else
    return true if self == CoordSystem.find_by_rank(1)  
  end
  return false
end