Class: Gff_dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/gene_assembler/gff_dataset.rb

Constant Summary collapse

@@undefined_features =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGff_dataset

Returns a new instance of Gff_dataset.



6
7
8
9
# File 'lib/gene_assembler/gff_dataset.rb', line 6

def initialize
	@master_features={}
	@index={}	
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



5
6
7
# File 'lib/gene_assembler/gff_dataset.rb', line 5

def index
  @index
end

#master_featuresObject

Returns the value of attribute master_features.



5
6
7
# File 'lib/gene_assembler/gff_dataset.rb', line 5

def master_features
  @master_features
end

Instance Method Details

#add_feature(source, type, start, stop, score, strand, phase, attribs) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/gene_assembler/gff_dataset.rb', line 44

def add_feature(source, type, start, stop, score, strand, phase, attribs)
	feature=@index[attribs['Parent']].add_child(source, type, start, stop, score, strand, phase, attribs)
	if !attribs['ID'].nil?
   		@index[attribs['ID']]=feature
   	else
   		@index[feature.attrib('Parent')+'_'+@@undefined_features.to_s]=feature
   		@@undefined_features+=1
    	end
	return feature
end

#add_master_feature(master_seq_id, source, type, start, stop, score, strand, phase, attribs) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gene_assembler/gff_dataset.rb', line 20

def add_master_feature(master_seq_id, source, type, start, stop, score, strand, phase, attribs)
	master=nil
	if @index.key?(master_seq_id)#Check that feature region exists, if exists add master feature like a child of that region
		attribs['Parent']=master_seq_id
		master=add_feature(source, type, start, stop, score, strand, phase, attribs)
		@index[attribs['ID']]=master
		if stop.to_i > @master_features[master_seq_id].stop #Redefine master_feature with new child
		  @master_features[master_seq_id].stop=stop.to_i
		end
	elsif attribs['ID']==master_seq_id #Check that exists a parent region for master_feature
		master=Master_feature.new(source, type, start, stop, score, strand, phase, attribs)	
		@master_features[master_seq_id]=master
		@index[master_seq_id]=master
	else #Creates a master feature with his child if it'sn defined master_feature
		master=Master_feature.new(source, 'region', 1, stop, '.', '.', '.', {'ID'=> master_seq_id})	
		@master_features[master_seq_id]=master
		@index[master_seq_id]=master
		attribs['Parent']=master_seq_id
		child=master.add_child(source, type, start, stop, score, strand, phase, attribs)
		@index[attribs['ID']]=child
	end
	return master
end

#add_parent_to(type_parent, type_child) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/gene_assembler/gff_dataset.rb', line 137

def add_parent_to(type_parent,type_child)
  each_id_feat {|id,feature|
    if feature.type==type_child
      new_feature=Feature.new(feature.source, type_parent, feature.start, feature.stop, '.', feature.strand, '.', feature.attribs.dup)
      feature.change_to_type_id_recursive
      new_feature.transfer_child(feature.attrib('ID'),feature)
      @index[feature.attrib('Parent')].child[id]=new_feature
      @index[id]=new_feature
      new_feature.each_child {|child|
        child.attribs['Parent']=new_feature.attrib('ID') #Define new parent
      }
    end
  }
end

#each_featureObject



55
56
57
58
59
# File 'lib/gene_assembler/gff_dataset.rb', line 55

def each_feature
  @index.each_value do |feature|
    yield feature
  end
end

#each_id_featObject



67
68
69
70
71
# File 'lib/gene_assembler/gff_dataset.rb', line 67

def each_id_feat
  @index.each do |id,feature|
    yield id,feature
  end
end

#each_id_masterObject



73
74
75
76
77
# File 'lib/gene_assembler/gff_dataset.rb', line 73

def each_id_master
  @master_features.each do |id,master|
    yield id,master
  end
end

#each_master_featureObject



61
62
63
64
65
# File 'lib/gene_assembler/gff_dataset.rb', line 61

def each_master_feature
  @master_features.each_value do |master_feature|
    yield master_feature
  end
end

#feature(hash_key) ⇒ Object



85
86
87
# File 'lib/gene_assembler/gff_dataset.rb', line 85

def feature(hash_key)
	return @index[hash_key]
end

#get(source = FALSE, type = FALSE) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/gene_assembler/gff_dataset.rb', line 111

def get(source=FALSE, type=FALSE)
  features=[]
  @index.each_value do |feature|
    s=TRUE
    if source
      s=feature.is_source?(source)
    end
    t=TRUE
    if type 
      t=feature.is_type?(type)
    end
         
    if s&t==TRUE
      features << feature
    end
  end
  return features
end

#has_source?(source) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
# File 'lib/gene_assembler/gff_dataset.rb', line 100

def has_source?(source)
  has_source=FALSE
  @index.each_value do |feature|
    if feature.source==source
      has_source=TRUE
      break
    end
  end
  return has_source
end

#has_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
97
98
# File 'lib/gene_assembler/gff_dataset.rb', line 89

def has_type?(type)
  has_type=FALSE
  @index.each_value do |feature|
    if feature.type==type
      has_type=TRUE
      break
    end
  end
  return has_type
end

#inspectsObject



79
80
81
82
83
# File 'lib/gene_assembler/gff_dataset.rb', line 79

def inspects
	@master_features.each do |item|
		item[1].inspects
	end
end

#treeObject



130
131
132
133
134
135
# File 'lib/gene_assembler/gff_dataset.rb', line 130

def tree
	@master_features.each_value do |master|
    	master.tree
    	puts "\n",'--------------------------------'
   	end
end