Class: Ensembl::Core::CoordSystem

Inherits:
DBConnection show all
Defined in:
lib/bio-ensembl/core/activerecord.rb

Overview

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:

  • toplevel: the coordinate system with rank 1

  • seqlevel: the coordinate system that contains the seq_regions

with the sequence

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.

Examples:

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DBConnection

connect, ensemblgenomes_connect

Methods inherited from DBRegistry::Base

generic_connect, get_info, get_name_from_db

Class Method Details

.find_default_by_name(name) ⇒ Ensembl::Core::CoordSystem

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.

Returns:



296
297
298
299
300
301
302
303
# 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

Instance Method Details

#find_level(coord_system_name) ⇒ Ensembl::Core::CoordSystem

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

Parameters:

  • coord_system_name (String)

    Name of coordinate system

Returns:



278
279
280
281
282
283
284
# 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_seqlevelEnsembl::Core::CoordSystem

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

Returns:



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# 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_toplevelEnsembl::Core::CoordSystem

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

Returns:



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# 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_versionString

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

Returns:

  • (String)

    Name of the coordinate system if possible including version



310
311
312
313
314
315
316
# 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?Boolean

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

Returns:

  • (Boolean)

    True if coord_system is seqlevel, else false.



216
217
218
219
220
221
222
223
# 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?Boolean

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

Returns:

  • (Boolean)

    True if coord_system is toplevel, else false.



203
204
205
206
207
208
209
210
# 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