Permalink
Browse files

Merge remote-tracking branch 'github/master'

  • Loading branch information...
2 parents 13cf342 + 464316b commit 1914ab082460d759b6c8597b37218afb0919ab6d Ben J Woodcroft committed Apr 30, 2012
Showing with 60 additions and 7 deletions.
  1. +1 −1 blast_by_splits.rb
  2. +6 −6 kmer_counter.rb
  3. +53 −0 translate_funky.rb
View
@@ -66,7 +66,7 @@
blast_threads = (1..options[:threads]).collect do |i|
Thread.new do
num_sequences_argument = "-max_target_seqs #{options[:max_target_seqs]}"
- if options[:outfmt].to_s == 1.to_s
+ if %w(0 1 2 3 4 5).include?(options[:outfmt].to_s)
num_sequences_argument = "-num_descriptions #{options[:max_target_seqs]} -num_alignments #{options[:max_target_seqs]}"
end
cmd = "blastp -query '#{input_temps[i-1].path}' -db '#{options[:db]}' #{num_sequences_argument} -outfmt #{options[:outfmt]} -out #{output_temps[i-1].path}"
View
@@ -59,7 +59,7 @@ def self.empty_kmer_hash(k=4)
OptionParser.new do |opts|
opts.banner = USAGE
- opts.on("-w", "--window-size SIZE", "Length of the window to be used") do |v|
+ opts.on("-w", "--window-size SIZE", "Length of the window to be used [default #{options[:window_size]}]") do |v|
window = v.to_i
unless window > 0
raise Exception, "Unexpected window size specified: #{v} - it must be greater than 0 residues long!"
@@ -68,35 +68,35 @@ def self.empty_kmer_hash(k=4)
options[:window_offset] = window
end
- opts.on("-W", "--window-offset SIZE", "Length of the offset between windows") do |v|
+ opts.on("-W", "--window-offset SIZE", "Length of the offset between windows [default #{options[:window_offset]}]") do |v|
offset = v.to_i
unless offset > 0
offset = options[:window_isze]
end
options[:window_offset] = offset
end
- opts.on("-m", "--minimum-window-size SIZE", "Length of the minimum window to be used") do |v|
+ opts.on("-m", "--minimum-window-size SIZE", "Length of the minimum window to be used [default #{options[:minimum_window_size]}]") do |v|
window = v.to_i
unless window > 0
raise Exception, "Unexpected minimum window size specified: #{v} - it must be greater than 0 residues long!"
end
options[:minimum_window_size] = window
end
- opts.on("-k", "--kmer-length SIZE", "Length of the kmer to be used") do |v|
+ opts.on("-k", "--kmer-length SIZE", "Length of the kmer to be used [default #{options[:kmer]}]") do |v|
window = v.to_i
unless window > 0
raise Exception, "Unexpected minimum window size specified: #{v} - it must be greater than 0 residues long!"
end
options[:kmer] = window
end
- opts.on("-n", "--contig-name", "Output the contig name, on top of the default contig chunk name [default: false]") do |v|
+ opts.on("-n", "--contig-name", "Output the contig name, on top of the default contig chunk name [default: #{options[:contig_name]}]") do |v|
options[:contig_name] = true
end
- opts.on("-l", "--window-length", "print the length of the window in the output") do |v|
+ opts.on("-l", "--window-length", "print the length of the window in the output [default #{options[:sequence_length]}]") do |v|
options[:sequence_length] = true
end
end.parse!
View
@@ -0,0 +1,53 @@
+#!/usr/bin/env ruby
+
+# Take in a fasta file of nucleotide sequences corresponding to a collection of proteins, and then translate them. However, the translation table is modifyable on the command line
+
+require 'bio'
+require 'optparse'
+require 'bio-logger'
+
+translation_table = Bio::CodonTable.copy(1)
+table_modifications = {}
+
+options = {
+ :logger => 'stderr',
+ :trace => 'info',
+}
+
+o = OptionParser.new do |opts|
+ opts.banner = "translate_funky.rb [-c <codon_modifications>] <transcript_fasta_file>"
+
+ opts.on('-c', "--codon-modifications CODON_MODS", "Modify the codon table e.g. 'ATG:L' to change ATG from M to L") do |v|
+ splits = v.split(',')
+ splits.each do |split|
+ if matches = split.match(/^([ATGC]{3}):([A-Za-z])$/)
+ table_modifications[matches[1].downcase] = matches[2]
+ else
+ raise Exception, "Unexpected table codon modification format '#{split}', expected something like 'ATG:L'"
+ end
+ end
+ end
+
+ opts.on(nil, "--debug", "Run very verbosely") do |v|
+ options[:trace] = 'funky-translate:debug'
+ end
+end.parse!
+
+
+Bio::Log::CLI.trace(options[:trace])
+Bio::Log::CLI.logger(options[:logger]) #defaults to STDERR not STDOUT
+log = Bio::Log::LoggerPlus.new('funky-translate')
+Bio::Log::CLI.configure('funky-translate')
+
+
+table_modifications.each do |codon, aa|
+ translation_table[codon] = aa
+end
+
+
+log.debug "Using CodonTable #{translation_table.inspect}"
+
+Bio::FlatFile.foreach(ARGF) do |entry|
+ puts ">#{entry.definition}"
+ puts Bio::Sequence::NA.new(entry.seq).translate(1,translation_table)
+end

0 comments on commit 1914ab0

Please sign in to comment.