# Copyright:: # Copyright (C) 2011 MISHIMA, Hiroyuki # License:: The Ruby licence (Ryby's / GPLv2 dual) # # this table is actually separated # into "chr1_*", "chr2_*", etc. This class dynamically # define *::Chr1_*, *::Chr2_*, etc. The # find_by_interval calls an appropreate class automatically. module Bio module Ucsc module Dm3 class Rmsk include DBConnector DBConnection.database "dm3" KLASS = "Rmsk" KLASS_S = KLASS[0..0].downcase + KLASS[1..-1] def self.find_by_interval(interval, opt = {:partial => true}); interval = Bio::Ucsc::Gi.wrap(interval) chrom = interval.chrom[0..0].upcase + interval.chrom[1..-1] chr_klass = self.const_get("#{chrom}_#{KLASS}") chr_klass.__send__(:find_by_interval, interval, opt) end def self.find_all_by_interval(interval, opt = {:partial => true}); interval = Bio::Ucsc::Gi.wrap(interval) chrom = interval.chrom[0..0].upcase + interval.chrom[1..-1] chr_klass = self.const_get("#{chrom}_#{KLASS}") chr_klass.__send__(:find_all_by_interval, interval, opt) end Bio::Ucsc::Dm3::CHROMS.each do |chr| class_eval %! class #{chr[0..0].upcase + chr[1..-1]}_#{KLASS} < DBConnection self.table_name = "#{chr[0..0].downcase + chr[1..-1]}_#{KLASS_S}" self.primary_key = nil self.inheritance_column = nil def self.find_by_interval(interval, opt = {:partial => true}); interval = Bio::Ucsc::Gi.wrap(interval) find_first_or_all_by_interval(interval, :first, opt) end def self.find_all_by_interval(interval, opt = {:partial => true}); interval = Bio::Ucsc::Gi.wrap(interval) find_first_or_all_by_interval(interval, :all, opt) end def self.find_first_or_all_by_interval(interval, first_all, opt); interval = Bio::Ucsc::Gi.wrap(interval) zstart = interval.zero_start zend = interval.zero_end if opt[:partial] == true where = <<-SQL genoName = :chrom AND bin in (:bins) AND ((genoStart BETWEEN :zstart AND :zend) OR (genoEnd BETWEEN :zstart AND :zend) OR (genoStart <= :zstart AND genoEnd >= :zend)) SQL else where = <<-SQL genoName = :chrom AND bin in (:bins) AND ((genoStart BETWEEN :zstart AND :zend) AND (genoEnd BETWEEN :zstart AND :zend)) SQL end cond = { :chrom => interval.chrom, :bins => Bio::Ucsc::UcscBin.bin_all(zstart, zend), :zstart => zstart, :zend => zend, } self.find(first_all, { :select => "*", :conditions => [where, cond], }) end end ! end # each chromosome end # class end # module end # module Ucsc end # module Bio