Class: BioChEMBL::ChEMBLID

Inherits:
String
  • Object
show all
Defined in:
lib/bio-chembl/chemblid.rb

Overview

ChEMBL ID

CHEMBL1

cid = BioChEMBL::ChEMBLID.new(“CHEMBL1”) cid.is_compound? #=> true cid.resolve #=> aBioChEMBL::Compound

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ ChEMBLID

Returns a new instance of ChEMBLID.



30
31
32
33
34
# File 'lib/bio-chembl/chemblid.rb', line 30

def initialize(str)
  @data_type = nil
  self.validate_chemblId(str)
  super(str)
end

Instance Attribute Details

#data_typeObject

Returns the value of attribute data_type.



22
23
24
# File 'lib/bio-chembl/chemblid.rb', line 22

def data_type
  @data_type
end

Class Method Details

.validate_chemblId(str) ⇒ Object



24
25
26
27
28
# File 'lib/bio-chembl/chemblid.rb', line 24

def self.validate_chemblId(str)
  unless str =~ /^CHEMBL\d+$/
    raise Exception, "Invalid ChEMBL ID."
  end
end

Instance Method Details

#is_assay?Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/bio-chembl/chemblid.rb', line 87

def is_assay?
  if @data_type == Assay
    return true
  else
    if Assay.find(self.to_s)
      @data_type = Assay
      return true
    else
      return false  
    end 
  end   
end

#is_compound?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bio-chembl/chemblid.rb', line 61

def is_compound?
  if @data_type == Compound
    return true
  else
    if Compound.find(self.to_s)
      @data_type = Compound
      return true
    else
      return false  
    end 
  end
end

#is_target?Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bio-chembl/chemblid.rb', line 74

def is_target?
  if @data_type == Assay
    return true
  else
    if Assay.find(self.to_s)
      @data_type = Assay
      return true
    else
      return false  
    end 
  end    
end

#resolveObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bio-chembl/chemblid.rb', line 37

def resolve
  case @data_type
  when Compound
    Compound.find(self.to_s)
  when Target
    Target.find(self.to_s)
  when Assay
    Assay.find(self.to_s)
  else
    begin
      Compound.find(self.to_s)
    rescue
    end 
    begin
      Target.find(self.to_s)
    rescue
    end 
    begin
      Assay.find(self.to_s)
    rescue
    end 
  end
end