[BioRuby] locus mixin
Naohisa GOTO
ngoto at gen-info.osaka-u.ac.jp
Sat Jun 13 06:05:01 UTC 2009
Hi,
On Fri, 12 Jun 2009 10:53:08 +0100
Jan Aerts <jan.aerts at gmail.com> wrote:
> 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:
What classes are considered the module to be mixed in?
In BioRuby, as far as I know, there are currently no classes
which have all of these methods simultaneously.
I think only putting a mixin is not a good way. It is better to
prepare some classes which can handle real data (which can probably
be downloaded from famous genome/expression data repositories) and
can perform typical tasks conveniently.
Naohisa Goto
ngoto at gen-info.osaka-u.ac.jp / ng at bioruby.org
> 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.
> _______________________________________________
> BioRuby mailing list
> BioRuby at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioruby
More information about the BioRuby
mailing list