def generic_report(id): aligned_volume_name, pcg_table_name = get_relevant_datastack_info( datastack_name) session = sqlalchemy_cache.get(aligned_volume_name) table = session.query(AnalysisTable).filter(AnalysisTable.id == id).first() make_dataset_models(table.analysisversion.dataset, [], version=table.analysisversion.version) Model = make_annotation_model( table.analysisversion.dataset, table.schema, table.tablename, version=table.analysisversion.version, ) n_annotations = Model.query.count() return render_template( "generic.html", n_annotations=n_annotations, dataset=table.analysisversion.dataset, analysisversion=table.analysisversion.version, version=__version__, table_name=table.tablename, schema_name=table.schema, )
def test_model_creation(): metadata_dict = {'spinecall': {'reference_table': 'synapse'}} model_dict = make_dataset_models( 'test', [('synapse', 'synapse'), ('postsynaptic_compartment', 'spinecall')], include_contacts=True) model = model_dict['synapse'] assert (model.__name__ == "synapse") model = model_dict['contact'] assert (model.__name__ == "test__contact") model = model_dict['spinecall'] assert (model.__name__ == 'spinecall') assert (issubclass(model, Base))
def synapse_report(datastack_name, id): aligned_volume_name, pcg_table_name = get_relevant_datastack_info( datastack_name) session = sqlalchemy_cache.get(aligned_volume_name) table = session.query(AnalysisTable).filter(AnalysisTable.id == id).first() if table.schema != "synapse": abort(504, "this table is not a synapse table") make_dataset_models(table.analysisversion.datastack, [], version=table.analysisversion.version) SynapseModel = make_annotation_model( table.analysisversion.dataset, "synapse", table.tablename, version=table.analysisversion.version, ) synapses = SynapseModel.query.count() n_autapses = (SynapseModel.query.filter( SynapseModel.pre_pt_root_id == SynapseModel.post_pt_root_id).filter( and_(SynapseModel.pre_pt_root_id != 0, SynapseModel.post_pt_root_id != 0)).count()) n_no_root = SynapseModel.query.filter( or_(SynapseModel.pre_pt_root_id == 0, SynapseModel.post_pt_root_id == 0)).count() return render_template( "synapses.html", num_synapses=synapses, num_autapses=n_autapses, num_no_root=n_no_root, dataset=table.analysisversion.dataset, analysisversion=table.analysisversion.version, version=__version__, table_name=table.tablename, schema_name="synapses", )
def cell_type_local_report(datastack_name, id): aligned_volume_name, pcg_table_name = get_relevant_datastack_info( datastack_name) session = sqlalchemy_cache.get(aligned_volume_name) table = AnalysisTable.query.filter(AnalysisTable.id == id).first_or_404() if table.schema != "cell_type_local": abort(504, "this table is not a cell_type_local table") make_dataset_models(table.analysisversion.dataset, [], version=table.analysisversion.version) CellTypeModel = make_annotation_model( table.analysisversion.dataset, table.schema, table.tablename, version=table.analysisversion.version, ) n_annotations = CellTypeModel.query.count() cell_type_merge_query = (db.session.query( CellTypeModel.pt_root_id, CellTypeModel.cell_type, func.count(CellTypeModel.pt_root_id).label("num_cells"), ).group_by(CellTypeModel.pt_root_id, CellTypeModel.cell_type).order_by("num_cells DESC")).limit(100) df = pd.read_sql(cell_type_merge_query.statement, db.get_engine(), coerce_float=False) return render_template( "cell_type_local.html", version=__version__, schema_name=table.schema, table_name=table.tablename, dataset=table.analysisversion.dataset, table=df.to_html(), )
def test_model_creation(): metadata_dict = {"spinecall": {"reference_table": "synapse"}} model_dict = make_dataset_models( aligned_volume="test", schemas_and_tables=[ ("synapse", "synapse"), ("postsynaptic_compartment", "spinecall"), ], metadata_dict=metadata_dict, include_contacts=True, ) synapse_model = model_dict["synapse"] assert synapse_model.__name__ == "synapse" assert issubclass(synapse_model, Base) contact_model = model_dict["contact"] assert contact_model.__name__ == "test__contact" assert issubclass(contact_model, Base) ref_model = model_dict["spinecall"] assert ref_model.__name__ == "spinecall" assert issubclass(ref_model, Base)