Class: Feature
- Inherits:
-
Object
- Object
- Feature
- Defined in:
- lib/gene_assembler/gff_feature.rb
Direct Known Subclasses
Constant Summary collapse
- @@undefined_features =
0
Instance Attribute Summary collapse
-
#attribs ⇒ Object
Returns the value of attribute attribs.
-
#child ⇒ Object
Returns the value of attribute child.
-
#phase ⇒ Object
Returns the value of attribute phase.
-
#score ⇒ Object
Returns the value of attribute score.
-
#source ⇒ Object
Returns the value of attribute source.
-
#start ⇒ Object
Returns the value of attribute start.
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#strand ⇒ Object
Returns the value of attribute strand.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_attribs(array_attribs) ⇒ Object
- #add_child(source, type, start, stop, score, strand, phase, attribs) ⇒ Object
- #attrib(tag) ⇒ Object
- #cds ⇒ Object
- #change_to_type_id_recursive(parent = FALSE) ⇒ Object
-
#compare(feature) ⇒ Object
Resultado oscila entre 0 y 1.
- #count ⇒ Object
- #each_child ⇒ Object
- #each_tag_attrib ⇒ Object
-
#initialize(source, type, start, stop, score, strand, phase, attribs) ⇒ Feature
constructor
A new instance of Feature.
- #inspects ⇒ Object
- #is_source?(source) ⇒ Boolean
- #is_type?(type) ⇒ Boolean
- #length ⇒ Object
- #transfer_child(id, child) ⇒ Object
- #tree(level = 0) ⇒ Object
- #write(file, id) ⇒ Object
Constructor Details
#initialize(source, type, start, stop, score, strand, phase, attribs) ⇒ Feature
Returns a new instance of Feature.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#attribs ⇒ Object
Returns the value of attribute attribs.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def attribs @attribs end |
#child ⇒ Object
Returns the value of attribute child.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def child @child end |
#phase ⇒ Object
Returns the value of attribute phase.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def phase @phase end |
#score ⇒ Object
Returns the value of attribute score.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def score @score end |
#source ⇒ Object
Returns the value of attribute source.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def source @source end |
#start ⇒ Object
Returns the value of attribute start.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def start @start end |
#stop ⇒ Object
Returns the value of attribute stop.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def stop @stop end |
#strand ⇒ Object
Returns the value of attribute strand.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def strand @strand end |
#type ⇒ Object
Returns the value of attribute type.
2 3 4 |
# File 'lib/gene_assembler/gff_feature.rb', line 2 def type @type end |
Instance Method Details
#add_attribs(array_attribs) ⇒ Object
167 168 169 170 171 172 173 |
# 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) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
52 53 54 55 |
# File 'lib/gene_assembler/gff_feature.rb', line 52 def attrib(tag) attrib=@attribs[tag] return attrib end |
#cds ⇒ Object
75 76 77 78 79 80 81 82 83 |
# 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) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# 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) ⇒ Object
Resultado oscila entre 0 y 1
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# 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 ⇒ Object
71 72 73 |
# File 'lib/gene_assembler/gff_feature.rb', line 71 def count return @child.count end |
#each_child ⇒ Object
46 47 48 49 50 |
# File 'lib/gene_assembler/gff_feature.rb', line 46 def each_child @child.each_value do |child| yield child end end |
#each_tag_attrib ⇒ Object
57 58 59 60 61 |
# File 'lib/gene_assembler/gff_feature.rb', line 57 def each_tag_attrib @attribs.each do |tag,attrib| yield tag,attrib end end |
#inspects ⇒ Object
63 64 65 66 67 68 69 |
# 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) ⇒ Boolean
105 106 107 108 109 110 111 112 113 114 115 |
# 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) ⇒ Boolean
93 94 95 96 97 98 99 100 101 102 103 |
# 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 ⇒ Object
131 132 133 134 |
# File 'lib/gene_assembler/gff_feature.rb', line 131 def length length=self.stop-(self.start-1) return length end |
#transfer_child(id, child) ⇒ Object
42 43 44 |
# File 'lib/gene_assembler/gff_feature.rb', line 42 def transfer_child(id,child) @child[id]=child end |
#tree(level = 0) ⇒ Object
85 86 87 88 89 90 91 |
# 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) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# 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 |