def write_pajek_hvcRA_coord(dirname, trial_number): """ Create .net file with locations of HVC-RA neurons in array. Mature neurons are highlighted """ file_RA_xy = os.path.join(dirname, "RA_xy_" + str(trial_number) + ".bin") file_training = os.path.join(dirname, "training_neurons.bin") file_pajek = os.path.join(dirname, "network_" + str(trial_number) + ".net") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") coord_RA = reading.read_coordinates(file_RA_xy) training_neurons = reading.read_training_neurons(file_training) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) mature_neurons = np.where(mature_indicators == 1)[0] num_neurons = coord_RA.shape[0] # sort array with neurons and training neurons # training_neurons.sort() mature_neurons.sort() with open(file_pajek, 'w') as f: f.write("*Vertices {0}\n".format(num_neurons)) for i in range(num_neurons): if i in training_neurons: f.write('{0} "{1}" {2} {3} {4} ic Green\n'.format( i + 1, i, coord_RA[i][0], coord_RA[i][1], coord_RA[i][2])) elif i in mature_neurons: f.write('{0} "{1}" {2} {3} {4} ic Black\n'.format( i + 1, i, coord_RA[i][0], coord_RA[i][1], coord_RA[i][2])) else: f.write('{0} "{1}" {2} {3} {4} ic Yellow\n'.format( i + 1, i, coord_RA[i][0], coord_RA[i][1], coord_RA[i][2]))
def estimate_oscillations(filenameTrial, filenameMature): """ Estimate oscillation prominence for mature neurons in trial """ (_, _, mature_indicators) = reading.read_mature_indicators(filenameMature) mature_neurons = np.where(mature_indicators == 1)[0] # plot somatic spikes and burst density for a single trial mature_neurons_set = set(mature_neurons) spike_times_s, neuron_id_s, ordered_spikes_s, neuron_ordered_id_s = utils.getSpikes( os.path.join(testDir, filenameTrial)) ordered_spikes_s_mature = [] neuron_ordered_id_s_mature = [] for spikes, neuron_id in zip(spike_times_s, neuron_id_s): if neuron_id[0] in mature_neurons_set: ordered_spikes_s_mature.append(spikes) neuron_ordered_id_s_mature.append(neuron_id) ordered_spikes_s_mature = sorted(ordered_spikes_s_mature) smallest_spike_time = ordered_spikes_s_mature[0][0] for spikes in ordered_spikes_s_mature: for i in range(len(spikes)): spikes[i] -= smallest_spike_time first_spikes_s = [s[0] for s in ordered_spikes_s_mature] time, burst_density = utils.calculate_burst_density_hist( first_spikes_s, BIN_WIDTH, -10.0, 600.0) f = plt.figure() plt.suptitle('Single trial') ax = f.add_subplot(111) ax.plot(time, burst_density) ax.set_ylabel('Burst density (1/ms)') ax.set_xlabel('Time (ms)') ax.set_xlim([0, 250]) ax.set_ylim([0, 11]) first_nonzero = np.where(burst_density > 0)[0][0] last_nonzero = np.where(burst_density > 0)[0][-1] mean_bd = np.mean(burst_density[first_nonzero:last_nonzero]) std_bd = np.std(burst_density[first_nonzero:last_nonzero]) print "Interval for non-zero burst density: ", time[first_nonzero], time[ last_nonzero] print "Mean burst density: ", mean_bd print "Std burst density: ", std_bd print "Std / mean: ", std_bd / mean_bd return std_bd / mean_bd
def write_pajek_neurons(dirname, trial_number): """ Create .net file with locations and connections between mature HVC-RA neurons in array """ file_RA_xy = os.path.join(dirname, "RA_xy_" + str(trial_number) + ".bin") file_training = os.path.join(dirname, "training_neurons.bin") file_pajek = os.path.join(dirname, "network_" + str(trial_number) + ".net") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") fileSuperSynapses = os.path.join( dirname, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileWeights = os.path.join(dirname, "weights_" + str(trial_number) + ".bin") coord_RA = reading.read_coordinates(file_RA_xy) training_neurons = reading.read_training_neurons(file_training) (N_RA, _, weights) = reading.read_weights(fileWeights) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) (_, _, super_synapses) = reading.read_synapses(fileSuperSynapses) mature_neurons = np.where(mature_indicators == 1)[0] #print list(mature_neurons) #mature_neurons = range(N_RA) num_neurons = len(mature_neurons) # sort array with neurons and training neurons # training_neurons.sort() mature_neurons.sort() with open(file_pajek, 'w') as f: f.write("*Vertices {0}\n".format(num_neurons)) for i, neuron_id in enumerate(mature_neurons): if neuron_id in training_neurons: f.write('{0} "{1}" {2} {3} {4} ic Green\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) else: f.write('{0} "{1}" {2} {3} {4} ic Yellow\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) f.write("*Arcs\n".format(num_neurons)) # write targets of HVC(RA) neurons for i, source_id in enumerate(mature_neurons): for target_id in super_synapses[source_id]: try: ind = utils.index(mature_neurons, target_id) f.write('{0} {1} {2} c Green\n'.format( i + 1, ind + 1, weights[source_id][target_id])) except ValueError: continue
def get_maturation_time_sequence(dirname, end_trial, trialStep, neurons): """ Outputs excitatory conductance input from source_neurons to target_neuron at different points during simulation """ num_timepoints = end_trial / trialStep + 1 maturation_indicators = np.zeros((len(neurons), num_timepoints), np.float32) current_trial = 0 timepoint = 0 while current_trial <= end_trial: fileMature = os.path.join(dirname, "mature_" + str(current_trial) + ".bin") (_, _, mat_indicators) = reading.read_mature_indicators(fileMature) for i, neuron_id in enumerate(neurons): maturation_indicators[i][timepoint] = mat_indicators[neuron_id] timepoint += 1 current_trial += trialStep return maturation_indicators
all_first_spikes_in_burst = [ s - min_first_spike for s in all_first_spikes_in_burst ] #ordered_dend_spikes = [d - min_dend_spike_time for d in ordered_dend_spikes] time, burst_density = utils.calculate_burst_density( sorted(all_first_spikes_in_burst), BIN_WIDTH) #start_time = 0.0 #end_time = 120.0 ######################################################################### # calculate continuity for the burst pattern produced by mature neurons # ######################################################################### (_, _, mature_indicators) = reading.read_mature_indicators( os.path.join(dataDir, "mature_" + str(trial) + ".bin")) print "Number of mature HVC-RA: ", len(np.where(mature_indicators == 1)[0]) min_first_spike_mature = 1e6 max_first_spike_mature = -1e6 for id in np.where(mature_indicators == 1)[0]: for first_spike in first_spikes_in_bursts[id]: if first_spike < min_first_spike_mature: min_first_spike_mature = first_spike if first_spike > max_first_spike_mature: max_first_spike_mature = first_spike min_first_spike_mature -= min_first_spike max_first_spike_mature -= min_first_spike
import matplotlib.pyplot as plt import numpy as np TRAINING_KICK_TIME = 100.0 #filename = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/maturationTransition4/jitter.bin" #fileMature = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/maturationTransition4/mature_16500.bin" filename = "/mnt/hodgkin/eugene/results/immature/clusters/test/matTrans62/trial4200/jitter.bin" fileMature = "/mnt/hodgkin/eugene/results/immature/clusters/matTrans62/mature_4200.bin" N, num_test_trials, \ probability_soma_spike, average_num_soma_spikes_in_trial, mean_first_soma_spike_time, std_first_soma_spike_time,\ probability_dend_spike, average_num_dend_spikes_in_trial, mean_first_dend_spike_time, std_first_dend_spike_time = reading.read_jitter(filename) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) mature_neurons = np.where(mature_indicators == 1)[0] print mature_neurons print "Number of mature: ", len(mature_neurons) #mature_neurons = range(N) mean_first_soma_spike_time_mature = mean_first_soma_spike_time[mature_neurons] mean_first_dend_spike_time_mature = mean_first_dend_spike_time[mature_neurons] std_first_soma_spike_time_mature = std_first_soma_spike_time[mature_neurons] std_first_dend_spike_time_mature = std_first_dend_spike_time[mature_neurons] probability_soma_spike_mature = probability_soma_spike[mature_neurons] probability_dend_spike_mature = probability_dend_spike[mature_neurons] average_num_soma_spikes_in_trial_mature = average_num_soma_spikes_in_trial[ mature_neurons]
def write_pajek_network_subset(dirname, trial_number, N, fileSpikes): """ Create .net file with locations and connections between mature HVC-RA neurons in array first N mature neurons that spiked are plotted """ file_RA_xy = os.path.join(dirname, "RA_xy_" + str(trial_number) + ".bin") file_training = os.path.join(dirname, "training_neurons.bin") file_pajek = os.path.join(dirname, "network_subset_" + str(trial_number) + ".net") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") fileSuperSynapses = os.path.join( dirname, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileWeights = os.path.join(dirname, "weights_" + str(trial_number) + ".bin") coord_RA = reading.read_coordinates(file_RA_xy) training_neurons = reading.read_training_neurons(file_training) (N_RA, _, weights) = reading.read_weights(fileWeights) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) (_, _, super_synapses) = reading.read_synapses(fileSuperSynapses) #print list(mature_neurons) #mature_neurons = range(N_RA) # sort array with neurons and training neurons # training_neurons.sort() #fileDend = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/noImmatureOut4/test_spike_times_dend_5.bin" #fileSoma = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/noImmatureOut4/test_spike_times_soma_5.bin" (_, _, spike_times_soma, neuron_fired_soma) = reading.read_time_info(fileSpikes) ordered_soma_spikes_raw, ordered_soma_raw = zip( *sorted(zip(spike_times_soma, neuron_fired_soma))) first_mature_spiked = [] for spikes, neuron_ids in zip(ordered_soma_spikes_raw, ordered_soma_raw): if len(first_mature_spiked) >= N: break if mature_indicators[neuron_ids[0]] == 1: first_mature_spiked.append(neuron_ids[0]) first_mature_spiked.sort() num_neurons = len(first_mature_spiked) with open(file_pajek, 'w') as f: f.write("*Vertices {0}\n".format(num_neurons)) for i, neuron_id in enumerate(first_mature_spiked): if neuron_id in training_neurons: f.write('{0} "{1}" {2} {3} {4} ic Green\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) else: f.write('{0} "{1}" {2} {3} {4} ic Yellow\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) f.write("*Arcs\n".format(num_neurons)) # write targets of HVC(RA) neurons for i, source_id in enumerate(first_mature_spiked): for target_id in super_synapses[source_id]: try: ind = utils.index(first_mature_spiked, target_id) f.write('{0} {1} {2} c Green\n'.format( i + 1, ind + 1, weights[source_id][target_id])) except ValueError: continue
num_cols = 3 #dirname = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/maturationTransition4/" dirname = "/mnt/hodgkin/eugene/results/immature/clusters/matTrans62/" trial_number = 32400 fileCoordRA = os.path.join(dirname, "RA_xy_" + str(trial_number) + ".bin") fileTraining = os.path.join(dirname, "training_neurons.bin") #fileSoma = os.path.join(dirname, "spike_times_soma_" + str(trial_number) + ".bin") #fileSoma = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/noImmatureOut8/test_spike_times_soma_5.bin" fileSoma = "/mnt/hodgkin/eugene/results/immature/clusters/test/matTrans62/trial32400/test_spike_times_soma_5.bin" coord = reading.read_coordinates(fileCoordRA) training_neurons = reading.read_training_neurons(fileTraining) (_, _, mature_indicators) = reading.read_mature_indicators(os.path.join(dirname, "mature_"+str(trial_number)+".bin")) (_, _, spike_times_soma, neuron_fired_soma) = reading.read_time_info(fileSoma) print "Number of spiked neurons: ",len(spike_times_soma) for spikes, neuron_id in zip(spike_times_soma, neuron_fired_soma): if len(spikes) > 6: print "Neuron {0} produced {1} spikes".format(neuron_id[0], len(spikes)) #print "Dedritic spikes: ", neuron_fired_dend #print "Dendritic spike times: ", spike_times_dend #print "Somatic spikes: ", neuron_fired_soma #print "Somatic spike times: ", spike_times_soma