Module: Exodb

Defined in:
lib/exodb/constant.rb,
lib/exodb.rb,
lib/exodb/extra.rb,
lib/exodb/utils.rb,
lib/exodb/rositza.rb,
lib/exodb/version.rb,
lib/exodb/exception.rb,
lib/exodb/usermanage.rb,
lib/exodb/dbconnection.rb,
lib/exodb/extra/upload.rb,
lib/exodb/rositza/load.rb,
lib/exodb/datamodel/region.rb,
lib/exodb/datamodel/source.rb,
lib/exodb/utils/miriamrest.rb,
lib/exodb/utils/upload_var.rb,
lib/exodb/datamodel/generef.rb,
lib/exodb/datamodel/isoform.rb,
lib/exodb/datamodel/variant.rb,
lib/exodb/utils/ensemblrest.rb,
lib/exodb/datamodel/reference.rb,
lib/exodb/datamodel/xrefsfield.rb,
lib/exodb/extra/upload_generef.rb,
lib/exodb/datamodel/varlocfield.rb,
lib/exodb/datamodel/genelocfield.rb

Overview

raise “Please, use ruby 1.9.0 or later.” if RUBY_VERSION < “1.9.0”

Defined Under Namespace

Modules: Ensembl, GeneLocationField, Miriam, Utils, VarLocationField, XrefsField Classes: Aa, Cell, Change, Chrref, CreateUserError, Dataset, Gene, Generef, InvalidResponse, Isoform, Lossgain, Mapping, Occurrent, Offexon, Onexon, Reference, Region, Source, Splice, Utr, Variant, Variantref

Constant Summary collapse

VERSION =
"0.1.3"
NAIUPAC =
{
  'Y'  => 'CT',
  'R'  => 'AG',
  'W'  => 'AT',
  'S'  => 'CG',
  'K'  => 'GT',
  'M'  => 'AC',
  
  'B'  => 'CGT',
  'D'  => 'AGT',
  'H'  => 'ACT',
  'V'  => 'ACG',
  
  'N'  => 'ACGT',
  
  'A'  => 'A',
  'T'  => 'T',
  'G'  => 'G',
  'C'  => 'C',
  'U'  => 'U',
  
  'CT' => 'Y',
  'AG' => 'R',
  'AT' => 'W',
  'CG' => 'S',
  'GT' => 'K',
  'AC' => 'M',
  
  'CGT' => 'B',
  'AGT' => 'D',
  'ACT' => 'H',
  'ACG' => 'V',
  
  'ACGT' => 'N'
}
ASSEMBLY =
{
  'hg19' => 'GRCh37',
  'hg38' => 'GRCh38',
  'GRCh37' => 'GRCh37',
  'GRCh38' => 'GRCh38',
  'grch37' => 'GRCh37',
  'grch38' => 'GRCh38'
}
DEFAULTASSEMBLY =
'GRCh37'
LATESTASSEMBLY =
'GRCh38'
HGVPATTERN =
/^([^:]+):g\.([\-_\d]+)([ATGC]>[ATCG]|del[ATCG]*|ins[ATCG]*)$/
@@verbose =
true

Class Method Summary collapse

Class Method Details

.assembly(str) ⇒ Object



67
68
69
# File 'lib/exodb.rb', line 67

def assembly(str)
  return Exodb::ASSEMBLY[str.downcase]
end

.connect(connectionstr = {}) ⇒ Object

Parameters:

  • Connection (Hash, String)

    string or a Hash in format { database: ‘exodus’, hosts: [‘localhost:27017’], username: ‘xxx’, options: {}}



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/exodb/dbconnection.rb', line 30

def connect(connectionstr = {})
  
  settings = { database: 'exodus', hosts: ['localhost:27017'], options: {}}
  
  if connectionstr.is_a?(Hash)
    connectionstr.each_pair {|k, v| settings[k.to_sym] = k.to_sym == :hosts ? [v].flatten : v}
  elsif connectionstr.is_a?(String)
    split1 = connectionstr.split('@')
    settings[:username] = split1[0] if split1.length > 1
    split2 = split1[-1].split('/')
    settings[:database] = split2[1] if split2.length > 1
    settings[:hosts] = [split2[0]].flatten
  end
  
  password = ask("Password:  ") { |q| q.echo = "*" } if settings[:username] && !settings[:password]
  
  Mongoid::Sessions.disconnect
  Mongoid::Sessions.clear
  Mongoid.load_configuration({"sessions"=>{"default"=> password ? settings.merge({password: password}) : settings}})
  
  return "#EXODB:INFO Connection with #{settings}" if Pry.current
end

.create_admin(username, database) ⇒ Object

To create an admin user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created



59
60
61
62
63
# File 'lib/exodb/usermanage.rb', line 59

def create_admin(username, database)
  
  create_user(username, database, "readWrite", "dbAdmin", "userAdmin")
  
end

.create_rouser(username) ⇒ Object

To create a read-only user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created



78
79
80
81
82
# File 'lib/exodb/usermanage.rb', line 78

def create_rouser(username)
  
  create_user(username, Mongoid.session(:default).options[:database], "read")
  
end

.create_rwuser(username) ⇒ Object

To create a rw user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created



69
70
71
72
73
# File 'lib/exodb/usermanage.rb', line 69

def create_rwuser(username)
  
  create_user(username, Mongoid.session(:default).options[:database], "readWrite")
  
end

.create_user(username, database, *roles) ⇒ Object

General command for creating a user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created

  • roles (Array)

    to be assigned to the user



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/exodb/usermanage.rb', line 22

def create_user(username, database, *roles)
  
  if database != 'admin'
    
    password = nil
    confirmed = nil
    
    while !password || password != confirmed
      password = ask("New password:  ") { |q| q.echo = "*" }
      confirmed = ask("Confirm password:  ") { |q| q.echo = "*" }
      
      puts "Password not match!\n" if password != confirmed
      
    end
    
    if database
      Mongoid.session(:default).with(database: database).command(
        createUser: username,
        pwd: password,
        roles: roles.flatten
      )
    else
      Mongoid.session(:default).command(
        createUser: username,
        pwd: password,
        roles: roles.flatten
      )
    end
  else
    raise CreateUserError, 'Cannot create user on admin database'
  end
end

.current_databaseString

Return the current database name

Returns:

  • (String)

    the database name



79
80
81
# File 'lib/exodb/dbconnection.rb', line 79

def current_database
  self.session.options[:database]
end

.noverboseObject



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

def noverbose()
  @@verbose = false
end

.putst(str) ⇒ Object



63
64
65
# File 'lib/exodb.rb', line 63

def putst(str)
  puts "Exodb:STATUS #{str}"
end

.putstv(str) ⇒ Object



59
60
61
# File 'lib/exodb.rb', line 59

def putstv(str)
  putst(str) if @@verbose == true
end

.sessionString

Return the session setting

Returns:

  • (String)

    the session setting



72
73
74
# File 'lib/exodb/dbconnection.rb', line 72

def session
  Mongoid.session(:default)
end

.sessionload!(sessionfile = nil) ⇒ Object

load session file

Parameters:

  • path (String)

    to session file



19
20
21
22
23
24
25
# File 'lib/exodb/dbconnection.rb', line 19

def sessionload!(sessionfile = nil)
    if sessionfile && File.exist?(sessionfile)
      Mongoid.load!(sessionfile, :production)
    else
      Mongoid.load!("#{Dir.pwd}/session.yml", :production) if File.exist?("#{Dir.pwd}/session.yml")
    end
end

.verboseObject



51
52
53
# File 'lib/exodb.rb', line 51

def verbose()
  @@verbose = true
end