Пример #1
0
 def __init__(self,
              mainconfig,
              dataconfig,
              modal=None,
              database=False,
              data_source=None,
              force=False):
     """Init the exporter using mainconfig and dataconfig."""
     self.mainconfig = mainconfig
     self.dataconfig = dataconfig
     if mainconfig.get('atlas_list', None) is None or mainconfig.get(
             'atlas_list', None) == 'all':
         # use default atlas_list
         self.atlas_list = load_txt(
             os.path.join(rootconfig.path.atlas, 'atlas_list.txt'))
     elif type(mainconfig['atlas_list']) is list:
         self.atlas_list = mainconfig['atlas_list']
     else:
         self.atlas_list = load_txt(mainconfig['atlas_list'])
     if os.path.isfile(mainconfig['scan_list']):
         self.mriscans = load_txt(mainconfig['scan_list'])
     elif mainconfig['scan_list'] == 'listdir':
         if modal is not None:
             self.mriscans = sorted(
                 os.listdir(mainconfig['input_folders'][modal]))
         else:
             self.mriscans = sorted(
                 os.listdir(mainconfig['input_folders']['T1']))
     else:
         raise Exception('Unrecognized scan_list:', mainconfig['scan_list'])
     self.modal = modal
     self.database = database
     self.data_source = data_source
     self.force = force
Пример #2
0
def combine_txts(outtxt, intxts):
    outset = set()
    for intxt in intxts:
        outset.update(load_txt(intxt))
    outlist = list(outset)
    outlist.sort()
    save_txt(outtxt, outlist)
Пример #3
0
 def __init__(self, api, mriscanstxt, modal, outmainfolder):
     """Construct by api object, mriscanstxt contains mriscans by name_date,
     modal or file name, and download the data to outmainfolder.
     """
     self.api = api
     self.mriscans = load_txt(mriscanstxt)
     self.outmainfolder = outmainfolder
     self.modal = modal
Пример #4
0
 def cb_copy(self):
     scanlist = loadsave.load_txt(self.fmriscanstxt.value)
     modal = self.fmodal.value
     outfolder = self.foutfolder.value
     for scan in scanlist:
         os.makedirs(os.path.join(outfolder, scan), exist_ok=True)
         os.system('robocopy "{}" "{}" {}'.format(
             os.path.join(rootconfig.dms.folder_mridata, scan),
             os.path.join(outfolder, scan), modal))
Пример #5
0
def main():
    dbfile = 'E:/mmdpdb.db'
    engine = create_engine('sqlite:///' + dbfile)
    sessionManager = sessionmaker(bind=engine)
    session = sessionManager()
    db_group = tables.Group(name='test', description='test desc')
    session.add(db_group)
    names = loadsave.load_txt(
        'E:/Changgung works/20180409_tDCS_14/score_info/control_namelist.txt')
    for name in names:
        person = session.query(tables.Person).filter_by(name=name).one()
        db_group.people.append(person)
    scans = loadsave.load_txt(
        'E:/Changgung works/20180409_tDCS_14/score_info/control_scanlist-2.txt'
    )
    for scan in scans:
        db_scan = session.query(tables.MRIScan).filter_by(filename=scan).one()
        db_group.scans.append(db_scan)
    session.commit()
Пример #6
0
    def scanFolder(self):
        """
		scan folder to load name/scan list
		"""
        for filename in sorted(os.listdir(self.folderPath)):
            if filename.find('txt') == -1:
                continue
            if filename.find('scan') == -1 and filename.find('name') == -1:
                continue
            if filename.find('name') != -1:
                group = filename.split('_')[0]
                self.nameDict[group] = loadsave.load_txt(
                    os.path.join(self.folderPath, filename))
            elif filename.find('scan') != -1:
                group = filename.split('_')[0]
                timeCase = filename[filename.find('-') +
                                    1:filename.find('.txt')]
                self.scanDict[group + timeCase] = loadsave.load_txt(
                    os.path.join(self.folderPath, filename))
Пример #7
0
    def run(self):
        """Run the para.
		finalfolders is the constructed folder in which to run the job in parallel,
		Or sequential if configured that way.
		Env MMDPS_NEWLIST_TXT will override folderlist.
		Env MMDPS_SECONDLIST_TXT will override secondlist.
		"""
        if self.folderlist == 'listdir':
            originalfolders = path.clean_listdir(self.mainfolder)
        else:
            originalfolders = loadsave.load_txt(
                path.env_override(self.folderlist, 'MMDPS_NEWLIST_TXT'))
        folders = [os.path.join(self.mainfolder, f) for f in originalfolders]
        if self.bsecond:
            finalfolders = []
            if type(self.secondlist) is list:
                secondfolders = self.secondlist
            elif self.secondlist == 'all':
                secondfolders = loadsave.load_txt(
                    os.path.join(rootconfig.path.atlas, 'atlas_list.txt'))
            else:
                secondfolders = loadsave.load_txt(
                    path.env_override(self.secondlist, 'MMDPS_SECONDLIST_TXT'))
            for folder in folders:
                for secondfolder in secondfolders:
                    newfolder = os.path.join(folder, secondfolder)
                    path.makedirs(newfolder)
                    finalfolders.append(newfolder)
        else:
            finalfolders = folders
        currentJob = job.create_from_dict(
            loadsave.load_json(path.fullfile(self.jobconfig)))
        if self.runmode == 'FirstOnly':
            return self.run_seq(currentJob, finalfolders[0:1])
        if self.runmode == 'Parallel':
            return self.run_para(currentJob, finalfolders)
        if self.runmode == 'Sequential':
            return self.run_seq(currentJob, finalfolders)
        else:
            print('Error: no such runmode as', self.runmode)
            return None
Пример #8
0
 def insert_grouptable(self, grouptable):
     """Insert one configured group."""
     name, desc, txt = grouptable
     db_group = Group(name=name, description=desc)
     self.session.add(db_group)
     people = load_txt(txt)
     for person in people:
         l = person.split('_')
         personname = l[0]
         if personname in self.db_people:
             db_person = self.db_people[personname]
             db_group.people.append(db_person)
Пример #9
0
    def __init__(self,
                 inMainFolder,
                 outMainFolder,
                 mriscanstxt=None,
                 db_generator=None,
                 cls_niftigetter=NiftiGetter):
        """
		Import from inMainFolder to outMainFolder, for mriscans from mriscanstxt.
		Update database. Use NiftiGetter class from cls_niftigetter.
		"""
        self.inMainFolder = inMainFolder
        self.outMainFolder = outMainFolder
        if mriscanstxt is not None:
            self.mriscans = loadsave.load_txt(mriscanstxt)
        self.db_generator = db_generator
        self.cls_niftigetter = cls_niftigetter
Пример #10
0
        self.mriscans = mriscans

    def run_mriscan(self, mriscan):
        src = os.path.join(self.preprocessedFolder, mriscan,
                           'Filtered_4DVolume.nii')
        if os.path.isfile(src):
            dst = os.path.join(self.exportFolder, mriscan, 'pBOLD.nii')
            path.makedirs_file(dst)
            shutil.copy2(src, dst)
            print(mriscan, 'OK')
        else:
            print(mriscan, 'not found', src)

    def run(self):
        for mriscan in self.mriscans:
            self.run_mriscan(mriscan)


if __name__ == '__main__':
    # parser = argparse.ArgumentParser(description='Copy preprocessed BOLD to processing folder')
    # parser.add_argument('--mriscanstxt', required=True, help='mriscans list in txt file')
    # parser.add_argument('--outfolder', required=True, help='pBOLD output folder for all mriscans')
    # args = parser.parse_args()
    # exp = ExportBOLD(r'E:\DataProcessing\BOLDPreprocess\Data\FunRawARWSDCF',
    # 				 loadsave.load_txt(args.mriscanstxt),
    # 				 args.outfolder)
    mriscanstxt = 'E:/namelist.txt'
    exp = ExportBOLD('E:/DataProcessing/BOLDPreprocess/Data/FunRawARWSDCF',
                     loadsave.load_txt(mriscanstxt), 'E:/DataProcessing/BOLD/')
    exp.run()
Пример #11
0
def test_newGroupByScans(groupManager):
	scans = loadsave.load_txt('E:/Changgung works/20180409_tDCS_14/score_info/control_scanlist-2.txt')
	groupManager.newGroupByScans('test control 2', scans)
	return
Пример #12
0
		self.exportFolder = exportFolder
		self.mriscans = mriscans

	def run_mriscan(self, mriscan):
		src = os.path.join(self.preprocessedFolder, mriscan, 'Filtered_4DVolume.nii')
		if os.path.isfile(src):
			dst = os.path.join(self.exportFolder, mriscan, 'pBOLD.nii')
			path.makedirs_file(dst)
			shutil.copy2(src, dst)
			print(mriscan, 'OK')
		else:
			print(mriscan, 'not found', src)

	def run(self):
		for mriscan in self.mriscans:
			self.run_mriscan(mriscan)

if __name__ == '__main__':
	# parser = argparse.ArgumentParser(description='Copy preprocessed BOLD to processing folder')
	# parser.add_argument('--mriscanstxt', required=True, help='mriscans list in txt file')
	# parser.add_argument('--outfolder', required=True, help='pBOLD output folder for all mriscans')
	# args = parser.parse_args()
	# exp = ExportBOLD(r'E:\DataProcessing\BOLDPreprocess\Data\FunRawARWSDCF',
	# 				 loadsave.load_txt(args.mriscanstxt),
	# 				 args.outfolder)
	mriscanstxt = 'E:/namelist.txt'
	exp = ExportBOLD(r'E:\DataProcessing\BOLDPreprocess\Data\FunRawARWSDCF',
	 				 loadsave.load_txt(mriscanstxt),
	 				 'E:/DataProcessing/BOLD/')
	exp.run()
Пример #13
0
	def load_mriscanstxt(self):
		"""Load the mriscans txt file."""
		if not os.path.isfile(self.mriscanstxt):
			return
		self.mriscans = load_txt(self.mriscanstxt)
		self.people = self.build_internals(self.mriscans)
Пример #14
0
 def __init__(self, dcmMainFolder, niftiMainFolder, mriscantxt):
     self.dcmMainFolder = dcmMainFolder
     self.niftiMainFolder = niftiMainFolder
     self.mriscans = load_txt(mriscantxt)
Пример #15
0
 def __init__(self, mmdb, outcsvname, personnamestxt, anonymize=True):
     self.mmdb = mmdb
     self.outcsvname = outcsvname
     self.anonymize = anonymize
     self.personnames = loadsave.load_txt(personnamestxt)
    volumename = '3mm'
    atlasobj = atlas.get(atlasname)
    work_path = 'D:/Research/xuquan_FMRI/Dynamic_tfMRI_work/'
    outfolder = os.path.join(work_path, subject, atlasname, 'bold_net',
                             'dynamic_%d_%d' % (stepsize, windowLength))
    img = load_nii(os.path.join(work_path, subject, 'pBOLD.nii'))
    os.makedirs(outfolder, exist_ok=True)
    c = CalcDynamic(atlasobj, volumename, img, outfolder, windowLength,
                    stepsize)
    c.run()


if __name__ == '__main__':
    atlasList = ['brodmann_lrce']
    mriscanstxt = 'D:/Research/xuquan_FMRI/DPARSFA work/namelist.txt'
    subjectList = loadsave.load_txt(mriscanstxt)
    windowLength = 10
    stepsize = 1
    taskList = []
    for subject in subjectList:
        for atlasname in atlasList:
            taskList.append((subject, atlasname, windowLength, stepsize))
    taskCount = len(taskList)
    totalResult = []
    pool = multiprocessing.Pool(processes=4)
    manager = multiprocessing.Manager()
    managerQueue = manager.Queue()
    fwrap = parabase.FWrap(func, managerQueue)
    result = pool.map_async(fwrap.run, taskList)
    nfinished = 0
    while True: