Class: ProteinSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rocker/protein-set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rocker, ids = nil, file = nil, aln_file = nil) ⇒ ProteinSet

Returns a new instance of ProteinSet.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rocker/protein-set.rb', line 12

def initialize(rocker, ids=nil, file=nil, aln_file=nil)
   @genomes = {}
   @tranids = {}
   @aln = nil
   @rocker = rocker
   @ids = []
   @ids += ids unless ids.nil?
   @ids += File.readlines(file).map{ |l| l.chomp } unless file.nil?
   unless aln_file.nil?
	 aln = Alignment.new
	 aln.read_fasta aln_file
	 aln_ids = aln.get_ids
	 @aln = aln if (@ids - aln_ids).empty?
	 @ids += aln_ids
   end
   @ids.uniq!
end

Instance Attribute Details

#alnObject (readonly)

Returns the value of attribute aln.



11
12
13
# File 'lib/rocker/protein-set.rb', line 11

def aln
  @aln
end

#idsObject (readonly)

Returns the value of attribute ids.



11
12
13
# File 'lib/rocker/protein-set.rb', line 11

def ids
  @ids
end

#rockerObject (readonly)

Returns the value of attribute rocker.



11
12
13
# File 'lib/rocker/protein-set.rb', line 11

def rocker
  @rocker
end

Instance Method Details

#download(file) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/rocker/protein-set.rb', line 29

def download(file)
   tmp_ids = Array.new(self.ids)
   f = File.open(file, "w")
   while tmp_ids.size>0
	 f.print rocker.ebiFetch(:uniprotkb, tmp_ids.shift(200), :fasta)
   end
   f.close
end

#empty?Boolean

Returns:

  • (Boolean)


99
# File 'lib/rocker/protein-set.rb', line 99

def empty?() self.ids.empty? end

#genome_by_prot_id(prot_id) ⇒ Object



66
67
68
# File 'lib/rocker/protein-set.rb', line 66

def genome_by_prot_id(prot_id)
  @genomes[prot_id]
end

#genomesObject



62
63
64
65
# File 'lib/rocker/protein-set.rb', line 62

def genomes
   return [] if @genomes.empty?
   @genomes.values.reduce(:+).uniq
end

#get_from_aln(file, aln) ⇒ Object



37
38
39
40
41
# File 'lib/rocker/protein-set.rb', line 37

def get_from_aln(file, aln)
   f = File.open(file, "w")
   f.print aln.to_seq_s
   f.close
end

#get_genomes!Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/rocker/protein-set.rb', line 42

def get_genomes!
   self.ids.each do |id|
	 doc = self.rocker.ebiFetch(:uniprotkb, [id], :annot).split("\n")
	 doc.grep( /^DR\s+EMBL;/ ).map do |ln|
  r=ln.split("; ")
  self.link_genome(id, r[1])
  self.link_tranid(id, r[2])
	 end
   end
end

#in_coords(coords) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rocker/protein-set.rb', line 82

def in_coords(coords)
   coords.keys.map do |genome|
	 locations = coords[ genome ]
	 locations.map do |loc|
  if not loc[:prot_id].nil? 
     loc[:prot_id] if include? loc[:prot_id]
  elsif not loc[:tran_id].nil?
     @tranids.map{ |k,v| v.include?(loc[:tran_id]) ? k : nil }.compact.first
  else
     warn "Warning: Impossible to resolve protein located " +
 "in '#{genome}' at: #{loc}."
     nil
  end
	 end
   end.reduce([], :+).compact.uniq
end

#include?(id) ⇒ Boolean

Returns:

  • (Boolean)


100
# File 'lib/rocker/protein-set.rb', line 100

def include?(id) self.ids.include?(id) end


52
53
54
55
56
# File 'lib/rocker/protein-set.rb', line 52

def link_genome(prot_id, genome_id)
   @genomes[prot_id] ||= []
   @genomes[prot_id] << genome_id
   @genomes[prot_id].uniq!
end


57
58
59
60
61
# File 'lib/rocker/protein-set.rb', line 57

def link_tranid(prot_id, transl_id)
   @tranids[prot_id] ||= []
   @tranids[prot_id] << transl_id
   @tranids[prot_id].uniq!
end

#remove_genomes_by_prot_id!(prot_ids) ⇒ Object

Removes genomes linked to prot_ids (an Array) and returns an Array of removed genomes.



72
73
74
# File 'lib/rocker/protein-set.rb', line 72

def remove_genomes_by_prot_id!(prot_ids)
  prot_ids.map{ |i| @genomes.delete(i) }.flatten.compact
end

#sizeObject



98
# File 'lib/rocker/protein-set.rb', line 98

def size() self.ids.size end

#tranidsObject



75
76
77
78
# File 'lib/rocker/protein-set.rb', line 75

def tranids
   return [] if @tranids.empty?
   @tranids.values.reduce(:+).uniq
end

#tranids_dumpObject



79
80
81
# File 'lib/rocker/protein-set.rb', line 79

def tranids_dump
   @tranids.map{|k,v| "{#{k}: #{v}}"}.join(", ")
end