コード例 #1
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours = simple_interface.load_contours(
        filenames, show_progress=options.show_progress)
    if options.reference is not None:
        reference = contour_class.from_file(options.reference)
        contours = simple_interface.align_contours_to(
            contours,
            reference,
            align_steps=options.alignment_steps,
            allow_reflection=options.allow_reflection,
            show_progress=options.show_progress)
    else:
        contours = simple_interface.align_contours(
            contours,
            options.alignment_steps,
            options.allow_reflection,
            max_iters=options.max_iterations,
            show_progress=options.show_progress)
    destination = path.path(options.destination)
    destination.makedirs_p()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
コード例 #2
0
ファイル: plot_model.py プロジェクト: wangjingbo1219/celltool
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) != 1:
        raise ValueError('Only a single PCA contour can be plotted at a time -- please specify only one model file on the command line.')
    pca_contour = contour_class.from_file(args[0], contour_class.PCAContour)
    if not options.output_file:
        output_file = pca_contour.simple_name()+'.svg'
    else:
        output_file = options.output_file
    plot_tools.pca_modes_plot(pca_contour, output_file, modes=options.modes, 
        positions=options.positions, scale=options.scale)
コード例 #3
0
ファイル: align_contours.py プロジェクト: zpincus/celltool
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours = simple_interface.load_contours(filenames, show_progress = options.show_progress)
    if options.reference is not None:
        reference = contour_class.from_file(options.reference)
        contours = simple_interface.align_contours_to(contours, reference, align_steps=options.alignment_steps,
            allow_reflection=options.allow_reflection, show_progress=options.show_progress)
    else:
        contours = simple_interface.align_contours(contours, options.alignment_steps, options.allow_reflection,
            max_iters=options.max_iterations, show_progress = options.show_progress)
    destination = path.path(options.destination)
    destination.makedirs_p()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
コード例 #4
0
ファイル: match_files.py プロジェクト: zpincus/celltool
def _get_contours_and_images(filenames, show_progress = True):
    contours = []
    image_names = []
    if show_progress:
        filenames = terminal_tools.progress_list(filenames, 'Loading Contours and Images')
    for filename in filenames:
        filename = path.path(filename)
        if not filename.exists():
            raise ValueError('File "%s" does not exist.'%filename)
        try:
            freeimage.read_metadata(filename)
            image_names.append(filename)
        except IOError as e:
            # print e
            # print Image.ID
            try:
                contours.append(contour_class.from_file(filename))
            except IOError as e:
                # print e
                raise ValueError('Could not open file "%s" as an image or a contour.'%filename)
    return contours, image_names
コード例 #5
0
ファイル: match_files.py プロジェクト: happydpc/celltool
def _get_contours_and_images(filenames, show_progress=True):
    contours = []
    image_names = []
    if show_progress:
        filenames = terminal_tools.progress_list(
            filenames, 'Loading Contours and Images')
    for filename in filenames:
        filename = path.path(filename)
        if not filename.exists():
            raise ValueError('File "%s" does not exist.' % filename)
        try:
            Image.open(filename)
            image_names.append(filename)
        except IOError, e:
            # print e
            # print Image.ID
            try:
                contours.append(contour_class.from_file(filename))
            except IOError, e:
                # print e
                raise ValueError(
                    'Could not open file "%s" as an image or a contour.' %
                    filename)
コード例 #6
0
ファイル: plot_distribution.py プロジェクト: zpincus/celltool
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    data_files = []
    new_args = []
    for arg in args:
        if type(arg) == list:
            data_files.append(arg)
        else:
            new_args.append(arg)
    args = cli_tools.glob_args(new_args)
    if len(args) + len(data_files) == 0:
        raise ValueError('Some data files (and optionally contour files, for 2D plots) must be specified!')
    
    # if the x, y, and name columns are convertible to integers, do so and 
    # then convert them from 1-indexed to 0-indexed
    try:
        options.name_column = int(options.name_column)
        options.name_column -= 1
    except:
        pass
    try:
        options.x_column = int(options.x_column)
        options.x_column -= 1
    except:
        pass
    try:
        options.y_column = int(options.y_column)
        options.y_column -= 1
    except:
        pass
    contours = {}
    if options.show_progress:
        args = terminal_tools.progress_list(args, "Reading input data and contours")
    for arg in args:
        contour = None
        try:
            contour = contour_class.from_file(arg)
        except:
            data_files.append(arg)
        if contour is not None:
            contours[contour.simple_name()] = contour
    if len(data_files) == 0:
        raise ValueError('No data files were specified!')
    headers, data_ranges, data_names, data_files, row_ranges = get_data(data_files)
    if not options.x_title:
            if isinstance(options.x_column, int):
                try: options.x_title = headers[0][options.x_column]
                except: pass
            else:
                options.x_title = options.x_column
    if options.y_column is not None:
        # make scatterplot
        if not options.y_title:
            if isinstance(options.y_column, int):
                try: options.y_title = headers[0][options.y_column]
                except: pass
            else:
                options.y_title = options.y_column
        contour_groups = get_contour_groups(data_ranges, contours, data_files, row_ranges, options.name_column, options.x_column, options.y_column)
        if numpy.alltrue([len(cg)==0 for cg in contour_groups]):
            raise RuntimeError('No contours found for data rows specified (perhaps the names mismatch or there were no data rows?).')
        plot_tools.contour_scatterplot(contour_groups, options.output_file, options.scale,
            (options.x_title, options.y_title), options.title, names=data_names, 
            axes_at_origin=options.axes_at_origin, fix_xrange=(options.x_min, options.x_max),
            fix_yrange=(options.y_min, options.y_max), show_contour_axes=options.contour_axes, 
            show_progress=options.show_progress)
    else:
        data_groups = [[row[options.x_column] for row in data_range] for data_range in data_ranges]
        plot_tools.distribution_plot(data_groups, options.output_file, options.x_title,
            options.title, names=data_names, axes_at_origin=options.axes_at_origin, 
            fix_xrange=(options.x_min, options.x_max))
コード例 #7
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    data_files = []
    new_args = []
    for arg in args:
        if type(arg) == list:
            data_files.append(arg)
        else:
            new_args.append(arg)
    args = cli_tools.glob_args(new_args)
    if len(args) + len(data_files) == 0:
        raise ValueError(
            'Some data files (and optionally contour files, for 2D plots) must be specified!'
        )

    # if the x, y, and name columns are convertible to integers, do so and
    # then convert them from 1-indexed to 0-indexed
    try:
        options.name_column = int(options.name_column)
        options.name_column -= 1
    except:
        pass
    try:
        options.x_column = int(options.x_column)
        options.x_column -= 1
    except:
        pass
    try:
        options.y_column = int(options.y_column)
        options.y_column -= 1
    except:
        pass
    contours = {}
    if options.show_progress:
        args = terminal_tools.progress_list(args,
                                            "Reading input data and contours")
    for arg in args:
        contour = None
        try:
            contour = contour_class.from_file(arg)
        except:
            data_files.append(arg)
        if contour is not None:
            contours[contour.simple_name()] = contour
    if len(data_files) == 0:
        raise ValueError('No data files were specified!')
    headers, data_ranges, data_names, data_files, row_ranges = get_data(
        data_files)
    if not options.x_title:
        if isinstance(options.x_column, int):
            try:
                options.x_title = headers[0][options.x_column]
            except:
                pass
        else:
            options.x_title = options.x_column
    if options.y_column is not None:
        # make scatterplot
        if not options.y_title:
            if isinstance(options.y_column, int):
                try:
                    options.y_title = headers[0][options.y_column]
                except:
                    pass
            else:
                options.y_title = options.y_column
        contour_groups = get_contour_groups(data_ranges, contours, data_files,
                                            row_ranges, options.name_column,
                                            options.x_column, options.y_column)
        if numpy.alltrue([len(cg) == 0 for cg in contour_groups]):
            raise RuntimeError(
                'No contours found for data rows specified (perhaps the names mismatch or there were no data rows?).'
            )
        plot_tools.contour_scatterplot(contour_groups,
                                       options.output_file,
                                       options.scale,
                                       (options.x_title, options.y_title),
                                       options.title,
                                       names=data_names,
                                       axes_at_origin=options.axes_at_origin,
                                       fix_xrange=(options.x_min,
                                                   options.x_max),
                                       fix_yrange=(options.y_min,
                                                   options.y_max),
                                       show_contour_axes=options.contour_axes,
                                       show_progress=options.show_progress)
    else:
        data_groups = [[row[options.x_column] for row in data_range]
                       for data_range in data_ranges]
        plot_tools.distribution_plot(data_groups,
                                     options.output_file,
                                     options.x_title,
                                     options.title,
                                     names=data_names,
                                     axes_at_origin=options.axes_at_origin,
                                     fix_xrange=(options.x_min, options.x_max))