Example #1
0
def make_lda_features_from_spks(SpkFileNames):
    "all files should have been generated by the same parameters"

    clu_means, clu_covs = [], []
    pars0 = n_ch, sample_rate, s_before, s_after = get_pars_from_xml2(
        switch_ext(SpkFileNames[0], "xml"))
    print "parameters: %s" % str(pars0[1:])

    for fname in SpkFileNames:
        pars = get_pars_from_xml2(switch_ext(fname, "xml"))
        if pars[1:] != pars0[1:]:
            print "%s has wrong parameters. skipping" % fname
            continue
        n_ch = pars[0]
        X_nsc = read_spk(fname, n_ch, s_after + s_before)
        Clu_n = read_clu(switch_ext(fname, "clu.1"))
        for i_ch in xrange(n_ch):
            Mean_ms, Cov_mss, Count_m = get_clu_params(Clu_n, X_nsc[:, :,
                                                                    i_ch])
            for mean, cov, count in zip(Mean_ms, Cov_mss, Count_m):
                if count > 100:
                    clu_means.append(mean)
                    clu_covs.append(cov)

    Feat_ss = compute_feats_lda(clu_means, clu_covs)
    save_feature_info(Feat_ss, s_before, s_after, sample_rate)
Example #2
0
def print_report_from_dirs(extra_dir, intra_dir):
    extra_clu_path = find_file_with_ext(extra_dir,
                                        '.clu.1',
                                        ex_if_not_found=True)
    extra_res_path = find_file_with_ext(extra_dir,
                                        '.res.1',
                                        ex_if_not_found=True)
    intra_res_path = find_file_with_ext(intra_dir,
                                        '.res.1',
                                        ex_if_not_found=True)

    xml_path = find_file_with_ext(extra_dir, '.xml')

    oprint(
        "Comparing extracellular units from res file %s, clu file %s to intracellular unit with time file %s"
        % tuple(
            map(os.path.basename,
                (extra_clu_path, extra_res_path, intra_res_path))))
    from xml.etree.ElementTree import ElementTree
    sample_rate = float(ElementTree().parse(xml_path).find(
        'acquisitionSystem').find('samplingRate').text)

    meas_clu_counts, isect_counts, n_undetected = match_real_to_meas(
        output.read_res(intra_res_path), output.read_res(extra_res_path),
        output.read_clu(extra_clu_path), sample_rate)
    print_report(meas_clu_counts, isect_counts, n_undetected,
                 len(output.read_res(intra_res_path)))
Example #3
0
def print_isect_table_from_dirs(sad_dir,happy_dir):
    rc_path = find_file_with_ext(sad_dir,'.clu.1',ex_if_not_found = True)
    rt_path = find_file_with_ext(sad_dir,'.res.1',ex_if_not_found = True)
    mc_path = find_file_with_ext(happy_dir,'.clu.1',ex_if_not_found = True)
    mt_path = find_file_with_ext(happy_dir,'.res.1',ex_if_not_found = True)        

    
    xml_path1 = find_file_with_ext(happy_dir,'.xml')
    xml_path2 = find_file_with_ext(sad_dir,'.xml')
    xml_path = xml_path1 if xml_path1 else xml_path2    
    
    
    oprint("Comparing cluster file %s with time file %s to cluster file %s with time file %s"
          %map(os.path.basename,(rc_path,rt_path,mc_path,mt_path)))
    from xml.etree.ElementTree import ElementTree
    sample_rate = float(ElementTree().parse(xml_path).find('acquisitionSystem').find('samplingRate').text)
    print_isect_table(output.read_res(rt_path),output.read_clu(rc_path),
                       output.read_res(mt_path),output.read_clu(mc_path),sample_rate)
Example #4
0
def print_isect_table_from_dirs(sad_dir, happy_dir):
    rc_path = find_file_with_ext(sad_dir, '.clu.1', ex_if_not_found=True)
    rt_path = find_file_with_ext(sad_dir, '.res.1', ex_if_not_found=True)
    mc_path = find_file_with_ext(happy_dir, '.clu.1', ex_if_not_found=True)
    mt_path = find_file_with_ext(happy_dir, '.res.1', ex_if_not_found=True)

    xml_path1 = find_file_with_ext(happy_dir, '.xml')
    xml_path2 = find_file_with_ext(sad_dir, '.xml')
    xml_path = xml_path1 if xml_path1 else xml_path2

    oprint(
        "Comparing cluster file %s with time file %s to cluster file %s with time file %s"
        % map(os.path.basename, (rc_path, rt_path, mc_path, mt_path)))
    from xml.etree.ElementTree import ElementTree
    sample_rate = float(ElementTree().parse(xml_path).find(
        'acquisitionSystem').find('samplingRate').text)
    print_isect_table(output.read_res(rt_path), output.read_clu(rc_path),
                      output.read_res(mt_path), output.read_clu(mc_path),
                      sample_rate)
Example #5
0
def klustakwik_cluster(Fet_nc3):
    kk_path = "KlustaKwik"
    tempdir = tempfile.mkdtemp()
    kk_input_filepath = join(tempdir,'k_input.fet.1')
    kk_output_filepath = join(tempdir,'k_input.clu.1')
    Fet_nf = Fet_nc3.reshape(len(Fet_nc3),-1)
    write_fet(Fet_nf,kk_input_filepath)
    n_fet = Fet_nf.shape[1]
    
    os.system( ' '.join([kk_path, kk_input_filepath[:-6], '1', '-UseFeatures', '1'*n_fet,'-MinClusters',str(MINCLUSTERS),'-MaxClusters',str(MAXCLUSTERS),'-Screen','0']) )
    return read_clu(kk_output_filepath)
Example #6
0
def klustakwik_cluster(Fet_nc3, clusterdir):
    kk_path = "KlustaKwik"
    if not (os.path.exists(clusterdir)):
        os.makedirs(clusterdir)
    kk_input_filepath = join(clusterdir,'k_input.fet.1')
    kk_output_filepath = join(clusterdir,'k_input.clu.1')
    Fet_nf = Fet_nc3.reshape(len(Fet_nc3),-1)
    write_fet(Fet_nf,kk_input_filepath)
    n_fet = Fet_nf.shape[1]
    
    os.system( ' '.join([kk_path, kk_input_filepath[:-6], '1', '-UseFeatures', '1'*n_fet,'-MinClusters',str(MINCLUSTERS),'-MaxClusters',str(MAXCLUSTERS),'-Screen','0']) )
    return read_clu(kk_output_filepath)
Example #7
0
def klustakwik_cluster(Fet_nc3):
    kk_path = "KlustaKwik"
    tempdir = tempfile.mkdtemp()
    kk_input_filepath = join(tempdir, 'k_input.fet.1')
    kk_output_filepath = join(tempdir, 'k_input.clu.1')
    Fet_nf = Fet_nc3.reshape(len(Fet_nc3), -1)
    write_fet(Fet_nf, kk_input_filepath)
    n_fet = Fet_nf.shape[1]

    os.system(' '.join([
        kk_path, kk_input_filepath[:-6], '1', '-UseFeatures', '1' * n_fet,
        '-MinClusters',
        str(MINCLUSTERS), '-MaxClusters',
        str(MAXCLUSTERS), '-Screen', '0'
    ]))
    return read_clu(kk_output_filepath)
Example #8
0
def print_report_from_dirs(extra_dir,intra_dir):
    extra_clu_path = find_file_with_ext(extra_dir,'.clu.1',ex_if_not_found = True)
    extra_res_path = find_file_with_ext(extra_dir,'.res.1',ex_if_not_found = True)
    intra_res_path = find_file_with_ext(intra_dir,'.res.1',ex_if_not_found = True)        

    
    xml_path = find_file_with_ext(extra_dir,'.xml')
    
    
    oprint("Comparing extracellular units from res file %s, clu file %s to intracellular unit with time file %s"
          %tuple(map(os.path.basename,(extra_clu_path,extra_res_path,intra_res_path))))
    from xml.etree.ElementTree import ElementTree
    sample_rate = float(ElementTree().parse(xml_path).find('acquisitionSystem').find('samplingRate').text)
    
    meas_clu_counts,isect_counts,n_undetected = match_real_to_meas(output.read_res(intra_res_path),output.read_res(extra_res_path),
                                                                   output.read_clu(extra_clu_path),sample_rate)
    print_report(meas_clu_counts,isect_counts,n_undetected,len(output.read_res(intra_res_path)))
Example #9
0
def make_lda_features_from_spks(SpkFileNames):
    "all files should have been generated by the same parameters"

    clu_means, clu_covs = [],[]
    pars0 = n_ch,sample_rate,s_before,s_after = get_pars_from_xml2(switch_ext(SpkFileNames[0],"xml"))
    print "parameters: %s"%str(pars0[1:])
    
    for fname in SpkFileNames:
        pars = get_pars_from_xml2(switch_ext(fname,"xml"))
        if pars[1:] != pars0[1:]:
            print "%s has wrong parameters. skipping"%fname
            continue
        n_ch = pars[0]
        X_nsc = read_spk(fname,n_ch,s_after+s_before)
        Clu_n = read_clu(switch_ext(fname,"clu.1"))
        for i_ch in xrange(n_ch):
            Mean_ms, Cov_mss, Count_m = get_clu_params(Clu_n,X_nsc[:,:,i_ch])
            for mean,cov,count in zip(Mean_ms, Cov_mss, Count_m):
                if count > 100: 
                    clu_means.append(mean)
                    clu_covs.append(cov)
    
    Feat_ss = compute_feats_lda(clu_means,clu_covs)
    save_feature_info(Feat_ss,s_before,s_after,sample_rate)