bin/fasta_util in fasta_util-0.2.3 vs bin/fasta_util in fasta_util-0.3.0
- old
+ new
@@ -1,8 +1,9 @@
#!/usr/bin/env ruby
require 'thor'
require 'bio'
+require 'set'
class FastaUtility < Thor
include Thor::Actions
Struct.new("Stats", :sum, :l50, :n50, :count, :mean, :median)
@@ -86,7 +87,23 @@
invoke :filecheck
Bio::FlatFile.open(filename).to_a.sort{|a,b| b.length <=> a.length}.each do |entry|
puts entry
end
end
+
+ desc "composition FILENAME [options]", "Outputs data on the sequence composition"
+ def composition(filename)
+ invoke :filecheck
+ composition_hash = Hash[Bio::FlatFile.open(filename).map{|entry| [entry.definition, entry.seq.composition]}]
+
+ all_chars = composition_hash.values.map{|h| h.keys}.inject(:+).to_set
+
+ puts "definition\t#{all_chars.to_a.join("\t")}"
+ composition_hash.each do |definition, composition|
+ composition.default = 0
+ print definition, "\t"
+ puts all_chars.map{|char| composition[char]}.join("\t")
+ end
+ end
end
+
FastaUtility.start