class Feature
Attributes
attribs[RW]
child[RW]
phase[RW]
score[RW]
source[RW]
start[RW]
stop[RW]
strand[RW]
type[RW]
Public Class Methods
new(source, type, start, stop, score, strand, phase, attribs)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 4 def initialize(source, type, start, stop, score, strand, phase, attribs) @source=source @type=type @start=start.to_i @stop=stop.to_i if score=='.' @score='.' else @score=score.to_f end @strand=strand if phase=='.' @phase='.' else @phase=phase.to_i end @attribs=attribs if attrib('Name').nil? #AƱade el atributo name en base a la ID de forma automatica @attribs['Name']=attrib('ID') else revised_name = @attribs['Name'] revised_name.gsub!(';','-') @attribs['Name'] = revised_name end @child={} end
Public Instance Methods
add_attribs(array_attribs)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 167 def add_attribs(array_attribs) array_attribs.each do |attrib| if !attrib[1].nil? @attribs[attrib[0]]=attrib[1] end end end
add_child(source, type, start, stop, score, strand, phase, attribs)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 31 def add_child(source, type, start, stop, score, strand, phase, attribs) child=Feature.new(source, type, start, stop, score, strand, phase, attribs) if !attribs['ID'].nil? @child[attribs['ID']]=child else @child[child.attrib('Parent')+'_'+@@undefined_features.to_s]=child @@undefined_features+=1 end return child end
attrib(tag)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 52 def attrib(tag) attrib=@attribs[tag] return attrib end
cds()
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 75 def cds cds_exones=[] @child.each do |key_cds| if key_cds[1].type=='CDS' cds_exones << [key_cds[1].start, key_cds[1].stop] end end return cds_exones end
change_to_type_id_recursive(parent=FALSE)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 137 def change_to_type_id_recursive(parent=FALSE) new_parent="#{attrib('ID')}_#{@type}" if !attrib('ID').nil? @attribs['ID']=new_parent end if !attrib('Name').nil? @attribs['Name']=new_parent end if !attrib('Parent').nil? && parent @attribs['Parent']=parent end each_child {|child| child.change_to_type_id_recursive(new_parent) } end
compare(feature)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 117 def compare(feature) #Resultado oscila entre 0 y 1 overlap=0 if feature.start >= self.start && feature.start <= self.stop && feature.stop >= self.start && feature.stop <= self.stop overlap=feature.length*1.00/self.length elsif self.start >= feature.start && self.start <= feature.stop && self.stop >= feature.start && self.stop <= feature.stop overlap=1 elsif feature.start > self.start && feature.start < self.stop overlap=(self.stop-feature.start)*1.00/self.length elsif feature.stop > self.start && feature.stop < self.stop overlap=(feature.stop-self.start)*1.00/self.length end return overlap end
count()
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 71 def count return @child.count end
each_child() { |child| ... }
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 46 def each_child @child.each_value do |child| yield child end end
each_tag_attrib() { |tag,attrib| ... }
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 57 def each_tag_attrib @attribs.each do |tag,attrib| yield tag,attrib end end
inspects()
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 63 def inspects print attrib('ID')+" ---> " @child.keys.each do |ch| print "#{ch} (#{@child[ch].count})\t" end print "\n" end
is_source?(source)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 105 def is_source?(source) s=FALSE source=[source].flatten source.each do |sour| if sour == @source s=TRUE break end end return s end
is_type?(type)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 93 def is_type?(type) t=FALSE type=[type].flatten type.each do |typ| if typ == @type t=TRUE break end end return t end
length()
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 131 def length length=self.stop-(self.start-1) return length end
transfer_child(id,child)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 42 def transfer_child(id,child) @child[id]=child end
tree(level=0)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 85 def tree(level=0) puts "\t"*level+"#{attrib('ID')}\t\t#{@type}\t#{@source}" level+=1 each_child {|child| child.tree(level) } end
write(file,id)
click to toggle source
# File lib/gene_assembler/gff_feature.rb, line 156 def write(file,id) file.print "#{id}\t#{@source}\t#{@type}\t#{@start}\t#{@stop}\t#{@score}\t#{@strand}\t#{@phase}\t" each_tag_attrib {|tag,attrib| file.print "#{tag}=#{attrib};" } file.puts #Print \n each_child {|child| child.write(file,id) } end