3.1.1.5. datanator_query_python.util package

3.1.1.5.1. Submodules

3.1.1.5.2. datanator_query_python.util.base26 module

Fork from git@github.com:mnowotka/chembl_ikey.git

datanator_query_python.util.base26.base26_dublet_for_bits_28_to_36(a)[source]
datanator_query_python.util.base26.base26_dublet_for_bits_56_to_64(a)[source]
datanator_query_python.util.base26.base26_triplet_1(a)[source]
datanator_query_python.util.base26.base26_triplet_2(a)[source]
datanator_query_python.util.base26.base26_triplet_3(a)[source]
datanator_query_python.util.base26.base26_triplet_4(a)[source]

3.1.1.5.3. datanator_query_python.util.chem_util module

class datanator_query_python.util.chem_util.ChemUtil[source]

Bases: object

get_sha256(text)[source]
hash_inchi(inchi='InChI = None')[source]

Hash inchi string using sha224

inchi_to_inchikey(szINCHISource)[source]

fork from git@github.com:mnowotka/chembl_ikey.git

simplify_inchi(inchi='InChI = None')[source]

Remove molecules’s protonation state “InChI=1S/H2O/h1H2” = > “InChI=1S/H2O”

3.1.1.5.4. datanator_query_python.util.file_util module

class datanator_query_python.util.file_util.FileUtil[source]

Bases: object

access_dict_by_index(_dict, count)[source]

Assuming dict has an order, return the first num of elements in dictionary :param _dict: { ‘a’:1, ‘b’:2, ‘c’:3, … } :param count: number of items to return

Returns

a dictionary with the first count

from _dict {‘a’:1}

Return type

result

exists_key_value_pair(dictionary, k, v)[source]

Test if a key/value pair exists in dictionary :param dict: dictionary to be checked :type dict: dict :param k: key to be matched :type k: str :param v (: obj:``): value to be matched

Returns

True or False

Return type

result (bool)

extract_values(obj, key)[source]

Pull all values of specified key from nested JSON.

flatten_json(nested_json)[source]

Flatten json object with nested keys into a single level. e.g. {a: b, {a: b,

c: [ d: e,

{d: e}, => f: g } {f: g}]}

Parameters

nested_json – A nested json object.

Returns

The flattened json object if successful, None otherwise.

get_common(list1, list2)[source]

Given two lists, find the closest common ancestor.

Parameters
  • list1 (list) – [a, b, c, f, g]

  • list2 (list) – [a, b, d, e]

Returns

the closest common ancestor, in the above example would be b.

Return type

(obj)

get_val_from_dict_list(dict_list, key)[source]

Get values for key from a list of dictionaries :param dict_list: list of dictionary

to query

Parameters

key (str) – key for which to get the value

Returns

obj:): list of values

Return type

results (list of

make_dict(keys, values)[source]

Give two lists, make a list of dictionaries :param keys: [a, b, c, d, …] :param values: [1, 2, 3, 4]

Returns

{‘a’: 1, ‘b’: 2, ‘c’: 3, …}

Return type

dic

merge_dict(dicts)[source]

Merge a list of dictionaries :param dicts: list of dictionaries :type dicts: list of dict

Returns

merged dictionries

Return type

result (dict)

replace_dict_key(_dict, replacements)[source]

Replace keys in a dictionary with the order in replacements e.g., {‘a’: 0, ‘b’: 1, ‘c’: 2}, [‘d’, ‘e’, ‘f’] => {‘d’: 0, ‘e’: 1, ‘f’: 2} :param _dict: dictionary whose keys are to be replaced :param replacement: list of replacement keys

Returns

dictionary with replaced keys

Return type

result

search_dict_index(dict_list, key, value)[source]

Find the index of the dictionary that contains key/val pair within the dict_list

Parameters
  • dict_list (list of dict) – list of dictionaries

  • key (str) – dictionary key

  • ( (value) – obj:): dictionary value.

Returns

list of indices.

Return type

index (list of int)

search_dict_list(dict_list, key, value='')[source]

Find the dictionary with key/value pair in a list of dictionaries

Parameters
  • dict_list (list) – list of dictionaries

  • key (string) – key in the dictionary

  • ( (value) – obj:``): value to be matched if value==None, then only search for key

Returns

list of dictionaries with the key/value pair

Return type

result (list of dict)

unpack_list(_list)[source]

Unpack sublists in a list :param _list: a list containing sublists e.g. [ […], […], … ]

Returns

unpacked list e.g. [ …. ]

Return type

result

class datanator_query_python.util.file_util.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.encoder.JSONEncoder

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)

3.1.1.5.5. datanator_query_python.util.mapper_reducer module

Form mapper and/or reducer https://api.mongodb.com/python/current/examples/aggregation.html

class datanator_query_python.util.mapper_reducer.MaRe[source]

Bases: object

snippet(_input)[source]

Takes in JavaScript string and code to function.

Parameters

_input (str) – JavaScript string.

Returns

(bson.code.Code)

3.1.1.5.6. datanator_query_python.util.mongo_util module

class datanator_query_python.util.mongo_util.MongoUtil(cache_dirname=None, MongoDB=None, replicaSet=None, db='test', verbose=False, max_entries=inf, username=None, password=None, authSource='admin', readPreference='nearest')[source]

Bases: object

build_taxon_object(_id, _format='tax_id')[source]

Build taxon object from taxon_id. (https://github.com/KarrLab/datanator_pattern_design/blob/master/components/taxon.json)

Parameters

_id (int) – Organism’s taxonomy ID.

Returns

(Obj)

con_db(collection_str)[source]
define_schema(collection_str, json_schema)[source]

Define collection’s $jsonSchema (https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/)

Parameters
  • collection_str (str) – Name of the collection to be defined.

  • json_schema (str or dict) – location of the jsonSchema definition.

flatten_collection(collection_str)[source]

Flatten a collection

c is ommitted because it does not have a non-object value associated with it

get_duplicates(collection_str, _key, **kwargs)[source]

Get duplicate key entries in collection.

Parameters
  • collection_str (str) – Name of collection.

  • _key (str) – Name of field in wichi to find duplicate values.

Returns

length of cursor and documents iterable.

Return type

(tuple of int and CommandCursor)

get_schema(collection_str)[source]

Get schema of a collection removed ‘_id’ from collection due to its object type and universality

list_all_collections()[source]

List all non-system collections within database

update_entity(obj, match, db='test', col='entity', op='update', query={})[source]

Update entity collection.

Parameters
  • obj (Obj) – object to be updated with.

  • match (Obj) – Identifier used to match existing document in collection.

  • db (str) – Name of database to be updated.

  • col (str) – Name of collection to be updated.

  • op (str) – operation to be done, e.g. update or bulk.

  • query (Obj) – Filter for updating operation.

update_observation(obj, source, db='test', op='update', col='observation', query={})[source]

Update observation collection

Parameters
  • obj (Obj) – obs object to be updated with.

  • source (Obj) – one of the sources used for matching.

  • db (Obj) – Name of database to be updated.

  • op (str) – Operation to be done.

  • col (str) – Name of collection to be updated.

  • query (Obj) – Filter for updating operation.

3.1.1.5.7. datanator_query_python.util.motor_util module

class datanator_query_python.util.motor_util.MotorUtil(MongoDB=None, replicaSet=None, db='test', verbose=False, max_entries=inf, username=None, password=None, authSource='admin', readPreference='nearest')[source]

Bases: object

3.1.1.5.8. datanator_query_python.util.parse_heroku_logs module

Parsing Heroku app datanator-rest-api

class datanator_query_python.util.parse_heroku_logs.ParseLogs(file_location=None, verbose=False)[source]

Bases: object

parse_regex(s, regex)[source]

Find in line matches for regulation expressions.

Parameters
  • s (str) – String in which to find matching regular expression.

  • regex( – obj:re`): regular expression.

Returns

Matches found.

Return type

(list)

parse_router(lines=0)[source]

Parse router lines to get API performance values.

Parameters

lines (int, optional) – Number of lines to parse. If 0, parse all lines.

Returns

(Obj)

3.1.1.5.9. Module contents