[BioRuby] locus mixin
Jan Aerts
jan.aerts at gmail.com
Fri Jun 12 09:53:08 UTC 2009
What do people think about adding a IsLocus mixin to bioruby? For a lot of
my work I need to check if genes or polymorphisms or clones or ... overlap.
I use the IsLocus mixin to get that done. Any object that has a chromosome,
start and stop can have the module mixed in. Some of the methods as I have
them defined locally:
module IsLocus
def range
return Range.new(self.start, self.stop)
end
def overlaps?(other_locus)
return false if self.chromosome != other_locus.chromosome
if self.range.overlaps?(other_locus.range)
return true
end
return false
end
def contained_by?(other_locus)
return false if self.chromosome != other_locus.chromosome
if self.range.contained_by?(other_locus.range)
return true
end
return false
end
def contains?(other_locus)
return false if self.chromosome != other_locus.chromosome
if self.range.contains?(other_locus.range)
return true
end
return false
end
def to_s
return self.chromosome + ':' + self.range.to_s
end
def to_gff3
return [self.chromosome, self.class.name, self.start, self.stop, '.',
'.', '.', 'ID=' + self.id.to_s].join("\t")
end
def to_bed
if self.respond_to?(:name)
return [self.chromosome, self.start, self.stop, self.name].join("\t")
else
return [self.chromosome, self.start, self.stop, self.class.name + '_'
+ self.id.to_s].join("\t")
end
end
# The following makes it possible to call Gene#to_bed which would dump all
Gene objects in BED format
def self.included mod
class << mod
def to_bed
output = Array.new
output.push("track name='#{self.name}' description='#{self.name}'")
self.all.each do |record|
output.push record.to_bed
end
return output.join("\n")
end
end
end
end
Let me know what you think,
jan.
More information about the BioRuby
mailing list