Exemplo n.º 1
0
    os.mkdir(func_dir)
    for exam in exams:
        exam_dir = os.path.join(source, exam)
        for rt, dirs, files in os.walk(exam_dir):
            for d in dirs:
                for str in ["spgr", "SPGR", '_166_', '_160_', '_164', 'f166']:
                    if str in d or str in root:
                        src_dir = os.path.join(rt, d)
                        dest_dir = os.path.join(anat_dir, d)
                        shutil.copytree(src_dir, dest_dir)
                        path_list = uf.splitall(src_dir)
                        ind = path_list.find('SocCog_Raw_Data_By_Exam_Number')
                        exam = path_list(ind + 1)
                        ex_dir = path_list(ind + 2)
                        with open(os.path.join(dest_dir, exam + 'txt')) as recfile:
                            recfile.write(''.join([exam, '\n', ex_dir]))
                        with open('/media/katie/SocCog/working_data/copyrec1.txt', 'a+') as copyrec:
                            copyrec.write(''.join(["d", d, '\n', "src", src_dir, '\n', "dest", dest_dir]))
                for str in ['M', 'L', '_1904', '_1960', '_5610', 'f5610', 'f1903', '_1848', '_5455', '_4522', '_2234', '_3374'\
                    '_5236', '_442', '_2550', '_6528', '_3094']:
                    if str in d:
                        src_dir = os.path.join(rt, d)
                        dest_dir = os.path.join(func_dir, d)
                        shutil.copytree(src_dir, dest_dir)
                        with open(os.path.join(root, 'copyrec1.txt', 'a+')) as copyrec:
                            copyrec.write(''.join(["d", d, '\n', "src", src_dir, '\n', "dest", dest_dir]))

uf.done(root, "getRawfromExamDir.py, program to retrieve files from raw exam directories, has finished")


Exemplo n.º 2
0
#                    done = True


        ###RENAME IMG###


        ###MOVE IMG####

    with open(os.path.join(scripts_dir, q_string), 'w+') as q:
        q.write("""
#!/bin/bash
#$ -S /bin/bash
#$ -l mem=4G,time=24:00:00
#$ -cwd
""")
        q.write('#$ -N j' + ser_id + '\n#$ -j y\n#$ -o ' + ser_id + '.txt\n')
        q.write('''\
echo "Starting on : $(date)"
echo "Running on node : $(hostname)"
echo "Current directory : $(pwd)"
echo "Current job ID : $JOB_ID"
echo "Current job name : $JOB_NAME"
#The following is the job to be performed:
''')
        q.write("python " + p_path)

uf.done(os.path.join(dst_root, 'done.txt'), "SocCogMasterSort.py, program to sort has completed")



Exemplo n.º 3
0
__author__ = 'katie'

root = '/media/truecrypt2/sample/7436test'
import os, uf

for rt, dirs, files in os.walk(root):
    for f in files:
        if (f[-3:] == 'img' or f[-3:] == 'hdr') and ('L' in f or 'M' in f):
            old = os.path.join(rt, f)
            newname = 'f' + f[-10:]
            new = os.path.join(rt, newname)
            os.rename(old, new)
            print old
            print new
            print ' '
        if (f[-3:] == 'img' or f[-3:] == 'hdr') and ('anat' in f and f[0] == 's'):
            old = os.path.join(rt, f)
            newname = 's' + f[-10:]
            new = os.path.join(rt, newname)
            os.rename(old, new)
            print old
            print new
            print ' '

uf.done('/media/truecrypt2/sample/7436new/done.txt')

        if (f[-3:] == 'img' or f[-3:] == 'hdr') and ('anat' in dst_path):
            newname = 's' + f[-13:-7] + f[-4:]
            new = os.path.join(dst_path, newname)
            os.rename(old, new)
    files = [f for f in os.listdir(dst_path) if len(f) <= 12]
    logline['Renamed'] = 'Renamed_' + str(len(files)) + '_files_' + os.path.join(dst_path, files[0])

    ###MOVE IMG####

    ult_path = uf.buildtree(ult_root, dst_path_lst)
    for f in os.listdir(dst_path):
        if (f[-3:] == 'img' or f[-3:] == 'hdr'):
            old = os.path.join(dst_path, f)
            new = os.path.join(ult_path, f)
            print old
            print new
            print ' '
            os.rename(old, new)
    files = [f for f in os.listdir(ult_path)]
    logline['Moved'] = 'Moved_' + str(len(files)) + '_files_' + os.path.join(ult_path, files[0])

    #del(logline[''])
    with open(logfile,'a+') as log:
        dw = csv.DictWriter(log, delimiter='\t', fieldnames=ordered_fieldnames)
        dw.writerow(logline)

uf.done(os.path.join(dst_root, 'done.txt'), "ks_mastersort_no_clust.py, program to sort has completed")



    os.mkdir(func_dir)
    for exam in exams:
        exam_dir = os.path.join(source, exam)
        for rt, dirs, files in os.walk(exam_dir):
            for d in dirs:
                for str in ["spgr", "SPGR", '_166_', '_160_', '_164', 'f166']:
                    if str in d or str in root:
                        src_dir = os.path.join(rt, d)
                        dest_dir = os.path.join(anat_dir, d)
                        shutil.copytree(src_dir, dest_dir)
                        path_list = uf.splitall(src_dir)
                        ind = path_list.find('SocCog_Raw_Data_By_Exam_Number')
                        exam = path_list(ind + 1)
                        ex_dir = path_list(ind + 2)
                        with open(os.path.join(dest_dir, exam + 'txt')) as recfile:
                            recfile.write(''.join([exam, '\n', ex_dir]))
                        with open('/media/katie/SocCog/working_data/copyrec1.txt', 'a+') as copyrec:
                            copyrec.write(''.join(["d", d, '\n', "src", src_dir, '\n', "dest", dest_dir]))
                for str in ['M', 'L', '_1904', '_1960', '_5610', 'f5610', 'f1903', '_1848', '_5455', '_4522', '_2234', '_3374'\
                    '_5236', '_442', '_2550', '_6528', '_3094']:
                    if str in d:
                        src_dir = os.path.join(rt, d)
                        dest_dir = os.path.join(func_dir, d)
                        shutil.copytree(src_dir, dest_dir)
                        with open(os.path.join(root, 'copyrec1.txt', 'a+')) as copyrec:
                            copyrec.write(''.join(["d", d, '\n', "src", src_dir, '\n', "dest", dest_dir]))

uf.done(root, "SocCogMasterSort.py, program to sort ")