Ejemplo n.º 1
0
def task_standardize_transform():
    """Standardize MRI images: transform phase."""
    if MODE[0] != 'T2w':
        return
    # mode = MODE - 'std'
    mode = MODE[:-1] if MODE[-1] == 'std' else MODE
    sl = SAMPLELIST
    paths = dwi.paths.Paths(mode)
    outpaths = dwi.paths.Paths(tuple(mode) + ('std', ))
    cfgpath = paths.std_cfg()
    for case, scan in cases_scans(mode, sl):
        inpath = paths.pmap(case=case, scan=scan)
        mask = paths.mask('prostate', case, scan)
        outpath = outpaths.pmap(case=case, scan=scan)
        cmd = dwi.shell.standardize_transform(cfgpath,
                                              inpath,
                                              outpath,
                                              mask=mask)
        yield {
            'name': taskname(mode, case, scan),
            'actions': folders(outpath) + [cmd],
            'file_dep': _files(cfgpath, inpath, mask),
            'targets': _files(outpath),
            'clean': True,
        }
Ejemplo n.º 2
0
def get_task_grid_texture(mode,
                          c,
                          s,
                          ls,
                          mt,
                          tspec,
                          lt=None,
                          mbb=None,
                          nanbg=False,
                          fmt='txt'):
    """Grid classifier."""
    paths = dwi.paths.Paths(mode)
    pmap = paths.texture(c, s, None, mt, 'all', 0, tspec, voxel='all')
    prostate = paths.mask('prostate', c, s)
    lesion = [paths.mask('lesion', c, s, lesion=x) for x in ls]
    out, target = paths.grid(c, s, mt, tspec, fmt=fmt)
    if fmt == 'h5':
        target = out
    z = 5
    # z = 1
    d = dict(mbb=mbb,
             voxelsize=None,
             winsize=z,
             voxelspacing=(z, 1, 1),
             lesiontypes=lt,
             use_centroid=False,
             nanbg=nanbg)
    cmd = dwi.shell.grid(pmap, None, prostate, lesion, out, **d)
    return {
        'name': taskname(mode, c, s, mt, tspec.method, tspec.winsize),
        'actions': folders(out) + [cmd],
        'file_dep': _files(pmap, prostate, *lesion),
        'targets': _files(target),
    }
Ejemplo n.º 3
0
def get_task_merge_textures(mode, mt, c, s, l, slices, portion, voxel):
    """Merge texture methods into singe file per case/scan/lesion."""
    paths = dwi.paths.Paths(mode)
    infiles = [paths.texture(c, s, l, mt, slices, portion, tspec, voxel=voxel)
               for tspec in texture_methods_winsizes(mode, mt)]
    outfile = paths.texture(c, s, l, mt+'_merged', slices, portion, None,
                            voxel=voxel)
    cmd = dwi.shell.select_voxels(' '.join(map(str, infiles)), outfile)
    return {
        'name': taskname(mode, c, s, l, mt, slices, portion,
                         voxel),
        'actions': folders(outfile) + [cmd],
        'file_dep': _files(*infiles),
        'targets': _files(outfile),
        }
Ejemplo n.º 4
0
def get_task_select_roi_auto(mode, case, scan, algparams):
    """Select ROIs from the pmap DICOMs based on masks."""
    paths = dwi.paths.Paths(mode)
    ap_ = '_'.join(algparams)
    mask = paths.mask('auto', case, scan, algparams=algparams)
    roi = paths.roi('auto', case=case, scan=scan, algparams=algparams)
    pmap = paths.pmap(case=case, scan=scan)
    cmd = dwi.shell.select_voxels(pmap, roi, mask=mask, keepmasked=False)
    return {
        'name': taskname(mode, ap_, case, scan),
        'actions': folders(roi) + [cmd],
        'file_dep': _files(mask, pmap),
        'targets': _files(roi),
        'clean': True,
        }
Ejemplo n.º 5
0
def task_make_subregion():
    """Make minimum bounding box + 10 voxel subregions from prostate masks."""
    for mode, sl in product(MODES, SAMPLELISTS):
        paths = dwi.paths.Paths(mode)
        if str(mode) == 'DWI-Mono-ADCm':
            for case, scan in cases_scans(mode, sl):
                mask = paths.mask('prostate', case, scan)
                subregion = paths.subregion(case=case, scan=scan)
                cmd = dwi.shell.make_subregion(mask, subregion)
                yield {
                    'name': taskname(mode, case, scan),
                    'actions': folders(subregion) + [cmd],
                    'file_dep': _files(mask),
                    'targets': _files(subregion),
                    'clean': True,
                    }
Ejemplo n.º 6
0
def task_make_subregion():
    """Make minimum bounding box + 10 voxel subregions from prostate masks."""
    for mode, sl in product(MODES, SAMPLELISTS):
        paths = dwi.paths.Paths(mode)
        if str(mode) == 'DWI-Mono-ADCm':
            for case, scan in cases_scans(mode, sl):
                mask = paths.mask('prostate', case, scan)
                subregion = paths.subregion(case=case, scan=scan)
                cmd = dwi.shell.make_subregion(mask, subregion)
                yield {
                    'name': taskname(mode, case, scan),
                    'actions': folders(subregion) + [cmd],
                    'file_dep': _files(mask),
                    'targets': _files(subregion),
                    'clean': True,
                }
Ejemplo n.º 7
0
def get_task_histogram(mode, masktype, samplelist):
    """Plot image histograms."""
    paths = dwi.paths.Paths(mode)
    if masktype == 'lesion':
        it = (dict(case=c, scan=s, lesion=l) for c, s, l in
              lesions(mode, samplelist))
    else:
        it = (dict(case=c, scan=s) for c, s in cases_scans(mode, samplelist))
    inpaths = [paths.roi(masktype, **x) for x in it]
    figpath = paths.histogram(masktype, samplelist)
    cmd = dwi.shell.histogram(inpaths, figpath, params=None)
    return {
        'name': taskname(mode, masktype, samplelist),
        'actions': folders(figpath) + [cmd],
        'file_dep': _files(inpaths),
        'targets': _files(figpath),
        }
Ejemplo n.º 8
0
def get_task_select_roi_manual(mode, case, scan, masktype):
    """Select ROIs from the pmap DICOMs based on masks."""
    paths = dwi.paths.Paths(mode)
    mask = paths.mask(masktype, case, scan)
    roi = paths.roi(masktype, case=case, scan=scan)
    pmap = paths.pmap(case=case, scan=scan)
    d = dict(mask=mask, keepmasked=(masktype == 'prostate'))
    if 'std' in mode:
        d['astype'] = 'float32'  # Integers cannot have nans.
    cmd = dwi.shell.select_voxels(pmap, roi, **d)
    return {
        'name': taskname(mode, masktype, case, scan),
        'actions': folders(roi) + [cmd],
        'file_dep': _files(mask, pmap),
        'targets': _files(roi),
        'clean': True,
        }
Ejemplo n.º 9
0
def get_task_histogram(mode, masktype, samplelist):
    """Plot image histograms."""
    paths = dwi.paths.Paths(mode)
    if masktype == 'lesion':
        it = (dict(case=c, scan=s, lesion=l)
              for c, s, l in lesions(mode, samplelist))
    else:
        it = (dict(case=c, scan=s) for c, s in cases_scans(mode, samplelist))
    inpaths = [paths.roi(masktype, **x) for x in it]
    figpath = paths.histogram(masktype, samplelist)
    cmd = dwi.shell.histogram(inpaths, figpath, params=None)
    return {
        'name': taskname(mode, masktype, samplelist),
        'actions': folders(figpath) + [cmd],
        'file_dep': _files(inpaths),
        'targets': _files(figpath),
    }
Ejemplo n.º 10
0
def get_task_grid_texture(mode, c, s, ls, mt, tspec, lt=None, mbb=None,
                          nanbg=False, fmt='txt'):
    """Grid classifier."""
    paths = dwi.paths.Paths(mode)
    pmap = paths.texture(c, s, None, mt, 'all', 0, tspec, voxel='all')
    prostate = paths.mask('prostate', c, s)
    lesion = [paths.mask('lesion', c, s, lesion=x) for x in ls]
    out, target = paths.grid(c, s, mt, tspec, fmt=fmt)
    if fmt == 'h5':
        target = out
    z = 5
    # z = 1
    d = dict(mbb=mbb, voxelsize=None, winsize=z, voxelspacing=(z, 1, 1),
             lesiontypes=lt, use_centroid=False, nanbg=nanbg)
    cmd = dwi.shell.grid(pmap, None, prostate, lesion, out, **d)
    return {
        'name': taskname(mode, c, s, mt, tspec.method, tspec.winsize),
        'actions': folders(out) + [cmd],
        'file_dep': _files(pmap, prostate, *lesion),
        'targets': _files(target),
        }
Ejemplo n.º 11
0
def task_standardize_train():
    """Standardize MRI images: training phase.

    Pay attention to the sample list: all samples should be used.
    """
    if MODE[0] != 'T2w':
        return
    # mode = MODE - 'std'
    mode = MODE[:-1] if MODE[-1] == 'std' else MODE
    paths = dwi.paths.Paths(mode)
    std_cfg = paths.std_cfg()
    inpaths = [paths.roi('prostate', case=c, scan=s) for c, s in
               cases_scans(mode, 'all')]
    cmd = dwi.shell.standardize_train(inpaths, std_cfg, 'none')
    yield {
        'name': taskname(mode),
        'actions': [cmd],
        'file_dep': _files(*inpaths),
        'targets': _files(std_cfg),
        'clean': True,
        }
Ejemplo n.º 12
0
def get_task_texture(mode, masktype, case, scan, lesion, slices, portion,
                     tspec, voxel):
    """Generate texture features."""
    paths = dwi.paths.Paths(mode)
    inpath = paths.pmap(case=case, scan=scan)
    deps = [inpath]
    mask = paths.mask(masktype, case, scan, lesion=lesion)
    if mask is not None:
        deps.append(mask)
    outfile = paths.texture(case, scan, lesion, masktype, slices, portion,
                            tspec, voxel=voxel)
    cmd = dwi.shell.get_texture(mode, inpath, tspec, slices, portion, outfile,
                                voxel, mask=mask)
    return {
        'name': taskname(mode, masktype, slices, portion, case, scan, lesion,
                         tspec.method, tspec.winsize, voxel),
        'actions': folders(outfile) + [cmd],
        'file_dep': _files(*deps),
        'targets': _files(outfile),
        'clean': True,
        }
Ejemplo n.º 13
0
def get_task_merge_textures(mode, mt, c, s, l, slices, portion, voxel):
    """Merge texture methods into singe file per case/scan/lesion."""
    paths = dwi.paths.Paths(mode)
    infiles = [
        paths.texture(c, s, l, mt, slices, portion, tspec, voxel=voxel)
        for tspec in texture_methods_winsizes(mode, mt)
    ]
    outfile = paths.texture(c,
                            s,
                            l,
                            mt + '_merged',
                            slices,
                            portion,
                            None,
                            voxel=voxel)
    cmd = dwi.shell.select_voxels(' '.join(map(str, infiles)), outfile)
    return {
        'name': taskname(mode, c, s, l, mt, slices, portion, voxel),
        'actions': folders(outfile) + [cmd],
        'file_dep': _files(*infiles),
        'targets': _files(outfile),
    }
Ejemplo n.º 14
0
def task_standardize_transform():
    """Standardize MRI images: transform phase."""
    if MODE[0] != 'T2w':
        return
    # mode = MODE - 'std'
    mode = MODE[:-1] if MODE[-1] == 'std' else MODE
    sl = SAMPLELIST
    paths = dwi.paths.Paths(mode)
    outpaths = dwi.paths.Paths(tuple(mode) + ('std',))
    cfgpath = paths.std_cfg()
    for case, scan in cases_scans(mode, sl):
        inpath = paths.pmap(case=case, scan=scan)
        mask = paths.mask('prostate', case, scan)
        outpath = outpaths.pmap(case=case, scan=scan)
        cmd = dwi.shell.standardize_transform(cfgpath, inpath, outpath,
                                              mask=mask)
        yield {
            'name': taskname(mode, case, scan),
            'actions': folders(outpath) + [cmd],
            'file_dep': _files(cfgpath, inpath, mask),
            'targets': _files(outpath),
            'clean': True,
            }
Ejemplo n.º 15
0
    """
    if MODE[0] != 'T2w':
        return
    # mode = MODE - 'std'
    mode = MODE[:-1] if MODE[-1] == 'std' else MODE
    paths = dwi.paths.Paths(mode)
    std_cfg = paths.std_cfg()
    inpaths = [
        paths.roi('prostate', case=c, scan=s)
        for c, s in cases_scans(mode, 'all')
    ]
    cmd = dwi.shell.standardize_train(inpaths, std_cfg, 'none')
    yield {
        'name': taskname(mode),
        'actions': [cmd],
        'file_dep': _files(*inpaths),
        'targets': _files(std_cfg),
        'clean': True,
    }


def task_standardize_transform():
    """Standardize MRI images: transform phase."""
    if MODE[0] != 'T2w':
        return
    # mode = MODE - 'std'
    mode = MODE[:-1] if MODE[-1] == 'std' else MODE
    sl = SAMPLELIST
    paths = dwi.paths.Paths(mode)
    outpaths = dwi.paths.Paths(tuple(mode) + ('std', ))
    cfgpath = paths.std_cfg()