Ejemplo n.º 1
0
 def test_get_from_uuid(self, kg_client):
     uri = "https://nexus.humanbrainproject.org/v0/data/neuralactivity/experiment/patchedcell/v0.1.0/5ab24291-8dca-4a45-a484-8a8c28d396e2"
     a = PatchedCell.from_uri(uri, kg_client, api="nexus")
     b = PatchedCell.from_uuid("5ab24291-8dca-4a45-a484-8a8c28d396e2",
                               kg_client,
                               api="nexus")
     assert a == b
     assert a.id == uri
Ejemplo n.º 2
0
 def test_repr(self):
     try:
         unicode
     except NameError:
         cell = PatchedCell("example001",
                            brain_location=BrainRegion("primary auditory cortex"),
                            collection=None,
                            cell_type=CellType("pyramidal cell"),
                            experiments=None,
                            pipette_id=31,
                            seal_resistance=QuantitativeValue(1.2, "GΩ"),
                            pipette_resistance=QuantitativeValue(1.5, "MΩ"),
                            liquid_junction_potential=None,
                            labeling_compound="0.1% biocytin ",
                            reversal_potential_cl=None)
         expected_repr = ("PatchedCell(name='example001', "
                          "brain_location=BrainRegion('primary auditory cortex', 'http://purl.obolibrary.org/obo/UBERON_0034751'), "
                          "cell_type=CellType('pyramidal cell', 'http://purl.obolibrary.org/obo/CL_0000598'), "
                          "pipette_id=31, seal_resistance=QuantitativeValue(1.2 'GΩ'), "
                          "pipette_resistance=QuantitativeValue(1.5 'MΩ'), "
                          "labeling_compound='0.1% biocytin ', id=None)")
         assert repr(cell) == expected_repr
     else:
         pytest.skip(
             "The remaining lifespan of Python 2 is too short to fix unicode representation errors")
Ejemplo n.º 3
0
 def test_get_from_uri_with_cache(self, kg_client):
     assert len(kg_client.cache) == 0
     assert kg_client._nexus_client._http_client.request_count == 0
     uri = "https://nexus.humanbrainproject.org/v0/data/neuralactivity/experiment/patchedcell/v0.1.0/5ab24291-8dca-4a45-a484-8a8c28d396e2"
     # 1st call
     cell1 = PatchedCell.from_uri(uri, kg_client, api="nexus")
     assert len(kg_client.cache) == 1
     assert kg_client._nexus_client._http_client.request_count == 1
     assert uri in kg_client.cache
     # 2nd call
     cell2 = PatchedCell.from_uri(uri, kg_client, api="nexus")
     assert kg_client._nexus_client._http_client.request_count == 1  # should be unchanged if cache was used
     # 3rd call, without cache
     cell3 = PatchedCell.from_uri(uri, kg_client, use_cache=False, api="nexus")
     assert kg_client._nexus_client._http_client.request_count == 2
     assert cell1.id == cell2.id == cell3.id == uri
Ejemplo n.º 4
0
 def test_get_from_uri_kgquery_simple(self, kg_client):  # TODO: UPDATE STORED QUERY
     uri = "https://nexus.humanbrainproject.org/v0/data/neuralactivity/experiment/patchedcell/v0.1.0/b813a2f7-5e87-4827-81cd-0008da041648"
     cell = PatchedCell.from_uri(uri, kg_client, api="query", resolved=False)
     assert isinstance(cell, PatchedCell)
     assert cell.brain_location == [BrainRegion('5th cerebellar lobule'),
                                    BrainRegion('6th cerebellar lobule'),
                                    BrainRegion('7th cerebellar lobule'),
                                    BrainRegion('8th cerebellar lobule')]
     assert isinstance(cell.collection, KGQuery)
     assert isinstance(cell.experiments, KGQuery)
Ejemplo n.º 5
0
 def test_get_from_uri_nexus(self, kg_client):
     uri = "https://nexus.humanbrainproject.org/v0/data/neuralactivity/experiment/patchedcell/v0.1.0/5ab24291-8dca-4a45-a484-8a8c28d396e2"
     cell = PatchedCell.from_uri(uri, kg_client, api="nexus")
     assert isinstance(cell, PatchedCell)
     assert cell.id == uri
     assert cell.brain_location == [BrainRegion('lobule 5 of the cerebellar vermis'),
                                    BrainRegion('lobule 6 of the cerebellar vermis'),
                                    BrainRegion('lobule 7 of the cerebellar vermis'),
                                    BrainRegion('lobule 8 of the cerebellar vermis')]
     assert isinstance(cell.collection, KGQuery)
     assert isinstance(cell.experiments, KGQuery)
Ejemplo n.º 6
0
 def test_round_trip(self, kg_client):
     cell1 = PatchedCell("example001",
                         brain_location=BrainRegion("primary auditory cortex"),
                         collection=None,
                         cell_type=CellType("pyramidal cell"),
                         experiments=None,
                         pipette_id=31,
                         seal_resistance=QuantitativeValue(1.2, "GΩ"),
                         pipette_resistance=QuantitativeValue(1.5, "MΩ"),
                         liquid_junction_potential=QuantitativeValue(5.0, "mV"),
                         labeling_compound="0.1% biocytin ",
                         reversal_potential_cl=QuantitativeValue(-65, "mV"))
     instance = Instance(PatchedCell.path, cell1._build_data(kg_client), Instance.path)
     instance.data["@id"] = "http://fake_uuid_93f9cd9a9b"
     instance.data["@type"] = PatchedCell.type
     cell2 = PatchedCell.from_kg_instance(instance, kg_client)
     for field in ("name", "brain_location", "cell_type",
                   "pipette_id", "seal_resistance", "pipette_resistance",
                   "liquid_junction_potential", "labeling_compound",
                   "reversal_potential_cl"):
         assert getattr(cell1, field) == getattr(cell2, field)
Ejemplo n.º 7
0
 def test_list_nexus(self, kg_client):
     cells = PatchedCell.list(kg_client, api="nexus", size=50)
     assert len(cells) == 30
     assert cells[0].brain_location == BrainRegion("hippocampus CA1")
     assert isinstance(cells[0].collection, KGQuery)
     assert cells[0].cell_type == CellType("hippocampus CA1 pyramidal cell")
     assert isinstance(cells[0].experiments, KGQuery)
     assert cells[0].pipette_id is None
     assert cells[0].seal_resistance is None
     assert cells[0].pipette_resistance is None
     assert cells[0].liquid_junction_potential is None
     assert cells[0].labeling_compound is None
     assert cells[0].reversal_potential_cl == QuantitativeValue(-16.0, unit_text="mV")
Ejemplo n.º 8
0
 def test_repr(self):
     cell = PatchedCell(
         "example001",
         brain_location=BrainRegion("primary auditory cortex"),
         collection=None,
         cell_type=CellType("pyramidal cell"),
         experiments=None,
         pipette_id=31,
         seal_resistance=QuantitativeValue(1.2, "GΩ"),
         pipette_resistance=QuantitativeValue(1.5, "MΩ"),
         liquid_junction_potential=None,
         labeling_compound="0.1% biocytin ",
         reversal_potential_cl=None)
     expected_repr = (
         "PatchedCell(name='example001', "
         "brain_location=BrainRegion('primary auditory cortex', 'http://uri.interlex.org/ilx_0443027'), "
         "cell_type=CellType('pyramidal cell', 'http://uri.interlex.org/ilx_0107385'), "
         "pipette_id=31, seal_resistance=QuantitativeValue(1.2 'GΩ'), "
         "pipette_resistance=QuantitativeValue(1.5 'MΩ'), "
         "labeling_compound='0.1% biocytin ', id=None)")
     assert repr(cell) == expected_repr
Ejemplo n.º 9
0
 def test_by_name_kgquery(self, kg_client):
     cell = PatchedCell.by_name("GF1.samp1", kg_client, api="query")
     assert cell.uuid == "b813a2f7-5e87-4827-81cd-0008da041648"
Ejemplo n.º 10
0
 def test_by_name_nexus_not_found(self, kg_client):
     cell = PatchedCell.by_name("qwertyuiop", kg_client, api="nexus")
     assert cell is None
Ejemplo n.º 11
0
 def test_by_name_nexus(self, kg_client):
     cell = PatchedCell.by_name("sub2epsp.samp1", kg_client, api="nexus")
     assert cell.uuid == "5ab24291-8dca-4a45-a484-8a8c28d396e2"
Ejemplo n.º 12
0
 def test_list_with_filter(self, kg_client):
     cells = PatchedCell.list(kg_client, api="nexus", brain_region=BrainRegion("hippocampus CA1"), size=50)
     assert len(cells) == 26
Ejemplo n.º 13
0
def test_all():
    ## Search based on brain region

    cells_in_ca1 = PatchedCell.list(
        client, brain_region=BrainRegion("hippocampus CA1"))
    pprint([cell.brain_location for cell in cells_in_ca1])

    ### Download the recorded data for one of these cells

    example_cell = cells_in_ca1[3]
    experiment = example_cell.experiments.resolve(client)
    trace = experiment.traces.resolve(client)
    print(trace.time_step)
    print(trace.data_unit)

    download_url = trace.data_location.location
    print(download_url)

    data = np.genfromtxt(BytesIO(requests.get(download_url).content))

    ### Plot the data

    times = data[:, 0]
    signals = data[:, 1:]

    # plot the first 100 signals
    plt.figure(figsize=(18, 16), dpi=80, facecolor='w', edgecolor='k')
    xlim = (times.min(), times.max())
    for i in range(1, 101):
        plt.subplot(10, 10, i)
        plt.plot(times, data[:, i], 'grey')
        plt.xlim(*xlim)
        plt.axis('off')

    ## Search based on species

    cells_from_mouse = PatchedCell.list(client,
                                        species=Species("Mus musculus"))
    for cell in cells_from_mouse[:10]:
        pprint(
            cell.collection.resolve(client).slice.resolve(
                client).slice.resolve(client).subject.resolve(client).species)

    ## Search based on cell type

    pyramidal_neurons = PatchedCell.list(
        client, cell_type=CellType("hippocampus CA1 pyramidal cell"))
    pprint([pn.cell_type for pn in pyramidal_neurons[:10]])

    # An activity dataset with minimal metadata

    Dataset.set_strict_mode(False)

    query = {
        "path":
        "minds:specimen_group / minds:subjects / minds:samples / minds:methods / schema:name",
        "op":
        "in",
        "value": [
            "Electrophysiology recording", "Voltage clamp recording",
            "Single electrode recording",
            "functional magnetic resonance imaging"
        ]
    }
    context = {
        "schema": "http://schema.org/",
        "minds": "https://schema.hbp.eu/minds/"
    }

    activity_datasets = KGQuery(Dataset, query, context).resolve(client)
    for dataset in activity_datasets:
        print("* " + getattr(dataset, "name", "unknown"))

    dataset = activity_datasets[-1]
    #dataset.owners[0].resolve(client)
    #dataset.license.resolve(client)

    ## An activity dataset with extended metadata

    dataset = client.by_name(
        Dataset,
        "sIPSCs from juvenile (P21-30) C57Bl6/J male mice from CA1 pyramidal neurons receiving input from PV+ interneurons"
    )
    query = {"path": "nsg:partOf", "op": "eq", "value": dataset.id}
    context = {
        "nsg":
        "https://bbp-nexus.epfl.ch/vocabs/bbp/neurosciencegraph/core/v0.1.0/"
    }
    traces = KGQuery(Trace, query, context).resolve(client)
    print(traces)

    tr0 = traces[0]

    print(tr0.name)
    print(tr0.channel)
    print(tr0.time_step)
    print(tr0.data_unit)
    print(tr0.data_location)

    experiment = tr0.generated_by.resolve(client)
    print(experiment.name)

    cell = experiment.recorded_cell.resolve(client)

    print(cell.brain_location)
    print(cell.cell_type)
    print(cell.reversal_potential_cl)