Sha256: 5eb6031705707632ce0e7a9524a244ca7c6212354e7c2de52506409df90b65f3

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby

require 'scbi_plot'
#############################################
### FUNCTIONS
#############################################
def take_taxonomy(file)
	taxonomy = {}
	File.open(file).each_with_index do |line, i|
		line.chomp!
		field = line.split("\t").last
		organism = field.split(";",2).last
		organism.gsub!(/\(\D+\)/,'')
		if organism.split(' ').length == 1
			next
		end
		organism.gsub!('.','')
		organism.gsub!(/^ /,'')
		organism.gsub!('  ','')
		organism ='"'+organism+'"'
		if taxonomy[organism].nil?
			taxonomy[organism] = 1
		else
			taxonomy[organism] += 1
		end	
	end
	return taxonomy
end

def plot(taxonomy)
	p=ScbiPlot::Histogram.new('fln_taxonomy_plot.png','Group organism representation')
	p.add_x(taxonomy.keys)
	p.add_y(taxonomy.values)
	p.do_graph
end

#############################################

require 'optparse'
options = {}

optparse = OptionParser.new do |opts|
   options[:path] = File.join('fln_results','pt_seqs')
  opts.on( '-p', '--path PATH', 'Path to FLN execution' ) do |path|
          options[:path] = File.join(path,'fln_results','pt_seqs')
  end

  # Set a banner, displayed at the top of the help screen.
  opts.banner = "Usage: plot_taxonomy.rb -p PATH  \n\n"

  # This displays the help screen
  opts.on( '-h', '--help', 'Display this screen' ) do
    puts opts
    exit
  end

end # End opts

# parse options and remove from ARGV
optparse.parse!

taxonomy = nil
if File.exists?(options[:path])
	taxonomy = take_taxonomy(options[:path])
else
	puts 'Path isn\'t valid'
	Process.exit
end

plot(taxonomy)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
full_lengther_next-0.6.2 bin/plot_taxonomy.rb
full_lengther_next-0.6.1 bin/plot_taxonomy.rb
full_lengther_next-0.6.0 bin/plot_taxonomy.rb
full_lengther_next-0.5.7 bin/plot_taxonomy.rb
full_lengther_next-0.5.6 bin/plot_taxonomy.rb