Exemplo n.º 1
0
    def run(self, args, extra_args):
        if args.output_file is not None:
            output_file = os.path.realpath(args.output_file)
        else:
            output_file = os.path.realpath(args.input_protocol)

        additional_files = []
        if args.additional_files:
            for file in args.additional_files:
                additional_files.append(np.genfromtxt(file))

        protocol = mdt.load_protocol(os.path.realpath(args.input_protocol))
        context_dict = {
            name: protocol.get_column(name)
            for name in protocol.column_names
        }

        exec(args.expr, {'np': np, 'files': additional_files}, context_dict)

        for key in context_dict:
            if is_scalar(context_dict[key]):
                context_dict[key] = np.ones(
                    protocol.length) * context_dict[key]

        protocol = Protocol(context_dict)
        mdt.write_protocol(protocol, output_file)
Exemplo n.º 2
0
    def run(self, args):
        if args.output_file is not None:
            output_file = os.path.realpath(args.output_file)
        else:
            output_file = os.path.realpath(args.input_protocol)

        protocol = mdt.load_protocol(os.path.realpath(args.input_protocol))
        context_dict = {
            name: protocol.get_column(name)
            for name in protocol.column_names
        }

        def rm(column_name):
            protocol.remove_column(column_name)
            del context_dict[column_name]

        def add(column_name, value):
            protocol.add_column(column_name, value)
            context_dict[column_name] = value

        exec(args.expr, {'np': np, 'rm': rm, 'add': add}, context_dict)

        for name, value in context_dict.items():
            protocol.update_column(name, value)

        mdt.write_protocol(protocol, output_file)
Exemplo n.º 3
0
    def _save_protocol(self):
        output_file_name, used_filter = QFileDialog().getSaveFileName(
            caption='Save the protocol as', directory=self._opened_file,
            filter=';;'.join(protocol_files_filters))

        if os.path.isdir(os.path.dirname(output_file_name)) and self._protocol.length:
            mdt.write_protocol(self._protocol, output_file_name)
            print('Saved protocol as: {}'.format(output_file_name))