neo package

Submodules

neo.neo4j_tools module

class vfb_connect.neo.neo4j_tools.Neo4jConnect(endpoint='http://pdb.virtualflybrain.org', usr='neo4j', pwd='vfb')[source]

Bases: object

Thin layer over REST API to hold connection details, handle multi-statement POST queries, return results and report errors.

Parameters
  • endpoint – a neo4j REST endpoint

  • usr – username (content ignored if credentials not rqd)

  • pwd – password (content ignored if credentials not rqd)

commit_csv(url, statement, chunk_size=1000, sep=',')[source]
commit_list(statements, return_graphs=False)[source]

Commit a list of statements to neo4J DB via REST API. Errors prompt warnings (STDERR), not exceptions, and cause return = FALSE.

Param

statements: A list of cypher statements.

Param

return_graphs: Optional. Boolean. Returns graphs under ‘graph’ key if True. Default: False

Return

List of results or False if any errors are encountered.

commit_list_in_chunks(statements, verbose=False, chunk_length=1000)[source]

Commit multiple (chunked) commit of statements to neo4J DB via REST API. Errors prompt warnings (STDOUT), not exceptions, and cause return = FALSE.

Param

statements: A list of cypher statements.

Param

verbose: Boolean. Optionally print periodic reports of progress to STDOUT

Param

chunk_length. Int. Optional. Set chunk size. Default = 1000.

Return

List of results or False if any errors are encountered. Chunking is not reflected in results.

get_lookup(limit_by_prefix=None, include_individuals=False, limit_properties_by_prefix=('RO', 'BFO', 'VFBext'))[source]

Generate a name:ID lookup from a VFB neo4j DB, optionally restricted by a list of prefixes.

Parameters
  • limit_by_prefix – Optional list of id prefixes for limiting lookup of classes & individuals

  • include_individuals – If True, individuals included in lookup.

  • limit_properties_by_prefix – Optional list of id prefixes for limiting lookup of properties.

list_all_edge_props()[source]
list_all_node_props()[source]
rest_return_check(response)[source]

Checks status response to post. Prints warnings to STDERR if not OK. If OK, checks for errors in response. Prints any present as warnings to STDERR. Returns True STATUS OK and no errors, otherwise returns False.

test_connection()[source]

Test neo4j endpoint connection

vfb_connect.neo.neo4j_tools.chunks(l, n)[source]

Yield successive n-sized chunks from l.

Parameters

l – a list

Param

n, chunk size

vfb_connect.neo.neo4j_tools.cli_credentials()[source]

Parses command line credentials for Neo4J rest connection; Optionally specify additional args as a list of dicts with args required by argparse.add_argument(). Order in list specified arg order

vfb_connect.neo.neo4j_tools.cli_neofj_connect()[source]
vfb_connect.neo.neo4j_tools.dict_cursor(results)[source]

Takes JSON results from a neo4J query and turns them into a list of dicts.

Parameters

results – neo4j query results

Returns

list of dicts

vfb_connect.neo.neo4j_tools.escape_string(strng)[source]

Simple escaping for strings used in neo queries.

neo.query_wrapper module

class vfb_connect.neo.query_wrapper.QueryWrapper(*args, **kwargs)[source]

Bases: vfb_connect.neo.neo4j_tools.Neo4jConnect

get_DataSet_TermInfo(short_forms, summary=False)[source]

Generate JSON reports for types from a list of VFB IDs (short_forms) of DataSets.

Parameters
  • short_forms – An iterable (e.g. a list) of VFB IDs (short_forms) of types

  • summary – Optional. Returns summary reports if True. Default False

Return type

list of VFB_json or summary_report_json

get_TermInfo(short_forms)[source]

Generate JSON report for terms specified by a list of IDs

Parameters
  • short_forms (iter) – An iterable (e.g. a list) of VFB IDs (short_forms)

  • db – optionally specify the VFB id (short_form) of external DB.

  • id_type – optionally specify an external id_type

Returns

list of term metadata as VFB_json

get_anatomical_individual_TermInfo(short_forms, summary=False)[source]

Generate JSON reports for anatomical individuals from a list of VFB IDs (short_forms)

Parameters
  • short_forms – An iterable (e.g. a list) of VFB IDs (short_forms) of anatomical individuals

  • summary – Optional. Returns summary reports if True. Default False

Return type

list of VFB_json or summary_report_json

get_datasets(summary=False)[source]

Generate JSON report of all datsets.

Parameters

summary – Optional. Returns summary reports if True. Default False

Returns

Returns a list of terms as nested python data structures following VFB_json or a summary_report_json

Return type

list of VFB_json or summary_report_json

get_dbs()[source]

Get a list of available database IDs

Returns

list of VFB IDs.

get_images(short_forms, template, image_folder, image_type='swc', stomp=False)[source]

Given an iterable of short_forms for instances, find all images of specified image_type registered to template. Save these to image_folder along with a manifest.tsv. Return manifest as pandas DataFrame.

Parameters
  • short_forms (iter) – iterable (e.g. list) of VFB IDs of Individuals with images

  • template – template name

  • image_folder – folder to save image files & manifest to.

  • image_type – image type (file extension)

  • stomp – Overwrite image_folder if already exists.

Returns

Manifest as Pandas DataFrame

get_images_by_filename(filenames, dataset=None)[source]

Takes a list of filenames as input and returns a list of image terminfo. Optionally restrict by dataset (improves speed)

get_template_TermInfo(short_forms)[source]

Generate JSON reports for types from a list of VFB IDs (short_forms) of templates.

Parameters
  • short_forms – An iterable (e.g. a list) of VFB IDs (short_forms) of types

  • summary – Optional. Returns summary reports if True. Default False

Return type

list of VFB_json or summary_report_json

get_templates(summary=False)[source]

Generate JSON report of all available templates.

Parameters

summary – Optional. Returns summary reports if True. Default False

Returns

Returns a list of terms as nested python data structures following VFB_json or a summary_report_json

Return type

list of VFB_json or summary_report_json

get_terms_by_xref(acc, db='', id_type='')[source]

Generate JSON report for terms specified by a list of IDs

Parameters

short_forms – An iterable (e.g. a list) of VFB IDs (short_forms)

Returns

list of term metadata as VFB_json

get_type_TermInfo(short_forms, summary=False)[source]

Generate JSON reports for types from a list of VFB IDs (short_forms) of classes/types.

Parameters
  • short_forms – An iterable (e.g. a list) of VFB IDs (short_forms) of types

  • summary – Optional. Returns summary reports if True. Default False

Return type

list of VFB_json or summary_report_json

vfb_id_2_neuprint_bodyID(vfb_id, db='')[source]
vfb_id_2_xrefs(vfb_id, db='', id_type='', reverse_return=False)[source]

Map a list of short_form IDs in VFB to external DB IDs

Parameters
  • vfb_id (iter) – An iterable (e.g. a list) of VFB short_form IDs.

  • db – optional specify the VFB id (short_form) of an external DB to map to. (use get_dbs to find options)

  • id_type – optionally specify an external id_type

  • reverse_return – Boolean: Optional (see return)

Returns

if reverse_return is False:

dict { VFB_id : [{ db: <db> : acc : <acc> }

Return if reverse_return is True:

dict { acc : [{ db: <db> : vfb_id : <VFB_id> }

xref_2_vfb_id(acc=None, db='', id_type='', reverse_return=False)[source]

Map a list external DB IDs to VFB IDs

Parameters
  • acc – An iterable (e.g. a list) of external IDs (e.g. neuprint bodyIDs).

  • db – optional specify the VFB id (short_form) of an external DB to map to. (use get_dbs to find options)

  • id_type – optionally specify an external id_type

  • reverse_return – Boolean: Optional (see return)

Returns

if reverse_return is False:

dict { acc : [{ db: <db> : vfb_id : <VFB_id> }

Return if reverse_return is True:

dict { VFB_id : [{ db: <db> : acc : <acc> }

vfb_connect.neo.query_wrapper.batch_query(func)[source]
vfb_connect.neo.query_wrapper.gen_simple_report(terms)[source]

Module contents