Sqlite Library

class rnamake.sqlite_library.MotifEnsembleSqliteLibrary(libname)[source]

Bases: rnamake.sqlite_library.SqliteLibrary

Sqlite3 library for holding stringifed motif_ensemble.MotifEnsemble objects. It is significantly faster then reloading each motif from file.

Examples:
get(**options)

Gets row for sqlite3 database with specific variables specified in options. Will at most return 1 item even if multiple items meet selection criteria.

Parameters:options – sqlite3 select columns and values
Returns:unstringified data from database
get_multi(**options)

Gets row for sqlite3 database with specific variables specified in options. Same as get() except will return an list of all items that meet the selection criteria.

Parameters:options – sqlite3 select columns and values
Returns:unstringified data from database
get_random()

Gets a random row of data from sqlite3 database. Mostly used for testing purposes.

Returns:random row of unstringified data from database file
load_all(limit=99999)

Loads all data from database into memory. This has to be done if one wants to iterate over all the rows in database. Can set a limit with limit=N, will only load that many elements.

Parameters:limit – the max number of database rows that should be loaded
Returns:None
class rnamake.sqlite_library.MotifSqliteLibrary(libname)[source]

Bases: rnamake.sqlite_library.SqliteLibrary

Sqlite3 library for holding stringifed motif.Motif objects. It is significantly faster then reloading each motif from file.

Examples:
# gets all twoway junctions
>>> mlib = sqlite_library.MotifSqliteLibrary("ideal_helices")
>>> mlib.get(name="HELIX.IDEAL.2")
<Motif(
            structure='<Structure(name: N/A, #chains: 2, #residues: 8, #atoms: 172)>',
            ends='2')>
get(**options)

Gets row for sqlite3 database with specific variables specified in options. Will at most return 1 item even if multiple items meet selection criteria.

Parameters:options – sqlite3 select columns and values
Returns:unstringified data from database
static get_libnames()[source]

get dictionary of valid registered library names / paths. Only library names registered in this corresponding function in children classes can be loaded.

Returns:Dictionary of names / pathes for each valid sqlite3 database
Return type:dict
get_multi(**options)

Gets row for sqlite3 database with specific variables specified in options. Same as get() except will return an list of all items that meet the selection criteria.

Parameters:options – sqlite3 select columns and values
Returns:unstringified data from database
get_random()

Gets a random row of data from sqlite3 database. Mostly used for testing purposes.

Returns:random row of unstringified data from database file
load_all(limit=99999)

Loads all data from database into memory. This has to be done if one wants to iterate over all the rows in database. Can set a limit with limit=N, will only load that many elements.

Parameters:limit – the max number of database rows that should be loaded
Returns:None
class rnamake.sqlite_library.SqliteLibrary(libname)[source]

Bases: object

A wrapper for sqlite3 library, makes it simpler to do repeated sqlite3 calls with a set database file. This is a base class and should not be called directly.

Attributes:
data : Dictionary of stored data
Holds data already queryed from database file so dont have to do an extra query.
get(**options)[source]

Gets row for sqlite3 database with specific variables specified in options. Will at most return 1 item even if multiple items meet selection criteria.

Parameters:options – sqlite3 select columns and values
Returns:unstringified data from database
static get_libnames()[source]

get dictionary of valid registered library names / paths. Only library names registered in this corresponding function in children classes can be loaded.

Returns:Dictionary of names / pathes for each valid sqlite3 database
Return type:dict
get_multi(**options)[source]

Gets row for sqlite3 database with specific variables specified in options. Same as get() except will return an list of all items that meet the selection criteria.

Parameters:options – sqlite3 select columns and values
Returns:unstringified data from database
get_random()[source]

Gets a random row of data from sqlite3 database. Mostly used for testing purposes.

Returns:random row of unstringified data from database file
load_all(limit=99999)[source]

Loads all data from database into memory. This has to be done if one wants to iterate over all the rows in database. Can set a limit with limit=N, will only load that many elements.

Parameters:limit – the max number of database rows that should be loaded
Returns:None
rnamake.sqlite_library.build_sqlite_library(path, data, keys, primary_key)[source]

Builds a sqlite library to store various data. See setup scripts for more info on use. It is unlikely to be necessary to need to build new libraries. The length of each row must be the same length as keys.

Parameters:
  • path (String) – the path of sqlite3 library you want to create
  • data (list) – list of data to be stored in sqlite library
  • keys (list) – name of columns for each row in sqlite library
  • primary_key (String) – which of the keys specified will be the primary key, for sqlite3 index purposes, this must be a unique key, different for each row.
Returns:

None

Examples:
# build test library
# each list is a row in sqlite db
>>> data = [['the_word', 0], ['the', 1], ['hello', 2]]
# the name of each column
>>> keys = ['word', 'id']
>>> sqlite_library.build_sqlite_library("test.db", data, keys, 'id')

# read library
>>> import sqlite3
>>> conn = sqlite3.connect("test.db")
>>> conn.execute("SELECT * from data_table WHERE word='the_word'").fetchone()
(u'the_word', u'0')