Module: ParseFasta::CoreExt::String

Defined in:
lib/parse_fasta/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#remove_gaps(gap_char = "-") ⇒ String

Removes all gap chars from the string.

Examples:

Remove all ‘-’ from string

# First inclued the methods
String.include ParseFasta::CoreExt::String

# The default gap char is '-'
"--A-C-t-g".remove_gaps #=> "ACtg"

Change the gap character to ‘n’

# First inclued the methods
String.include ParseFasta::CoreExt::String

"-N-nACTG".remove_gaps "N" #=> "--nACTG"

Passing multiple gap chars

# First inclued the methods
String.include ParseFasta::CoreExt::String

".A----C_t~~~~g^G3".remove_gaps '^._-~3' #=> "ACtgG"

Parameters:

  • gap_char (String) (defaults to: "-")

    the character(s) to treat as a gap

Returns:

  • (String)

    a string with all instances of gap_char_removed



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/parse_fasta/core_ext/string.rb', line 30

def remove_gaps gap_char="-"

  if gap_char.length > 1
    if gap_char.include? "^"
      gap_char.sub! '^', '\\^'
    end

    if gap_char.include? "-"
      gap_char.sub! '-', '\\-'
    end
  end

  self.tr gap_char, ""
end