Open3.popen3("muscle", "-quiet") do |stdin, stdout, stderr|
entries.each do |entry|
- raise AlignError, "Duplicate sequence name: #{entry.seq_name}" if index.has_key? entry.seq_name
+ raise AlignError, "Duplicate sequence name: #{entry.seq_name}" if index[entry.seq_name]
index[entry.seq_name] = entry.dup
# NArrays.
def consensus_calc
if @has_qual
- if @options.has_key? :quality_min
+ if @options[:quality_min]
mask = mask_quality_min
@na_seq *= mask
@na_qual *= mask
end
- if @options.has_key? :quality_mean
+ if @options[:quality_mean]
mask = mask_quality_mean
@na_seq *= mask
end
end
- if @options.has_key? :sequence_min
+ if @options[:sequence_min]
mask = mask_sequence_min
@na_seq *= mask
@na_qual *= mask if @has_qual
end
- if @options.has_key? :gap_max
+ if @options[:gap_max]
mask = mask_gap_max
@na_seq *= mask
@na_qual *= mask if @has_qual
end
- if @options.has_key? :residue_min
+ if @options[:residue_min]
mask = mask_residue_min
@na_seq *= mask
def check_keys
@cast_list.each do |cast|
MANDATORY.each do |mandatory|
- raise CastError, "Missing symbol in cast: '#{mandatory.to_sym}'" unless cast.has_key? mandatory.to_sym
+ raise CastError, "Missing symbol in cast: '#{mandatory}'" unless cast.has_key? mandatory.to_sym
end
end
end
type_hash[type] = true
end
- unless type_hash.has_key? cast[:type]
+ unless type_hash[cast[:type]]
raise CastError, "Illegal cast of type: '#{cast[:type]}'"
end
end
def check_duplicates
check_hash = {}
@cast_list.each do |cast|
- raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash.has_key? cast[:long]
- raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash.has_key? cast[:short]
+ raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash[cast[:long]]
+ raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash[cast[:short]]
check_hash[cast[:long]] = true
check_hash[cast[:short]] = true
end
def options_default
@casts.each do |cast|
if cast[:default]
- unless @options.has_key? cast[:long]
+ unless @options[cast[:long]]
if cast[:type] == 'list'
@options[cast[:long]] = cast[:default].split ','
else
def options_glob
@casts.each do |cast|
if cast[:type] == 'files' or cast[:type] == 'files!'
- if @options.has_key? cast[:long]
+ if @options[cast[:long]]
files = []
@options[cast[:long]].each do |path|
# Check if a mandatory option is set and raise if it isn't.
def options_check_mandatory(cast)
if cast[:mandatory]
- raise ArgumentError, "Mandatory argument: --#{cast[:long]}" unless @options.has_key? cast[:long]
+ raise ArgumentError, "Mandatory argument: --#{cast[:long]}" unless @options[cast[:long]]
end
end
# Check int type option and raise if not an integer.
def options_check_int(cast)
- if cast[:type] == 'int' and @options.has_key? cast[:long]
+ if cast[:type] == 'int' and @options[cast[:long]]
unless @options[cast[:long]].is_a? Integer
raise ArgumentError, "Argument to --#{cast[:long]} must be an integer, not '#{@options[cast[:long]]}'"
end
# Check uint type option and raise if not an unsinged integer.
def options_check_uint(cast)
- if cast[:type] == 'uint' and @options.has_key? cast[:long]
+ if cast[:type] == 'uint' and @options[cast[:long]]
unless @options[cast[:long]].is_a? Integer and @options[cast[:long]] >= 0
raise ArgumentError, "Argument to --#{cast[:long]} must be an unsigned integer, not '#{@options[cast[:long]]}'"
end
# Check file! type argument and raise if file don't exists.
def options_check_file(cast)
- if cast[:type] == 'file!' and @options.has_key? cast[:long]
+ if cast[:type] == 'file!' and @options[cast[:long]]
raise ArgumentError, "No such file: '#{@options[cast[:long]]}'" unless File.file? @options[cast[:long]]
end
end
# Check files! type argument and raise if files don't exists.
def options_check_files(cast)
- if cast[:type] == 'files!' and @options.has_key? cast[:long]
+ if cast[:type] == 'files!' and @options[cast[:long]]
@options[cast[:long]].each do |path|
next if path == "-"
raise ArgumentError, "File not readable: '#{path}'" unless File.readable? path
# Check dir! type argument and raise if directory don't exist.
def options_check_dir(cast)
- if cast[:type] == 'dir!' and @options.has_key? cast[:long]
+ if cast[:type] == 'dir!' and @options[cast[:long]]
raise ArgumentError, "No such directory: '#{@options[cast[:long]]}'" unless File.directory? @options[cast[:long]]
end
end
# Check options and raise unless allowed.
def options_check_allowed(cast)
- if cast[:allowed] and @options.has_key? cast[:long]
+ if cast[:allowed] and @options[cast[:long]]
allowed_hash = {}
cast[:allowed].split(',').each { |a| allowed_hash[a.to_s] = 1 }
- raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash.has_key? @options[cast[:long]].to_s
+ raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash[@options[cast[:long]].to_s]
end
end
# Check disallowed argument values and raise if disallowed.
def options_check_disallowed(cast)
- if cast[:disallowed] and @options.has_key? cast[:long]
+ if cast[:disallowed] and @options[cast[:long]]
cast[:disallowed].split(',').each do |val|
raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} is disallowed" if val.to_s == @options[cast[:long]].to_s
end
bp[:SCORES] = sam[:SEQ].convert_phred2illumina!.qual
end
- if sam.has_key? :NM and sam[:NM].to_i > 0
+ if sam[:NM] and sam[:NM].to_i > 0
bp[:NM] = sam[:NM]
bp[:MD] = sam[:MD]
bp[:ALIGN] = self.align_descriptors(sam)
@header[:SQ][:SN] = Hash.new unless @header[:SQ][:SN].is_a? Hash
- if @header[:SQ][:SN].has_key? seq_name
+ if @header[:SQ][:SN][seq_name]
raise SamError, "Non-unique sequence name: #{seq_name}"
else
@header[:SQ][:SN][seq_name] = hash
end
end
- if hash.has_key? :FO
+ if hash[:FO]
unless hash[:FO] =~ /^\*|[ACMGRSVTWYHKDBN]+$/
raise SamError, "Bad flow order: #{hash[:FO]}"
end
end
- if hash.has_key? :PL
+ if hash[:PL]
unless hash[:PL] =~ /^(CAPILLARY|LS454|ILLUMINA|SOLID|HELICOS|IONTORRENT|PACBIO)$/
raise SamError, "Bad platform: #{hash[:PL]}"
end
@header[:RG][:ID] = Hash.new unless @header[:RG][:ID].is_a? Hash
- if @header[:RG][:ID].has_key? id
+ if @header[:RG][:ID][id]
raise SamError, "Non-unique read group identifier: #{id}"
else
@header[:RG][:ID][id] = hash
@header[:PG][:ID] = Hash.new unless @header[:PG][:ID].is_a? Hash
- if @header[:PG][:ID].has_key? id
+ if @header[:PG][:ID][id]
raise SamError, "Non-unique program record identifier: #{id}"
else
@header[:PG][:ID][id] = hash
fields[11 .. -1].each do |field|
tag, type, val = field.split(':')
- raise SamError, "Non-unique optional tag: #{tag}" if entry.has_key? tag.to_sym
+ raise SamError, "Non-unique optional tag: #{tag}" if entry[tag.to_sym]
# A [!-~] Printable character
raise SamError, "Bad rname: #{rname}" unless rname =~ /^(\*|[!-()+-<>-~][!-~]*)$/
unless @header.empty? or rname == '*'
- unless @header[:SQ][:SN].has_key? rname.to_sym
+ unless @header[:SQ][:SN][rname.to_sym]
raise SamError, "rname not found in header hash: #{rname}"
end
end
raise SamError, "Bad rnext: #{rnext}" unless rnext =~ /^(\*|=|[!-()+-<>-~][!-~]*)$/
unless @header.empty? or rnext == '*' or rnext == '='
- unless @header[:SQ][:SN].has_key? rnext.to_sym
+ unless @header[:SQ][:SN][rnext.to_sym]
raise SamError, "rnext not found in header hash: #{rnext}"
end
end