Class: FastaUtility
Instance Method Summary collapse
- #clean(filename) ⇒ Object
- #composition(filename) ⇒ Object
- #filecheck(filename) ⇒ Object
- #filter(filename) ⇒ Object
- #lengths(filename) ⇒ Object
- #sort(filename) ⇒ Object
Instance Method Details
#clean(filename) ⇒ Object
82 83 84 85 86 87 |
# File 'bin/fasta_util', line 82 def clean(filename) invoke :filecheck Bio::FlatFile.open(filename).each do |entry| puts entry.to_biosequence.output(:fasta, :header => entry.definition, :width => .wrap_width) end end |
#composition(filename) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'bin/fasta_util', line 99 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(:+).uniq.sort puts "definition\t#{all_chars.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 |
#filecheck(filename) ⇒ Object
39 40 41 |
# File 'bin/fasta_util', line 39 def filecheck(filename) say "The file '#{filename}' doesn't seem to exist!", :red unless File.exists?(filename) end |
#filter(filename) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'bin/fasta_util', line 64 def filter(filename) invoke :filecheck invoke :filecheck, [.definitions_file] requested_definitions = File.open(.definitions_file).map{|definition| definition.strip} unless .definitions_file == '' entry_ids = File.open(.entry_id_file).map{|id| id.strip} unless .entry_id_file == '' Bio::FlatFile.open(filename).each do |entry| passed = true passed &&= (entry.length >= .length_cutoff) passed &&= (entry.definition.match(Regexp.new(.defline_grep))) passed &&= (requested_definitions.include? entry.definition) unless .definitions_file == '' passed &&= (entry_ids.include? entry.entry_id) unless .entry_id_file == '' passed = !passed if .inverse_match puts entry if passed end end |
#lengths(filename) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'bin/fasta_util', line 45 def lengths(filename) invoke :filecheck lengths = Bio::FlatFile.open(filename).map{|entry| (entry.seq[-1,1] == "*") ? entry.length - 1 : entry.length} say "All entries", :green puts format(stats(lengths)) if .cutoff > 0 say "Entries with length >= #{.cutoff}", :green puts format(stats(lengths.find_all{|l| l >= .cutoff})) end end |
#sort(filename) ⇒ Object
91 92 93 94 95 96 |
# File 'bin/fasta_util', line 91 def sort(filename) invoke :filecheck Bio::FlatFile.open(filename).to_a.sort{|a,b| b.length <=> a.length}.each do |entry| puts entry end end |