class SolveBio::GenomicFilter
Constants
- FIELD_CHR
- FIELD_START
Standardized fields for genomic coordinates in
SolveBio
- FIELD_STOP
Public Class Methods
from_string(string, exact=false)
click to toggle source
Handles UCSC-style range queries (chr1:100-200)
# File lib/solvebio/filter.rb, line 256 def self.from_string(string, exact=false) begin chromosome, pos = string.split(':') rescue ValueError raise ValueError, 'Please use UCSC-style format: "chr2:1000-2000"' end if pos.member?('-') start, stop = pos.replace(',', '').split('-') else start = stop = pos.replace(',', '') end return self.new(chromosome, start, stop, exact) end
new(chromosome, start, stop=nil, exact=false)
click to toggle source
This class supports single position and range filters.
By default, the filter will match any record that overlaps with the position or range specified. Exact matches must be explicitly specified using the `exact` parameter.
# File lib/solvebio/filter.rb, line 278 def initialize(chromosome, start, stop=nil, exact=false) begin if not start.nil? start = Integer(start) end stop = stop ? Integer(stop) : start rescue ValueError raise ValueError('Start and stop positions must be integers or nil') end if exact or start.nil? # Handle the case where start is None because sometimes # a record will have only the chromosome set (no positions). f = SolveBio::Filter.new({FIELD_START => start, FIELD_STOP => stop}) else f = SolveBio::Filter.new({"#{FIELD_START}__lte" => start, "#{FIELD_STOP}__gte" => stop}) if start != stop f |= SolveBio::Filter.new({"#{FIELD_START}__range" => [start, stop]}) f |= SolveBio::Filter.new({"#{FIELD_STOP}__range" => [start, stop]}) end end if chromosome.nil? f &= SolveBio::Filter.new({"#{FIELD_CHR}" => nil}) else f &= SolveBio::Filter.new({"#{FIELD_CHR}" => chromosome.sub('chr', '')}) end @filters = f.filters end
Public Instance Methods
inspect()
click to toggle source
# File lib/solvebio/filter.rb, line 313 def inspect return "<GenomicFilter #{@filters}>" end