class ProteinSet
Attributes
aln[R]
ids[R]
rocker[R]
Public Class Methods
new(rocker, ids=nil, file=nil, aln_file=nil)
click to toggle source
# 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
Public Instance Methods
download(file)
click to toggle source
# 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?()
click to toggle source
# File lib/rocker/protein-set.rb, line 99 def empty?() self.ids.empty? end
genome_by_prot_id(prot_id)
click to toggle source
# File lib/rocker/protein-set.rb, line 66 def genome_by_prot_id(prot_id) @genomes[prot_id] end
genomes()
click to toggle source
# File lib/rocker/protein-set.rb, line 62 def genomes return [] if @genomes.empty? @genomes.values.reduce(:+).uniq end
get_from_aln(file, aln)
click to toggle source
# 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!()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/rocker/protein-set.rb, line 100 def include?(id) self.ids.include?(id) end
link_genome(prot_id, genome_id)
click to toggle source
# 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
link_tranid(prot_id, transl_id)
click to toggle source
# 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)
click to toggle source
Removes genomes linked to prot_ids
(an Array) and returns an Array of removed genomes.
# 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
size()
click to toggle source
# File lib/rocker/protein-set.rb, line 98 def size() self.ids.size end
tranids()
click to toggle source
# File lib/rocker/protein-set.rb, line 75 def tranids return [] if @tranids.empty? @tranids.values.reduce(:+).uniq end
tranids_dump()
click to toggle source
# File lib/rocker/protein-set.rb, line 79 def tranids_dump @tranids.map{|k,v| "{#{k}: #{v}}"}.join(", ") end