Module: SBCF::LegacyMethods

Defined in:
lib/sanger_barcode_format/legacy_methods.rb

Overview

These methods are all added to maintain compatibility with the Existing sequencescape Barcode API. They will be deprecated over time.

Instance Method Summary collapse

Instance Method Details

#barcode_to_human(code) ⇒ Object


55
56
57
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 55

def barcode_to_human(code)
  SBCF::SangerBarcode.from_machine(code).human_barcode
end

#barcode_to_human!(code, prefix = nil) ⇒ Object

Returns the Human barcode or raises an InvalidBarcode exception if there is a problem. The barcode is considered invalid if it does not translate to a Human barcode or, when the optional prefix is specified, its human equivalent does not match.


68
69
70
71
72
73
74
75
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 68

def barcode_to_human!(code, prefix = nil)
  (barcode = SBCF::SangerBarcode.from_machine(code)) ||
    raise(InvalidBarcode, "Barcode #{code} appears to be invalid")
  unless prefix.nil? || (barcode.prefix.human == prefix)
    raise InvalidBarcode, "Barcode #{code} (#{barcode.human_barcode}) does not match prefix #{prefix}"
  end
  barcode.human_barcode
end

#calculate_barcode(human_prefix, number) ⇒ Object


77
78
79
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 77

def calculate_barcode(human_prefix, number)
  SangerBarcode.new(prefix: human_prefix, number: number).machine_barcode
end

#calculate_checksum(human_prefix, number) ⇒ Object


81
82
83
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 81

def calculate_checksum(human_prefix, number)
  SangerBarcode.new(prefix: human_prefix, number: number).checksum.human
end

#check_EAN(code) ⇒ Object

We disable the SnakeCase check here as this method is intended to support legacy code.


61
62
63
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 61

def check_EAN(code) # rubocop:disable Style/MethodName
  SBCF::SangerBarcode.from_machine(code).check_ean
end

#human_to_machine_barcode(human_barcode) ⇒ Object


47
48
49
50
51
52
53
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 47

def human_to_machine_barcode(human_barcode)
  bc = SBCF::SangerBarcode.from_human(human_barcode)
  unless bc.valid?
    raise InvalidBarcode, 'The human readable barcode was invalid, perhaps it was mistyped?'
  end
  bc.machine_barcode
end

#number_to_human(machine_barcode) ⇒ String

Deprecated.

Use SBCF::SangerBarcode.from_machine(machine_barcode).number instead

Extracts a barcode number form a machine readable barcoder


28
29
30
31
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 28

def number_to_human(machine_barcode)
  number = SBCF::SangerBarcode.from_machine(machine_barcode).number
  number && number.to_s
end

#prefix_from_barcode(machine_barcode) ⇒ Sting

Deprecated.

Use SBCF::SangerBarcode.from_machine(machine_barcode).prefix.human instead

Returns the human readable prefix from a machine barcode


37
38
39
40
41
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 37

def prefix_from_barcode(machine_barcode)
  barcode = SBCF::SangerBarcode.from_machine(machine_barcode)
  return nil unless barcode.valid?
  barcode.prefix.human
end

#prefix_to_human(prefix) ⇒ Object


43
44
45
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 43

def prefix_to_human(prefix)
  Prefix.from_machine(prefix).human
end

#split_barcode(machine_barcode) ⇒ Array

Deprecated.

You are encouraged to use the prefix, number and checksum methods instead

Returns an array of [machine_prefix,number,machine_checksum] You are encouraged to use the prefix, number and checksum methods instead


10
11
12
13
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 10

def split_barcode(machine_barcode)
  bc = SBCF::SangerBarcode.from_machine(machine_barcode)
  [bc.prefix.machine_s, bc.number, bc.checksum.machine]
end

#split_human_barcode(code) ⇒ Array

Deprecated.

You are encouraged to create and use a SangerBarcode instead

Returns an array of [human_prefix,number,human_checksum]


19
20
21
22
# File 'lib/sanger_barcode_format/legacy_methods.rb', line 19

def split_human_barcode(code)
  bc = SBCF::SangerBarcode.from_human(code)
  [bc.prefix.human, bc.number.to_s, bc.checksum.human]
end