コード例 #1
0
def get_body_ids_from_roi(roi,
                          server,
                          token,
                          hemibrain_neuron=True,
                          pre_threshold=0,
                          post_threshold=0,
                          total_threshold=0):
    """

    Args:
        roi (str): Neuropil abreviation from Neuprint
        server (str): Neuprint server URL
        token (str): Neuprint auth token
        hemibrain_neuron (bool): Specifies whether to search
            Hemibrain-Neuron of Hemibrain-Segment.
        pre_threshold (int): Requires bodies meet threshold of presynaptic sites
            in the ROI
        post_threshold (int): Requires bodies meet threshold of postsynaptic sites
            in the ROI
        total_threshold (int): Requires bodies meet threshold of total synaptic sites
            in the ROI

    Returns:
        Dataframe containing body IDs that innervate the ROI

    """
    query_template = (
        'MATCH (n:`{HEMIBRAIN}`)\n'
        'WHERE n.{ROI}\n'
        'RETURN n.bodyId AS ID, n.name AS NAME, n.roiInfo AS ROIINFO'
    )

    # Start Neuprint python client
    client = Client(server, token)
    client.fetch_version()

    if hemibrain_neuron:
        query = query_template.format(HEMIBRAIN='hemibrain-Neuron', ROI=roi)
    else:
        query = query_template.format(HEMIBRAIN='hemibrain-Segment', ROI=roi)

    results = client.fetch_custom(query)
    results['ROIINFO'] = results['ROIINFO'].apply(ast.literal_eval)
    results['PRE'] = results['ROIINFO'].apply(lambda x: int(x[roi]['pre']))
    results['POST'] = results['ROIINFO'].apply(lambda x: int(x[roi]['post']))

    results = results[results['PRE'] + results['POST'] >= total_threshold]
    results = results[results['PRE'] >= pre_threshold]
    results = results[results['POST'] >= post_threshold]

    return results[['ID', 'NAME', 'PRE', 'POST']].reset_index()
コード例 #2
0
def test_members():
    set_default_client(None)
    assert default_client() is None
    c = Client(NEUPRINT_SERVER, DATASET)
    assert c.server == f'https://{NEUPRINT_SERVER}'
    assert c.dataset == DATASET

    assert default_client() is c

    df = c.fetch_custom("MATCH (m:Meta) RETURN m.primaryRois as rois")
    assert isinstance(df, pd.DataFrame)
    assert df.columns == ['rois']
    assert len(df) == 1
    assert isinstance(df['rois'].iloc[0], list)

    assert isinstance(c.fetch_available(), list)
    assert isinstance(c.fetch_help(), str)
    assert c.fetch_server_info() is True
    assert isinstance(c.fetch_version(), str)
    assert isinstance(c.fetch_database(), dict)
    assert isinstance(c.fetch_datasets(), dict)
    assert isinstance(c.fetch_db_version(), str)
    assert isinstance(c.fetch_profile(), dict)
    assert isinstance(c.fetch_token(), str)
    assert isinstance(c.fetch_daily_type(), tuple)
    assert isinstance(c.fetch_roi_completeness(), pd.DataFrame)
    assert isinstance(c.fetch_roi_connectivity(), pd.DataFrame)
    assert isinstance(c.fetch_roi_mesh('AB(R)'), bytes)
    assert isinstance(c.fetch_skeleton(EXAMPLE_BODY), pd.DataFrame)
コード例 #3
0
import os

import h5py
import neuprint
from neuprint import Client, queries, SegmentCriteria
from extract_labels_from_volume import extract_labels_from_volume

import numpy as np

c = Client(
    'neuprint.janelia.org',
    dataset='hemibrain:v1.1',
    token=
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFuZHJldy5saW5Ac2hlZmZpZWxkLmFjLnVrIiwibGV2ZWwiOiJub2F1dGgiLCJpbWFnZS11cmwiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS0vQUF1RTdtQmp2LXlGaUlDWjdFQ3AwUHhzYmNVSHNDclppTU96eWtHbnFSemk_c3o9NTA_c3o9NTAiLCJleHAiOjE3NjE0MzE3Mzh9.kfurqTReeqmGsFHQdkKKGhTcaw3JR-FnpxCpMpS7uOA'
)
print(c.fetch_version())

print("Loading volume")
with h5py.File('hemibrain-v1.1-primary-roi-segmentation.h5', 'r') as f:
    roi_vol_scale_5 = f['volume-256nm'][:]

KCs = SegmentCriteria(type="^KC.*", regex=True)
KCneurons, KCroicounts = neuprint.queries.fetch_neurons(KCs)
KCids = KCneurons['bodyId']
KCidsarray = np.asarray(KCids)
np.savetxt("KCids_v1.1.csv", KCidsarray, delimiter=",", fmt="%u")
for i in range(0, len(KCids)):
    print(f"Fetching skeleton for KC {i}")
    KC = SegmentCriteria(bodyId=KCids[i])
    KCskel = c.fetch_skeleton(KCids[i], format='pandas', heal=True)
    print(f"Extracting ROI for each skeleton point for KC {i}")
コード例 #4
0
            try:
                c = Client('neuprint.janelia.org', dataset='hemibrain:v1.2', token=Token)
                with open(token_file_name, "wt")as ff:
                    ff.writelines(Token)
                check_token=1
            except:
                pass
else:
    with open(token_file_name,"rt")as ff:
        for line in ff:
            if line.find("\n")!=-1:
                line=line[:-1]
            Token=line
            break
c = Client('neuprint.janelia.org', dataset='hemibrain:v1.2', token=Token)
c.fetch_version()



def lookup(line):
    if re.search('[a-zA-Z]', line) != None:
        condition = "type="
        if line.find("*") != -1:
            condition=condition+"~"
        condition=condition+"\""
        if line[0].find("*")!=-1:
            condition=condition+"."
        if line[-1].find("*")!=-1:
            condition=condition+line[:-1]+".*\""
        else:
            condition=condition+line+"\""
コード例 #5
0
ファイル: fly.py プロジェクト: grelade/fruitfly
from neuprint import Client

# Please put the API token into the environment variable NEUPRINT_APPLICATION_CREDENTIALS

client = Client('neuprint.janelia.org', dataset='hemibrain:v1.1')

client.fetch_version()

コード例 #6
0
output_dedge_csv = os.path.join(output_dir, "preprocessed_directed_edges.csv")

# check that output doesn't exist, or that overwrite option is set
if not args.force and any([os.path.isfile(f) for f in [output_node_csv, output_uedge_csv, output_dedge_csv]]):
    logging.warning("Found existing output file(s):")
    for f in [output_node_csv, output_uedge_csv, output_dedge_csv]:
        if os.path.isfile(f):
            print(f)
    logging.warning("Force overwriting with -f, or specifiy output with --output_dir")
    exit(1)

# Connect to Janelia
auth_token_file = open(args.auth_file, 'r')
auth_token = next(auth_token_file).strip()
np_client = Client('neuprint.janelia.org', dataset='hemibrain:v' + args.hemibrain_version, token=auth_token)
logging.info('Connected to neuprint; client version %s', np_client.fetch_version())


logging.debug("path = %s", path)
logging.debug("cluster_dir = %s", cluster_dir)

logging.info("Attempting to read neuron csv with pandas: %s", neuron_csv)
local_df = pd.read_csv(neuron_csv)

# Read cluster info and prepare node df
for filename in os.listdir(cluster_dir):
    logging.info("Reading file %s", os.path.join(cluster_dir, filename))
    if "unweighted" in filename:
        cluster_name = "unweighted"
    elif "lr" in filename:
        cluster_name = "lr"