def parse(in_data): """Parses a samtools flagstat result into a dictionary. :param in_data: Input flagstat contents. :type in_data: str or file handle :returns: Parsed flagstat values. :rtype: dict """ with get_handle(in_data) as fh: contents = fh.read(_MAX_SIZE) f = partial(search, contents, caster=int) parsed = ( ("total", f(_RE_TOTAL)), ("duplicates", f(_RE_DUPLICATES)), ("secondary", f(_RE_SECONDARY)), ("supplementary", f(_RE_SUPPLEMENTARY)), ("mapped", f(_RE_MAPPED)), ("paired_sequencing", f(_RE_PAIRED_SEQ)), ("paired", f(_RE_PAIRED_BAM)), ("paired_proper", f(_RE_PAIRED_PROPER)), ("read1", f(_RE_READ1)), ("read2", f(_RE_READ2)), ("singleton", f(_RE_SINGLETON)), ("diff_chrom", f(_RE_DIFF)), ("diff_chrom_mapq", f(_RE_DIFF_MIN)), ) payload = { "pass_qc": {k: v[0] for k, v in parsed if v[0] is not None}, "fail_qc": {k: v[1] for k, v in parsed if v[1] is not None}, } if len(payload["pass_qc"]) == 0 and len(payload["fail_qc"]) == 0: raise click.BadParameter("Cannot parse input flagstat file.") return payload
def main(): handle = None try: # # Create a handle # handle = get_handle(tenant_id) # # Create a table # statement = 'Create table if not exists ' + table_name + '(id integer, \ sid integer, name string, primary key(shard(sid), id))' print('Creating table: ' + statement) request = TableRequest().set_statement(statement).set_table_limits( TableLimits(30, 10, 1)) handle.do_table_request(request, 50000, 3000) print('After create table') # # Put a few rows # request = PutRequest().set_table_name(table_name) for i in range(10): value = {'id': i, 'sid': 0, 'name': 'myname' + str(i)} request.set_value(value) handle.put(request) print('After put of 10 rows') # # Multiple write a few rows # request = WriteMultipleRequest() for i in range(10): value = {'id': i, 'sid': 0, 'name': 'newname' + str(i)} request.add( PutRequest().set_value(value).set_table_name(table_name), True) result = handle.write_multiple(request) print('After multiple write: ' + str(result)) # # Prepare a statement # statement = 'select * from ' + table_name + ' where id > 2 and id < 8' request = PrepareRequest().set_statement(statement) prepared_result = handle.prepare(request) print('After prepare the statement: ' + statement) # # Query, using the prepared statement # request = QueryRequest().set_prepared_statement(prepared_result) print('Query results for the prepared statement: ') while True: result = handle.query(request) for r in result.get_results(): print('\t' + str(r)) if request.is_done(): break # # Multiple delete the rows # request = MultiDeleteRequest().set_table_name(table_name).set_key( {'sid': 0}) result = handle.multi_delete(request) print('After multiple delete: ' + str(result)) # # Query again to show deletions, using the prepared statement # request = QueryRequest().set_prepared_statement(prepared_result) print('Query results for the prepared statement (should be no rows): ') while True: result = handle.query(request) for r in result.get_results(): print('\t' + str(r)) if request.is_done(): break # # Drop the table # if drop_table: request = TableRequest().set_statement('drop table if exists ' + table_name) handle.do_table_request(request, 40000, 2000) print('After drop table') else: print('Not dropping table') print('Example is complete') except Exception as e: print(e) traceback.print_exc() finally: # If the handle isn't closed Python will not exit properly if handle is not None: handle.close()
def main(): handle = None try: # # Create a handle # handle = get_handle(tenant_id) # # Create a table # statement = 'Create table if not exists ' + table_name + '(id integer, \ sid integer, name string, primary key(shard(sid), id))' print('Creating table: ' + statement) request = TableRequest().set_statement(statement).set_table_limits( TableLimits(30, 10, 1)) result = handle.table_request(request) # # Table creation can take time, depending on the state of the system. # If if fails after 40s, re-run the program # result.wait_for_state(handle, table_name, State.ACTIVE, 50000, 3000) print('After create table') # # Put a few rows # request = PutRequest().set_table_name(table_name) for i in range(10): value = {'id': i, 'sid': 0, 'name': 'myname' + str(i)} request.set_value(value) handle.put(request) print('After put of 10 rows') # # Get the row # request = GetRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.get(request) print('After get: ' + str(result)) # # Query, using a range # statement = 'select * from ' + table_name + ' where id > 2 and id < 8' request = QueryRequest().set_statement(statement) result = handle.query(request) print('Query results for: ' + statement) for r in result.get_results(): print('\t' + str(r)) # # Delete the row # request = DeleteRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.delete(request) print('After delete: ' + str(result)) # # Get again to show deletion # request = GetRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.get(request) print('After get (should be None): ' + str(result)) # # Drop the table # if drop_table: request = TableRequest().set_statement('drop table if exists ' + table_name) result = handle.table_request(request) # # Table drop can take time, depending on the state of the system. # If this wait fails the table will still probably been dropped # result.wait_for_state(handle, table_name, State.DROPPED, 40000, 2000) print('After drop table') else: print('Not dropping table') print('Example is complete') except Exception as e: print(e) traceback.print_exc() finally: # If the handle isn't closed Python will not exit properly if handle is not None: handle.close()
def main(): handle = None try: # # Create a handle # handle = get_handle(tenant_id) # # List any existing tables for this tenant # print('Listing tables') ltr = ListTablesRequest() lr_result = handle.list_tables(ltr) print('Existing tables: ' + str(lr_result)) # # Create a table # statement = 'Create table if not exists ' + table_name + '(id integer, \ sid integer, name string, primary key(shard(sid), id))' print('Creating table: ' + statement) request = TableRequest().set_statement(statement).set_table_limits( TableLimits(30, 10, 1)) result = handle.table_request(request) # # Table creation can take time, depending on the state of the system. # If if fails after 40s, re-run the program # result.wait_for_state(handle, table_name, State.ACTIVE, 40000, 3000) print('After create table') # # Create an index # statement = ('Create index if not exists ' + index_name + ' on ' + table_name + '(name)') print('Creating index: ' + statement) request = TableRequest().set_statement(statement) result = handle.table_request(request) # # Index creation can take time, depending on the state of the system. # If if fails after 40s, re-run the program # result.wait_for_state(handle, table_name, State.ACTIVE, 40000, 3000) print('After create index') # # Get the table # request = GetTableRequest().set_table_name(table_name) result = handle.get_table(request) print('After get table: ' + str(result)) # # Get the indexes # request = GetIndexesRequest().set_table_name(table_name) result = handle.get_indexes(request) print('The indexes for: ' + table_name) for idx in result.get_indexes(): print('\t' + str(idx)) # # Get the table usage information # request = TableUsageRequest().set_table_name(table_name) result = handle.get_table_usage(request) print('The table usage information for: ' + table_name) for record in result.get_usage_records(): print('\t' + str(record)) # # Drop the table # if drop_table: request = TableRequest().set_statement('drop table if exists ' + table_name) result = handle.table_request(request) # # Table drop can take time, depending on the state of the system. # If this wait fails the table will still probably been dropped # result.wait_for_state(handle, table_name, State.DROPPED, 30000, 2000) print('After drop table') else: print('Not dropping table') print('Example is complete') except Exception as e: print(e) traceback.print_exc() finally: # If the handle isn't closed Python will not exit properly if handle is not None: handle.close()
def main(): handle = None try: # # Create a handle # handle = get_handle(tenant_id) # # List any existing tables for this tenant # print('Listing tables') ltr = ListTablesRequest() lr_result = handle.list_tables(ltr) print('Existing tables: ' + str(lr_result)) # # Create a table # statement = 'Create table if not exists ' + table_name + '(id integer, \ sid integer, name string, primary key(shard(sid), id))' print('Creating table: ' + statement) request = TableRequest().set_statement(statement).set_table_limits( TableLimits(30, 10, 1)) handle.do_table_request(request, 40000, 3000) print('After create table') # # Create an index # statement = ('Create index if not exists ' + index_name + ' on ' + table_name + '(name)') print('Creating index: ' + statement) request = TableRequest().set_statement(statement) handle.do_table_request(request, 40000, 3000) print('After create index') # # Get the table # request = GetTableRequest().set_table_name(table_name) result = handle.get_table(request) print('After get table: ' + str(result)) # # Get the indexes # request = GetIndexesRequest().set_table_name(table_name) result = handle.get_indexes(request) print('The indexes for: ' + table_name) for idx in result.get_indexes(): print('\t' + str(idx)) # # Get the table usage information, on-prem mode not supported # if not using_on_prem: request = TableUsageRequest().set_table_name(table_name) result = handle.get_table_usage(request) print('The table usage information for: ' + table_name) for record in result.get_usage_records(): print('\t' + str(record)) # # Drop the index # request = TableRequest().set_statement( 'drop index ' + index_name + ' on ' + table_name) handle.do_table_request(request, 30000, 2000) print('After drop index') # # Drop the table # if drop_table: request = TableRequest().set_statement( 'drop table if exists ' + table_name) handle.do_table_request(request, 30000, 2000) print('After drop table') else: print('Not dropping table') print('Example is complete') except Exception as e: print(e) traceback.print_exc() finally: # If the handle isn't closed Python will not exit properly if handle is not None: handle.close()