def main_wrap():
    """Wrap function call in main."""
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'tcat_tcorrelate'))
    logfile.info('Started 18.tcat_tcorrelate_z_transform.py')

    subj_list = ['VREA']

    __, clip, __ = tc.get_timings(logfile)
    segments = set(c.split('_')[0] for c in clip)

    for subject in subj_list:
        os.chdir(os.path.join(os.environ['decor'], subject, '6mmblur_results'))
        for m in ['AV', 'A', 'V', 'lowlev']:
            get_condition_mean(logfile, segments, m, subject,
                               '6mmblur_tcorr_out_spearman')
            tr.setnames_call_funcs(logfile, subject, m,
                                   '6mmblur_tcorr_out_spearman_v2')
        for funcseg in ['abouthalf', 'twothirds']:
            segments = set(c.split('_')[0] for c in clip)
            sub_segments = tc.subsettter(segments, funcseg)
            for m in ['AV', 'A', 'V', 'lowlev']:
                get_condition_mean(logfile, sub_segments, m, subject,
                                   '6mmblur_tcorr_out_spearman_%s' % funcseg)
                tr.setnames_call_funcs(logfile, subject, m,
                                       '6mmblur_tcorr_out_spearman_%s_v2' %
                                       funcseg)
Esempio n. 2
0
def main():
    """Execute afni_anova."""
    subjectlist = [s for s in range(1, 20)]
    subjectlist.remove(3)
    subjectlist.remove(11)

    workdir = os.path.join(os.environ['avp'], 'nii/group_effects_trad')
    logfile = setup_log(os.path.join(workdir, 'do_anova_grouptrad'))
    logfile.info('Doing main call')
    outname = os.path.join(workdir, 'anova2_grouptrad')
    afni_anova(logfile, subjectlist, outname)
Esempio n. 3
0
def main():
    """Wrap the methods to do both main call."""
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'transform_corr'))
    logfile.info('Started 9.transform_corr.py')

    subj_list = ['RSDE', 'VREA']
    for subject in subj_list:
        os.chdir(os.path.join(os.environ['decor'], subject, '6mmblur_results'))
        for m in ['AV', 'A', 'V', 'lowlev']:
            tcorr_suf = '6mmblur_tcorr_out_spearman'
            setnames_call_funcs(logfile, subject, m, tcorr_suf)
Esempio n. 4
0
def main(subjectlist, anatlist):
    """Wrap methods in main call."""
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                        'fsl_anat'))
    logfile.info('started 4.fsl_anat.py')
    for subject in subjectlist:
        os.chdir(os.path.join(os.environ['decor'], subject))
        for mprage in anatlist:
            anat = '{}.{}.gert_reco'.format(subject, mprage)
            fsla = FslAnat(anat)
            fsla.afni_to_nifti(logfile)
            fsla.fslanat(logfile)
def main():
    """Set names to call vol2surf_mni."""
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'project_to_surf'))
    os.chdir(os.path.join(os.environ['decor'], 'randomise_repmeas'))
    pndiff = '1.0'
    # No clusters survive tstat4 so do only the first 3
    for i in range(1, 4):
        for h in ['lh', 'rh']:
            parnt = os.path.join(os.environ['decor'], 'randomise_repmeas',
                                 '%s_clustere_corrp_tstat%d_thr005fwe05' %
                                 ('repmeas_randomise_out_n5000', i))
            vol_to_surf_mni(logfile, h, '%s.nii.gz' % parnt, pndiff,
                            '%s_%s_pn%s_MNI_N27.1D' % (parnt, h, pndiff))
Esempio n. 6
0
def main():
    """Wrap funciton calls to main."""
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'anova'))
    logfile.info('Started 17.anova.py')

    conditions_list = ['AV', 'A', 'V', 'lowlev']
    subjects_list = ['NNPT', 'SSGO', 'LSRS', 'SEKI',
                     'LNSE', 'JNWL', 'PMBI', 'LNDR',
                     'GOPR', 'DAHL', 'RSDE', 'VREA']

    anova_afni(logfile, subjects_list, conditions_list)
    for seg in ['twothirds', 'abouthalf']:
        anova_afni(logfile, subjects_list, conditions_list, seg)
Esempio n. 7
0
def main():
    """Call methods to get randomise."""
    randomise_dir = os.path.join(os.environ['decor'], 'randomise_repmeas')
    conditions = ['AV', 'A', 'V', 'lowlev']
    subjects = ['NNPT', 'SSGO', 'LSRS', 'SEKI',
                'LNSE', 'JNWL', 'PMBI', 'LNDR',
                'GOPR', 'DAHL', 'RSDE', 'VREA']
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'do_randomise'))
    setup_randomise(logfile, randomise_dir, subjects, conditions)
    os.chdir(randomise_dir)
    logfile.info('Now in working directory: %s', os.getcwd())
    nreps = 5000
    fsl_randomise(logfile, nreps,
                  os.path.join(randomise_dir, 'repmeas_4Dfile'),
                  os.path.join(randomise_dir,
                               'repmeas_randomise_out_main2tailp005_n%d' % nreps))
def main():
    """Do methods above via this wrapper."""
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'tcat_tcorrelate'))
    logfile.info('Started 8.tcat_tcorrelate.py')

    subj_list = ['RSDE', 'VREA']

    # Below is for full time series.
    __, clip, __ = get_timings(logfile)
    segments = set(c.split('_')[0] for c in clip)
    tcorr_suf = '6mmblur_tcorr_out_spearman'
    for subject in subj_list:
        tcorr_main(logfile, subject, segments, tcorr_suf)

    # Below is for subset of time series.
    # When run either 'twothirds' or 'abouthalf'.
    """
def main():
    """Wrap funciton call."""
    randomise_dir = os.path.join(os.environ['decor'], 'randomise_repmeas')
    conditions = ['AV', 'A', 'V', 'lowlev']
    subjects = ['NNPT', 'SSGO', 'LSRS', 'SEKI',
                'LNSE', 'JNWL', 'PMBI', 'LNDR',
                'GOPR', 'DAHL', 'RSDE', 'VREA']
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'indivcond_randomise'))
    nreps = 10
    os.chdir(randomise_dir)
    logfile.info('Now in working directory: %s', os.getcwd())
    make_condition_file(logfile, randomise_dir, conditions, subjects)
    for cond in conditions:
        indiv_t_randomise(logfile, nreps,
                          os.path.join(randomise_dir, '%s_4Dfile' % cond),
                          os.path.join(randomise_dir,
                                       '%s_out_2tailp005_n%d' % (cond, nreps)))
Esempio n. 10
0
def main():
    """Wrap funciton calls to main."""
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'epi_reg'))
    logfile.info('Started 10.epi_reg.py')

    subj_list = ['NNPT']
    for subject in subj_list:
        basedir = os.path.join(os.environ['decor'], subject)
        os.chdir(os.path.join(basedir, '6mmblur_results'))
        print os.getcwd()
        outpref = 'epi2anat_%s_sess1_6mmblur_meanepi_mprage2' % subject
#         converttoNIFTI(logfile, '%s_sess1_6mmblur_meanepi+orig' % subject)
#         epi_reg(logfile, '%s_sess1_6mmblur_meanepi.nii.gz' % subject,
#                 os.path.join(basedir, '%s.mprage2.gert_reco.anat' % subject,
#                              'T1_biascorr.nii.gz'),
#                 os.path.join(basedir, '%s.mprage2.gert_reco.anat' % subject,
#                              'T1_biascorr_brain.nii.gz'),
#                 outpref)

        for modal in ['AV', 'A', 'V', 'lowlev']:
            # below runs full time series segment
            out_flirt = 'highres_flirted_MNI2mm_%s_%s_6mmblur_v2__Z' % \
                        (subject, modal)
            apply_transforms(logfile, subject,
                             '%s_%s_6mmblur_tcorr_out_spearman_v2_mean_Z.nii.gz'
                             % (modal, subject),
                             out_flirt,
                             '%s.nii.gz' % out_flirt,
                             'highres_fnirted_MNI2mm_%s_%s_6mmblur_v2_Z'
                             % (subject, modal),
                             '%s.mat' % outpref)
            # below runs shorter time series segments
            for seg in ['twothirds', 'abouthalf']:
                out_flirt = 'highres_flirted_MNI2mm_%s_%s_%s_6mmblur_v2__Z' % \
                            (subject, modal, seg)
                apply_transforms(logfile, subject,
                                 '%s_%s_6mmblur_tcorr_out_spearman_%s_v2_mean_Z.nii.gz'
                                 % (modal, subject, seg),
                                 out_flirt,
                                 '%s.nii.gz' % out_flirt,
                                 'highres_fnirted_MNI2mm_%s_%s_%s_6mmblur_v2_Z'
                                 % (subject, modal, seg),
                                 '%s.mat' % outpref)
def main():
    """Wrap method to execute in main.

    high/high - mean(high/low, low/high)
    mean(high/low, low/high) - low/low
    """
    subj_list = [s for s in range(1, 20)]
    subj_list.remove(3)
    subj_list.remove(11)

    logfile = setup_log(os.path.join(os.environ['avp'], 'logs',
                                     'do_regularity_gradient_grptest'))
    logfile.info('Doing regularity_gradient_grptest.')
    logfile.info('Doing 3dMEMA.')
    for lvl in ['high', 'low']:
        mema_out = os.path.join(os.environ['avp'], 'nii',
                                'regularity_gradient',
                                '{}_grad_flt2_msk_mema'.format(lvl))
        mema(logfile, lvl, subj_list, mema_out)
Esempio n. 12
0
def main():
    """Wrap all the methods to execute."""
    subject_list = ['RSDE', 'VREA']
    subjectstim_dict = build_subject_dict(subject_list)
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                        'align_epis'))
    logfile.info('started 5.align_epis.py')

    for subject in subject_list:
        resultsdir = os.path.join(os.environ['decor'], subject,
                                  '6mmblur_results')
        dir_check(resultsdir)
        os.chdir(resultsdir)
        print(os.getcwd())
        do_avg_mean_epis(logfile, subjectstim_dict, subject)
        align_epis(logfile, subject)
        for run in subjectstim_dict[subject]['sess2']:
            allineate(logfile, subject, run)

        for run in subjectstim_dict[subject]['sess1']:
            copyn(logfile, subject, run)
def main():
    """Call methods for thresholding and clustering."""
    lname = 'thresh_cluster_twocond_contr_conj'
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs', lname))
    logfile.info('Do threshold and cluster.')
    os.chdir(os.path.join(os.environ['decor'], 'randomise_twocond_contr_conj'))

    pref = 'out_1tailp001_n5000'
    for ctype in ['clustere', 'clusterm', 'tfce']:
        for pref in ['AVvA_randomise_out_n5000_p005',
                     'AVvV_randomise_out_n5000_p005']:
            for i in range(1, 3):
                fsl_maths(logfile,
                          '{}_{}_corrp_tstat{}'.format(pref, ctype, i),
                          '{}_tstat{}.nii.gz'.format(pref, i),
                          '{}_{}_corrp_tstat{}_fwe05'.format(pref, ctype, i))
                cluster(logfile,
                        '{}_{}_corrp_tstat{}_fwe05.nii.gz'.format(pref, ctype, i),
                        '{}_{}_corrp_tstat{}_fwe05_cluster_index'.format(pref, ctype, i),
                        '{}_{}_corrp_tstat{}_fwe05lmax.txt'.format(pref, ctype, i),
                        '{}_{}_corrp_tstat{}_fwe05omean'.format(pref, ctype, i),
                        '{}_{}_corrp_tstat{}_fwe05cluster_size'.format(pref, ctype, i))
def main():
    """Call methods to get randomise."""
    randomise_dir = os.path.join(os.environ['decor'],
                                 'randomise_twocond_contr_conj')
    subjects = ['NNPT', 'SSGO', 'LSRS', 'SEKI',
                'LNSE', 'JNWL', 'PMBI', 'LNDR',
                'GOPR', 'DAHL', 'RSDE', 'VREA']
    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                                     'do_randomise_twocond_contr_conj'))
    os.chdir(randomise_dir)
    nreps = 5000

    mergefsl(logfile, make_file_list(subjects, ['AV', 'A']), 'AVvA_4Dfile')
    fsl_randomise(logfile, nreps,
                  os.path.join(randomise_dir, 'AVvA_4Dfile'),
                  os.path.join(randomise_dir,
                               'AVvA_randomise_out_n%d_p005' % nreps))

    mergefsl(logfile, make_file_list(subjects, ['AV', 'V']), 'AVvV_4Dfile')
    fsl_randomise(logfile, nreps,
                  os.path.join(randomise_dir, 'AVvV_4Dfile'),
                  os.path.join(randomise_dir,
                               'AVvV_randomise_out_n%d_p005' % nreps))
Esempio n. 15
0
from pdfminer.pdfpage import PDFPage

from lib.parse_helpers import parse_timecard_line_v2, timecard2dict, date_find
from lib.parse_helpers import weekly_mapping
from lib.parse_helpers import reform_produce
from lib.parse_helpers import handle_buffer_entries

from lib.regex_helper import filter_junk, clean_line_intake

from lib.settings import key_page
from lib.settings import last_timecard
#read?
import lib.settings

from setlog import setup_log
logger = setup_log()


def extract_text_from_pdf(pdf_path):

    resource_manager = PDFResourceManager()
    fake_file_handle = io.StringIO()
    converter = TextConverter(resource_manager, fake_file_handle)
    page_interpreter = PDFPageInterpreter(resource_manager, converter)

    with open(pdf_path, 'rb') as fh:
        for page in PDFPage.get_pages(fh, caching=True,
                                      check_extractable=True):
            page_interpreter.process_page(page)
        text = fake_file_handle.getvalue()
Esempio n. 16
0
                        run, subj, subj, run))
    proc = Popen(cmdargs, stdout=PIPE, stderr=STDOUT)
    log.info(proc.stdout.read())


def splicer_localizer(subj, run):
    """Splice localizer series."""
    stdf = open('stdout_files/stdout_from_Tcat_{}.txt'.format(run), 'w')
    cmdargs = split('3dTcat -prefix {}.{}.TRIM \
                    raw.{}.{}.gert_reco+orig.BRIK[14-405]'.format(
                        run, subj, subj, run))
    Popen(cmdargs, stdout=stdf, stderr=STDOUT)
    stdf.close()


if __name__ == "__main__":

    SCRUNS = ['SC{}'.format(i) for i in range(1, 7)]
    AVRUNS = ['AV1.1', 'AV1.2', 'AV2.1', 'AV2.2', 'AV3.1', 'AV3.2']
    RUNIDS = SCRUNS + AVRUNS
    SUBJECTLIST = ['RSDE', 'VREA']

    logfile = setup_log(os.path.join(os.environ['decor'], 'logs/splicer'))
    logfile.info('started splicer.py')
    for ss in SUBJECTLIST:
        subjectdir = os.path.join(os.environ['decor'], ss)
        os.chdir(subjectdir)
        for rr in RUNIDS:
            splicer(logfile, ss, rr)
        splicer_rest(logfile, ss, 'Rest')
Esempio n. 17
0
    stimdict = {}
    for subj in subjectlist:
        seriesorder = pd.Series(df.loc[df.SSname == subj, 'stim_name'])
        subidx = list(seriesorder.iloc[[0, 6]])
        subjitem = {subj: {subidx[0]: list(seriesorder.iloc[:6]),
                           subidx[1]: list(seriesorder.iloc[6:]),
                           'Rest': ['Rest']}}
        stimdict.update(subjitem)

    return stimdict


if __name__ == '__main__':

    SUBJECTLIST = ['RSDE', 'VREA']
    STIMDICT = build_subject_dict(SUBJECTLIST)

    logfile = setup_log(os.path.join(os.environ['decor'], 'logs',
                        'afproc_withblur'))
    logfile.info('started 3.afproc_withblur.py')

    for subject in SUBJECTLIST:
        print('setting work dir: ')
        os.chdir(os.path.join(os.environ['decor'], subject))
        print(os.getcwd())
        for ref in STIMDICT[subject]:
            for runident in STIMDICT[subject][ref]:
                subjrun = '{}.{}.6mmblur'.format(subject, runident)
                afniproc(subject, runident, subjrun, ref)
                run_afniproc(logfile, subjrun)   # this is separate