Пример #1
0
def first_pass_organizing_files(qc_path):

    import os
    from CPAC.qc.utils import append_to_files_in_dict_way

    qc_files = os.listdir(qc_path)
    strat_dict = {}

    for file_ in sorted(qc_files, reverse=True):

        if not ('.txt' in file_):
            continue

        file_ = os.path.join(qc_path, file_)
        str_ = os.path.basename(file_)

        str_ = str_.replace('paths_file_', '')

        str_ = str_.replace('scan_', '')

#        str_ = str_.replace('_', '')
        str_ = str_.replace('.txt', '')


        str_ = str_.replace('____', '_')
        str_ = str_.replace('___', '_')
        str_ = str_.replace('__', '_')

        if '_hp_' in str_ and '_fwhm_' in str_ and not ('_bandpass_freqs_' in str_):

            str_, fwhm_val = str_.split('_fwhm_')

            fwhm_val = '_fwhm_' + fwhm_val

            str_, hp_lp_ = str_.split('_hp_')
            hp_lp_ = '_hp_'  + hp_lp_

            str_ = str_ + fwhm_val + hp_lp_

        if strat_dict.keys() == []:

            strat_dict[str_] = [file_]

        else:

            flag_ = 0
            for key_ in strat_dict.keys():

                if str_ in key_:
                    append_to_files_in_dict_way(strat_dict[key_], file_)
                    flag_ = 1

            if flag_ == 1:

                os.system('rm -f %s' % file_)

            else:

                strat_dict[str_] = [file_]
Пример #2
0
def first_pass_organizing_files(qc_path):

    import os
    from CPAC.qc.utils import append_to_files_in_dict_way

    qc_files = os.listdir(qc_path)
    strat_dict = {}

    for file_ in sorted(qc_files, reverse=True):

        if not ('.txt' in file_):
            continue

        file_ = os.path.join(qc_path, file_)
        str_ = os.path.basename(file_)

        str_ = str_.replace('paths_file_', '')

        str_ = str_.replace('scan_', '')

        #        str_ = str_.replace('_', '')
        str_ = str_.replace('.txt', '')

        str_ = str_.replace('____', '_')
        str_ = str_.replace('___', '_')
        str_ = str_.replace('__', '_')

        if '_hp_' in str_ and '_fwhm_' in str_ and not ('_bandpass_freqs_'
                                                        in str_):

            str_, fwhm_val = str_.split('_fwhm_')

            fwhm_val = '_fwhm_' + fwhm_val

            str_, hp_lp_ = str_.split('_hp_')
            hp_lp_ = '_hp_' + hp_lp_

            str_ = str_ + fwhm_val + hp_lp_

        if strat_dict.keys() == []:

            strat_dict[str_] = [file_]

        else:

            flag_ = 0
            for key_ in strat_dict.keys():

                if str_ in key_:
                    append_to_files_in_dict_way(strat_dict[key_], file_)
                    flag_ = 1

            if flag_ == 1:

                os.system('rm -f %s' % file_)

            else:

                strat_dict[str_] = [file_]
Пример #3
0
def second_pass_organizing_files(qc_path):

    from CPAC.qc.utils import append_to_files_in_dict_way

    qc_files = os.listdir(qc_path)

    strat_dict = {}

    for file_ in sorted(qc_files, reverse=True):

        if not ('.txt' in file_):
            continue
        str_ = file_
        file_ = os.path.join(qc_path, file_)

        str_ = str_.replace('paths_file_', '')
        str_ = str_.replace('scan_', '')
        str_ = str_.replace('.txt', '')
        str_ = str_.replace('____', '_')
        str_ = str_.replace('___', '_')
        str_ = str_.replace('__', '_')
        fwhm_val_ = ''

        #organize all derivatives excluding alff falff
        if '_bandpass_freqs_' in str_:

            if not str_ in strat_dict:
                strat_dict[str_] = [file_]
            else:
                print 'Error: duplicate keys for files in QC 2nd file_org pass: %s %s' % (strat_dict[str_], file_)
                raise

        #organize alff falff
        elif ('_hp_' in str_) and ('_lp_' in str_):


            key_ = ''
            key_1 = ''
            hp_lp_ = ''
            if '_fwhm_' in str_:
                key_1 = ''
                key_, hp_lp_ = str_.split('_hp_')
                ignore, fwhm_val_ = hp_lp_.split('_fwhm_')
                hp_lp_ = '_hp_' + ignore
                key_1 = '_fwhm_' + fwhm_val_
            else:
                key_, hp_lp_ = str_.split('_hp_')
                hp_lp_ = '_hp_' + hp_lp_


            flag_ = 0
            for key in strat_dict.keys():

                if (key_ in key) and (key_1 in key):

                    append_to_files_in_dict_way(strat_dict[key], file_)
                    str_ = strat_dict[key][0].replace('.txt', '')
                    new_fname = str_ + hp_lp_ + '.txt'

                    os.system('mv %s %s' %(strat_dict[key][0], new_fname))
                    del strat_dict[key]
                    flag_ = 1


                if flag_ == 1:
                    os.system('rm -f %s' % file_)

        else:
            if not str_ in strat_dict:
                strat_dict[str_] = [file_]
            else:
                print 'Error: duplicate keys for files in QC 2nd file_org pass: %s %s' % (strat_dict[str_], file_)
                raise
Пример #4
0
def second_pass_organizing_files(qc_path):

    from CPAC.qc.utils import append_to_files_in_dict_way

    qc_files = os.listdir(qc_path)

    strat_dict = {}

    for file_ in sorted(qc_files, reverse=True):

        if not ('.txt' in file_):
            continue
        str_ = file_
        file_ = os.path.join(qc_path, file_)

        str_ = str_.replace('paths_file_', '')
        str_ = str_.replace('scan_', '')
        str_ = str_.replace('.txt', '')
        str_ = str_.replace('____', '_')
        str_ = str_.replace('___', '_')
        str_ = str_.replace('__', '_')
        fwhm_val_ = ''

        #organize all derivatives excluding alff falff
        if '_bandpass_freqs_' in str_:

            if not str_ in strat_dict:
                strat_dict[str_] = [file_]
            else:
                print 'Error: duplicate keys for files in QC 2nd file_org pass: %s %s' % (
                    strat_dict[str_], file_)
                raise

        #organize alff falff
        elif ('_hp_' in str_) and ('_lp_' in str_):

            key_ = ''
            key_1 = ''
            hp_lp_ = ''
            if '_fwhm_' in str_:
                key_1 = ''
                key_, hp_lp_ = str_.split('_hp_')
                ignore, fwhm_val_ = hp_lp_.split('_fwhm_')
                hp_lp_ = '_hp_' + ignore
                key_1 = '_fwhm_' + fwhm_val_
            else:
                key_, hp_lp_ = str_.split('_hp_')
                hp_lp_ = '_hp_' + hp_lp_

            flag_ = 0
            for key in strat_dict.keys():

                if (key_ in key) and (key_1 in key):

                    append_to_files_in_dict_way(strat_dict[key], file_)
                    str_ = strat_dict[key][0].replace('.txt', '')
                    new_fname = str_ + hp_lp_ + '.txt'

                    os.system('mv %s %s' % (strat_dict[key][0], new_fname))
                    del strat_dict[key]
                    flag_ = 1

                if flag_ == 1:
                    os.system('rm -f %s' % file_)

        else:
            if not str_ in strat_dict:
                strat_dict[str_] = [file_]
            else:
                print 'Error: duplicate keys for files in QC 2nd file_org pass: %s %s' % (
                    strat_dict[str_], file_)
                raise