def run(datatype, columns, input): # import modules locally import sh if input: sh.mlr('--tsv', 'cut', '-x', '-f', columns, input, _out=sys.stdout, _err=sys.stderr) elif not sys.stdin.isatty(): print('reading from stdin') # print(sh.cat(_in=sys.stdin)) print( sh.mlr('--tsv', 'cut', '-x', '-f', columns, _in=sys.stdin, _out=sys.stdout, _err=sys.stderr)) else: parser.print_help()
def run(datatype, columns, input): # import modules locally import socket import sh # type: ignore from kgtk.exceptions import KGTKException try: if input: print(input) sh.mlr('--tsv', 'cut', '-x', '-f', columns, input, _out=sys.stdout, _err=sys.stderr) elif not sys.stdin.isatty(): print( sh.mlr('--tsv', 'cut', '-x', '-f', columns, _in=sys.stdin, _out=sys.stdout, _err=sys.stderr)) else: raise KGTKException except: raise KGTKException
def run(datatype, pattern, input, subj_col, pred_col, obj_col): # import modules locally import socket import sh # type: ignore from kgtk.exceptions import KGTKException props = [subj_col, pred_col, obj_col] def prepare_filter(property, prop_pattern): prop_pattern = prop_pattern.strip() prop_filters = [] for value in prop_pattern.split(','): value = value.strip() value_filter = '$%s == "%s"' % (property, value) prop_filters.append(value_filter) return '(%s)' % ' || '.join(prop_filters) try: n1_filter, lbl_filter, n2_filter = pattern.split(';') filters = [] for i, col_filter in enumerate([n1_filter, lbl_filter, n2_filter]): if col_filter.strip(): ready = prepare_filter(props[i], col_filter) filters.append(ready) filter_str = '\'%s\'' % ' && '.join(filters) if filter_str: if input: sh.mlr('--%s' % datatype, 'filter', filter_str, input, _out=sys.stdout, _err=sys.stderr) elif not sys.stdin.isatty(): sh.mlr('--%s' % datatype, 'filter', filter_str, _in=sys.stdin, _out=sys.stdout, _err=sys.stderr) except: raise KGTKException
def run(datatype, property, value, input): # import modules locally import socket import sh filter = '$%s == "%s"' % (property, value) if input: sh.mlr('--%s' % datatype, 'filter', filter, input, _out=sys.stdout, _err=sys.stderr) elif not sys.stdin.isatty(): sh.mlr('--%s' % datatype, 'filter', filter, _in=sys.stdin, _out=sys.stdout, _err=sys.stderr)
def run(datatype, column, input): # import modules locally import socket import sh sh.mlr('--%s' % datatype, 'sort', '-f', column, input, _out=sys.stdout, _err=sys.stderr)