def program_choose(type1, type2)
program = ""
- if type1 == 'protein'
- if type2 == 'protein'
+ if type1 == :protein
+ if type2 == :protein
program = 'blastp'
else
program = 'tblastn'
end
else
- if type2 == 'protein'
+ if type2 == :protein
program = 'blastx'
else
program = 'blastn'
options = Biopieces.options_parse(ARGV, casts)
if options[:forward_rc]
- options[:forward] = Seq.new("test", options[:forward_rc], 'dna').reverse.complement.seq
+ options[:forward] = Seq.new("test", options[:forward_rc], :dna).reverse.complement.seq
end
if options[:reverse_rc]
- options[:reverse] = Seq.new("test", options[:reverse_rc], 'dna').reverse.complement.seq
+ options[:reverse] = Seq.new("test", options[:reverse_rc], :dna).reverse.complement.seq
end
raise ArgumentError, "no adaptor specified" unless options[:forward] or options[:reverse]
args = []
args << "scan_for_matches"
args << "-c" if comp
- args << "-p" if type == 'protein'
+ args << "-p" if type == :protein
args << "-n #{max_mis}" if max_mis
args << "-m #{max_hit}" if max_hit
args << @pat_file
seq = Seq.new
seq.seq = primer
- seq.type = 'dna'
+ seq.type = :dna
seq.reverse!.complement!
descriptor ? seq.seq + descriptor : seq.seq
casts << {:long=>'forward_rc', :short=>'F', :type=>'string', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'reverse', :short=>'r', :type=>'string', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'reverse_rc', :short=>'R', :type=>'string', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
-casts << {:long=>'max_dist', :short=>'m', :type=>'uint', :mandatory=>true, :default=>5000, :allowed=>nil, :disallowed=>"0"}
+casts << {:long=>'max_dist', :short=>'m', :type=>'uint', :mandatory=>true, :default=>5000, :allowed=>nil, :disallowed=>"0"}
options = Biopieces.options_parse(ARGV, casts)
tmpdir = Biopieces.mktmpdir
infile = File.join(tmpdir, "in.fna")
if options[:forward_rc]
- options[:forward] = Seq.new("test", options[:forward_rc], 'dna').reverse.complement.seq
+ options[:forward] = Seq.new("test", options[:forward_rc], :dna).reverse.complement.seq
end
if options[:reverse_rc]
- options[:reverse] = Seq.new("test", options[:reverse_rc], 'dna').reverse.complement.seq
+ options[:reverse] = Seq.new("test", options[:reverse_rc], :dna).reverse.complement.seq
end
raise ArgumentError, "no adaptor specified" unless options[:forward] or options[:reverse]
input.each_record do |record|
if record[:SEQ] and record[:SEQ].length >= options[:size]
entry = Seq.new(record[:SEQ_NAME], record[:SEQ], record[:SCORES])
- entry.type = 'dna'
+ entry.type = :dna
entry.shred(options[:size], options[:coverage]) do |subentry|
output.puts subentry.to_bp
new_seq = Seq.new
new_seq.seq = consensus_seq
new_seq.qual = consensus_qual if @has_qual
- new_seq.type = "dna"
+ new_seq.type = :dna
new_seq
end
seq = @entry[j + 1 .. i].join.delete(" 0123456789")
- Seq.new(nil, seq, "dna") if seq
+ Seq.new(nil, seq, :dna) if seq
end
# Method to get the base keys from EMBL entry and return these
seq = @entry[j + 1 .. i].join.delete(" 0123456789")
- Seq.new(nil, seq, "dna") if seq
+ Seq.new(nil, seq, :dna) if seq
end
# Method to get the base keys from Genbank entry and return these
def initialize(locator, seq)
@locator = locator
@seq = seq
- @subseq = Seq.new(nil, "", "dna")
+ @subseq = Seq.new(nil, "", :dna)
parse_locator(locator)
end
int_beg = $1.to_i - 1
int_end = $2.to_i - 1
- newseq = Seq.new(nil, @seq.seq[int_beg..int_end], "dna")
+ newseq = Seq.new(nil, @seq.seq[int_beg..int_end], :dna)
unless newseq.seq.nil?
newseq.reverse!.complement! if comp
when /^(\d+)$/
pos = $1.to_i - 1
- newseq = Seq.new(nil, @seq.seq[pos], "dna")
+ newseq = Seq.new(nil, @seq.seq[pos], :dna)
unless newseq.seq.nil?
newseq.reverse!.complement! if comp
def self.new_bp(record)
seq_name = record[:SEQ_NAME]
seq = record[:SEQ]
- type = record[:SEQ_TYPE]
+ type = record[:SEQ_TYPE].to_sym if record[:SEQ_TYPE]
qual = record[:SCORES]
self.new(seq_name, seq, type, qual)
raise SeqError, "Cannot generate negative oligo length: #{length}" if length <= 0
case type.downcase
- when /dna/ then alph = DNA
- when /rna/ then alph = RNA
- when /protein/ then alph = PROTEIN
+ when :dna then alph = DNA
+ when :rna then alph = RNA
+ when :protein then alph = PROTEIN
else
raise SeqError, "Unknown sequence type: #{type}"
end
raise SeqError, "Guess failed: sequence is nil" if self.seq.nil?
case self.seq[0 ... 100].downcase
- when /[flpqie]/ then return "protein"
- when /[u]/ then return "rna"
- else return "dna"
+ when /[flpqie]/ then return :protein
+ when /[u]/ then return :rna
+ else return :dna
end
end
# Method that returns true is a given sequence type is DNA.
def is_dna?
- self.type == 'dna'
+ self.type == :dna
end
# Method that returns true is a given sequence type is RNA.
def is_rna?
- self.type == 'rna'
+ self.type == :rna
end
# Method that returns true is a given sequence type is protein.
def is_protein?
- self.type == 'protein'
+ self.type == :protein
end
# Method to transcribe DNA to RNA.
def to_rna
raise SeqError, "Cannot transcribe 0 length sequence" if self.length == 0
raise SeqError, "Cannot transcribe sequence type: #{self.type}" unless self.is_dna?
- self.type = 'rna'
+ self.type = :rna
self.seq.tr!('Tt','Uu')
end
def to_dna
raise SeqError, "Cannot reverse-transcribe 0 length sequence" if self.length == 0
raise SeqError, "Cannot reverse-transcribe sequence type: #{self.type}" unless self.is_rna?
-
- self.type = 'dna'
+ self.type = :dna
self.seq.tr!('Uu','Tt')
end
# Method to translate a DNA sequence to protein.
def translate!(trans_tab = 11)
- raise SeqError, "Sequence type must be 'dna' - not #{self.type}" unless self.type == 'dna'
+ raise SeqError, "Sequence type must be 'dna' - not #{self.type}" unless self.type == :dna
raise SeqError, "Sequence length must be a multiplum of 3 - was: #{self.length}" unless (self.length % 3) == 0
case trans_tab
self.seq = protein
self.qual = nil
- self.type = "protein"
+ self.type = :protein
self
end
def generate(length, type)
raise SeqError, "Cannot generate sequence length < 1: #{length}" if length <= 0
- case type.downcase
- when "dna"
- alph = DNA
- when "rna"
- alph = RNA
- when "protein"
- alph = PROTEIN
+ case type
+ when :dna then alph = DNA
+ when :rna then alph = RNA
+ when :protein then alph = PROTEIN
else
raise SeqError, "Unknown sequence type: #{type}"
end
seq_new = Array.new(length) { alph[rand(alph.size)] }.join("")
self.seq = seq_new
- self.type = type.downcase
+ self.type = type
seq_new
end
def pattern_disambiguate
case self.type
- when 'protein'
+ when :protein
@pattern.gsub!('J', '[IFVLWMAGCY]')
@pattern.gsub!('O', '[TSHEDQNKR]')
@pattern.gsub!('B', '[DN]')
@pattern.gsub!('Z', '[EQ]')
@pattern.gsub!('X', '.')
- when 'dna'
+ when :dna
@pattern.gsub!('R', '[AG]')
@pattern.gsub!('Y', '[CT]')
@pattern.gsub!('S', '[GC]')
@pattern.gsub!('D', '[AGT]')
@pattern.gsub!('B', '[CGT]')
@pattern.gsub!('N', '.')
- when 'rna'
+ when :rna
else
raise SeqError "unknown sequence type: #{self.type}"
end
class TestLocator < Test::Unit::TestCase
def setup
- @seq = Seq.new(nil, "tcatgatcaagatctaacagcagaagtacacttctattta", "dna")
+ @seq = Seq.new(nil, "tcatgatcaagatctaacagcagaagtacacttctattta", :dna)
end
test "#new with single position returns correctly" do
end
test "Seq.new_bp returns correctly" do
- record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => "dna", :SCORES => "hhhh"}
+ record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => :dna, :SCORES => "hhhh"}
seq = Seq.new_bp(record)
assert_equal("test", seq.seq_name)
assert_equal("ATCG", seq.seq)
- assert_equal("dna", seq.type)
+ assert_equal(:dna, seq.type)
assert_equal("hhhh", seq.qual)
end
end
test "#is_dna? with dna sequence type returns true" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert(@entry.is_dna? == true)
end
end
test "#is_rna? with rna sequence type returns true" do
- @entry.type = 'rna'
+ @entry.type = :rna
assert(@entry.is_rna? == true)
end
end
test "#is_protein? with protein sequence type returns true" do
- @entry.type = 'protein'
+ @entry.type = :protein
assert_equal(true, @entry.is_protein?)
end
test "#type_guess with protein returns protein" do
@entry.seq = 'atcatcrFgatcg'
- assert_equal('protein', @entry.type_guess)
+ assert_equal(:protein, @entry.type_guess)
end
test "#type_guess with rna returns rna" do
@entry.seq = 'atcatcrUgatcg'
- assert_equal('rna', @entry.type_guess)
+ assert_equal(:rna, @entry.type_guess)
end
test "#type_guess with dna returns dna" do
@entry.seq = 'atcatcgatcg'
- assert_equal('dna', @entry.type_guess)
+ assert_equal(:dna, @entry.type_guess)
end
test "#type_guess! without sequence raises" do
test "#type_guess! with protein returns protein" do
@entry.seq = 'atcatcrFgatcg'
@entry.type_guess!
- assert_equal('protein', @entry.type)
+ assert_equal(:protein, @entry.type)
end
test "#type_guess! with rna returns rna" do
@entry.seq = 'atcatcrUgatcg'
@entry.type_guess!
- assert_equal('rna', @entry.type)
+ assert_equal(:rna, @entry.type)
end
test "#type_guess! with dna returns dna" do
@entry.seq = 'atcatcgatcg'
@entry.type_guess!
- assert_equal('dna', @entry.type)
+ assert_equal(:dna, @entry.type)
end
test "#length returns corretly" do
end
test "#to_rna with no sequence raises" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.to_rna }
end
test "#to_rna with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_raise(SeqError) { @entry.to_rna }
end
test "#to_rna transcribes correctly" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_equal("AUCGaucg", @entry.to_rna)
end
test "#to_rna changes entry type to rna" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
@entry.to_rna
- assert_equal("rna", @entry.type)
+ assert_equal(:rna, @entry.type)
end
test "#to_dna with no sequence raises" do
- @entry.type = 'rna'
+ @entry.type = :rna
assert_raise(SeqError) { @entry.to_dna }
end
test "#to_dna with bad type raises" do
@entry.seq = 'AUCG'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.to_dna }
end
test "#to_dna transcribes correctly" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_equal("ATCGatcg", @entry.to_dna)
end
test "#to_dna changes entry type to dna" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
@entry.to_dna
- assert_equal("dna", @entry.type)
+ assert_equal(:dna, @entry.type)
end
test "#to_bp returns correct record" do
end
test "#complement with no sequence raises" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.complement }
end
test "#complement with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'protein'
+ @entry.type = :protein
assert_raise(SeqError) { @entry.complement }
end
test "#complement for DNA is correct" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
comp = @entry.complement
assert_equal("TAGCtagc", comp.seq)
assert_equal("ATCGatcg", @entry.seq)
test "#complement for RNA is correct" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
comp = @entry.complement
assert_equal("UAGCuagc", comp.seq)
assert_equal("AUCGaucg", @entry.seq)
end
test "#complement! with no sequence raises" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.complement! }
end
test "#complement! with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'protein'
+ @entry.type = :protein
assert_raise(SeqError) { @entry.complement! }
end
test "#complement! for DNA is correct" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_equal("TAGCtagc", @entry.complement!.seq)
end
test "#complement! for RNA is correct" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_equal("UAGCuagc", @entry.complement!.seq)
end
end
test "#generate with length < 1 raises" do
- assert_raise(SeqError) { @entry.generate(-10, "dna") }
- assert_raise(SeqError) { @entry.generate(0, "dna") }
+ assert_raise(SeqError) { @entry.generate(-10, :dna) }
+ assert_raise(SeqError) { @entry.generate(0, :dna) }
end
test "#generate with bad type raises" do
end
test "#generate with ok type dont raise" do
- %w[dna DNA rna RNA protein Protein].each do |type|
- assert_nothing_raised { @entry.generate(10, type) }
+ %w[dna rna protein].each do |type|
+ assert_nothing_raised { @entry.generate(10, type.to_sym) }
end
end
test "#<< with different types raises" do
@entry.seq = "atcg"
- assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna") }
+ assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna) }
end
test "#<< with missing qual in one entry raises" do
@entry.seq = "atcg"
- @entry.type = "dna"
- assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna", "IIII") }
+ @entry.type = :dna
+ assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna, "IIII") }
@entry.qual = "IIII"
- assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna") }
+ assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna) }
end
test "#<< with nil qual in both entries dont raise" do
test "#<< with qual in both entries dont raise" do
@entry.seq = "atcg"
- @entry.type = "dna"
+ @entry.type = :dna
@entry.qual = "IIII"
- assert_nothing_raised { @entry << Seq.new("test", "atcg", "dna", "IIII") }
+ assert_nothing_raised { @entry << Seq.new("test", "atcg", :dna, "IIII") }
end
test "#<< without qual returns correctly" do
test "#<< with qual returns correctly" do
@entry.seq = "atcg"
- @entry.type = "dna"
+ @entry.type = :dna
@entry.qual = "HHHH"
- @entry << Seq.new("test", "ATCG", "dna", "IIII")
+ @entry << Seq.new("test", "ATCG", :dna, "IIII")
assert_equal("atcgATCG", @entry.seq)
assert_equal("HHHHIIII", @entry.qual)
end