Dear Stephanie,
I want to create a csv file with the data that I want from your database.
I would like to have: âpairâ, âsyn_typeâ, âpre_exp_idâ, âpre_idâ, âpre_classâ, âpre_layerâ,âpost_exp_idâ, âpost_idâ,
âpost_classâ, âpost_layerâ, âPSP_mean (mV)â, âstim_freq (Hz)â, âtime_rec (ms)â
Here I send you my code:
import numpy as np
import scipy.stats
from aisynphys.database import default_db as db
from aisynphys.cell_class import CellClass, classify_cells, classify_pairs
from aisynphys.connectivity import measure_connectivity, pair_was_probed
from aisynphys.database import SynphysDatabase
import matplotlib.pyplot as plt
from aisynphys.ui.notebook import plot_stim_sorted_pulse_amp
from aisynphys.dynamics import stim_sorted_pulse_amp
import csv
# Download and cache the sqlite file for the requested database
# Load all synapses associated with human projects
# First load the data base
path_to_db = '/Users/natalibarros/ai_synphys_cache/database/synphys_r2.0_medium.sqlite'
db = SynphysDatabase.load_version(path_to_db)
pairs = db.pair_query(project_name=db.human_projects, synapse=True).all()
print("loaded %d synapses" % len(pairs))
print("number of experiments %d" % len(set([pair.experiment for pair in pairs])))
print("number of experiments with recordings %d" %len(set([pair.experiment.data for pair in pairs])))
# We can do a pair_query to return pairs with stp valid values
query = db.pair_query(
experiment_type='standard multipatch', # filter: just multipatch experiments
species='human', # filter: only human data
synapse=True, # filter: only cell pairs connected by synapse
)
pairs = query.all()
print('number of pairs with patch experiments', len(pairs))
pairs_with_stp = [p for p in pairs if p.dynamics.stp_induction_50hz is not None] # Is that ok?
print('number of pairs with STP dynamics', len(pairs_with_stp))
N = 1
# create a csv file object to save useful values
path_to_csv_file = '/Users/natalibarros/Desktop/EPFL_BBP/HUMAN_CORTEX/CIRCUIT_BUILDING/DATA/DATA_Allen_Brain/PSP_values_DBmedium_04.csv'
with open(path_to_csv_file, 'wt') as csvfile:
writer = csv.writer(csvfile, delimiter=',', lineterminator='\n', )
# Add the header row
writer.writerow(['pair', 'syn_type', 'pre_exp_id', 'pre_id', 'pre_class', 'pre_layer','post_exp_id', 'post_id',
'post_class', 'post_layer', 'PSP_mean (mV)', 'stim_freq (Hz)', 'time_rec (ms)'])
for pair in pairs_with_stp:
print('#', N)
print('working on pair', pair)
N = N+1
# syn and cells information
try:
syn_type = pair.synapse.synapse_type
pre_exp_id = pair.pre_cell
pre_id = pair.pre_cell_id
pre_class = pair.pre_cell.cell_class
pre_layer = pair.pre_cell.cortical_location.cortical_layer
post_exp_id = pair.post_cell
post_id = pair.post_cell_id
post_class = pair.post_cell.cell_class
post_layer = pair.post_cell.cortical_location.cortical_layer
except AttributeError:
print('missing attribute')
continue
# PSPs information
qc_pass_data = stim_sorted_pulse_amp(pair, db=db)
# Stim freq information (ind_f)
try:
ind_f = int(qc_pass_data['induction_frequency'][0])
# scatter plots of event amplitudes sorted by pulse number
mask = qc_pass_data['induction_frequency'] == ind_f
except KeyError:
ind_f = 50 # assumption: if there is no stim freq, we suppose is 50 Hz
mask = qc_pass_data['induction_frequency'] == ind_f
print('no ind_f vector')
filtered = qc_pass_data[mask].copy()
sign = 1 if pair.synapse.synapse_type == 'ex' else -1
try:
filtered['dec_fit_reconv_amp'] *= sign * 1000 # the data are in Volts, so I convert them into mV.
except KeyError:
print('No fit amps for pair: %s' % pair)
PSP_means = filtered.groupby('pulse_number').mean()['dec_fit_reconv_amp'].to_list()
# Find recovery_delay???????
# Add the data row
writer.writerow([pair, syn_type, pre_exp_id, pre_id, pre_class, pre_layer,
post_exp_id, post_id, post_class, post_layer, PSP_means, ind_f, recov_time])
My questions are:
- Is it ok to use pair.dynamics.stp_induction_50hz to know which pairs have stp dynamics at all frequencies?
- I donât know how to ask for the recovery_delay. I know that I need a recording object, but I donât know how to do it inside my loop.
Could you help me please?