Esempio n. 1
0
 def __init__(self, atlasobj, title, outfilepath, plot_config=None):
     if plot_config is None:
         plot_config = {}
     self.atlasobj = atlasobj
     if plot_config.get('draw_RSN', False):
         self.brainparts = BrainParts(
             self.atlasobj.get_brainparts_config(
                 'RSN'))  # circosparts.json file in each atlas's folder
     else:
         self.brainparts = BrainParts(self.atlasobj.get_brainparts_config(
         ))  # circosparts.json file in each atlas's folder
     self.title = title
     if outfilepath[-4:] == '.png':
         outfilepath = outfilepath[:-4]
     self.outfilepath = outfilepath
     self.outfolder, self.outfilename = os.path.split(outfilepath)
     self.circosfolder = os.path.join(self.outfolder, 'circosdata',
                                      self.outfilename)
     path.makedirs(self.circosfolder)
     self.circosConfigFile = CircosConfigFile()
     self.circoslinks = []
     self.circos_directed_links = []
     self.circosvalues = []
     self.ideogram_radius = None
     self.colorlist = None
     if atlasobj.name == 'bnatlas':
         plot_config['region_tick_size'] = '20p'
         plot_config['link_thickness'] = '10p'
     elif atlasobj.name == 'aicha':
         plot_config['region_tick_size'] = '10p'
         plot_config['link_thickness'] = '5p'
     self.customizeSize(plot_config)
Esempio n. 2
0
def convert_dicom_to_nifti(infolder, outfolder):
    """
	Convert DICOM to raw NIFTI.
	
	The infolder should be the DICOM folder.
	The outfolder will be the converted NIFTI folder.
	the ret is the conversion program return value. 0 typically indicates success.
	"""
    path.rmtree(outfolder)
    path.makedirs(outfolder)
    gen_scan_info(infolder, outfolder)
    ret = subprocess.call(
        [rootconfig.path.dcm2nii, '-z', 'y', '-o', outfolder, infolder],
        cwd=os.path.dirname(rootconfig.path.dcm2nii))
    print(outfolder, ret)
    return ret
Esempio n. 3
0
def calc_binary_density(img, atlasobj, atlasimg):
    timg = atlasimg
    data = img.get_data()
    tdata = timg.get_data()
    threshold = 0.5
    data[data <= threshold * 255] = 0
    path.makedirs('t1mean')
    nib.save(img, 't1mean/thres_{}.nii.gz'.format(threshold))
    data[data > threshold] = 1
    res = np.empty(atlasobj.count)
    for i, region in enumerate(atlasobj.regions):
        regiondots = data[tdata == region]
        regioncount = regiondots.shape[0]
        ndots = np.sum(regiondots)
        res[i] = ndots / regioncount
    return res
Esempio n. 4
0
 def copy_one_nifti(self, mriscan):
     """Copy all modals for one mriscan."""
     infolder = os.path.join(self.inMainFolder, mriscan)
     outfolder = os.path.join(self.outMainFolder, mriscan)
     path.makedirs(outfolder)
     niftigetter = self.cls_niftigetter(infolder)
     modalities_coverage = [False, False, False, False]
     modalities_coverage[0] = self.copy_one_nifti_modal(
         outfolder, niftigetter.get_T1, 'T1.nii.gz')
     modalities_coverage[1] = self.copy_one_nifti_modal(
         outfolder, niftigetter.get_T2, 'T2.nii.gz')
     modalities_coverage[2] = self.copy_one_nifti_modal(
         outfolder, niftigetter.get_BOLD, 'BOLD.nii.gz')
     modalities_coverage[3] = self.copy_one_nifti_modal(
         outfolder, niftigetter.get_DWI, 'DWI')
     self.copy_one_nifti_modal(outfolder, niftigetter.get_ScanInfo,
                               'scan_info.json')
     return modalities_coverage
Esempio n. 5
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
Esempio n. 6
0
def convert_dicom_to_nifti(infolder, outfolder):
    """
	Convert DICOM to raw NIFTI.
	
	The infolder should be the DICOM folder.
	The outfolder will be the converted NIFTI folder.
	the ret is the conversion program return value. 0 typically indicates success.
	"""
    if os.path.isdir(outfolder):
        print('Output path %s is not empty. Continue anyway...' % outfolder)
    else:
        path.makedirs(outfolder)
    try:
        # try to generate scan info, processing date-time etc
        # will fail on non-Changgung data folder structure
        gen_scan_info(infolder, outfolder)
    except Exception:
        pass
    ret = subprocess.call(
        [rootconfig.path.dcm2nii, '-z', 'y', '-o', outfolder, infolder],
        cwd=os.path.dirname(rootconfig.path.dcm2nii))
    print('Conversion finished. Return value: %d. Data saved at: %s' %
          (ret, outfolder))
    return ret
Esempio n. 7
0
File: job.py Progetto: yaojh18/mmdps
def genlogfilename(info=''):
    """Generate a log file name base on current time and supplied info."""
    path.makedirs('log')
    timestr = clock.now()
    return 'log/log_{}_{}.txt'.format(timestr, info)