Returns a table containing the column percents made from a source table, after first calculating the counts
cross-tabulated from the given columns
17114
public static Table columnPercents(Table table, CategoricalColumn<?> column1, CategoricalColumn<?> column2) {
        Table xTabs = counts(table, column1, column2);
        return columnPercents(xTabs);
    }
1212242
public static Table tablePercents(Table table, String column1, String column2) {
        return tablePercents(table, table.categoricalColumn(column1), table.categoricalColumn(column2));
    }
1283620
def get_columns_of_table(self, table=None):
        """"""
        # Check the table exists #
        if table is None: table = self.main_table
        if not table in self.tables: return []
        # A PRAGMA statement will implicitly issue a commit, don't use #
        self.own_cursor.execute('SELECT * from "%s" LIMIT 1;' % table)
        columns = [x[0] for x in self.own_cursor.description]
        self.cursor.fetchall()
        return columns
371357
def _convert_md_table_to_rst(table):
    """"""
    if len(table) < 3:
        return ''
    out = '```eval_rst\n.. list-table::\n   :header-rows: 1\n\n'
    for i,l in enumerate(table):
        cols = l.split('|')[1:-1]
        if i == 0:
            ncol = len(cols)
        else:
            if len(cols) != ncol:
                return ''
        if i == 1:
            for c in cols:
                if len(c) is not 0 and '---' not in c:
                    return ''
        else:
            for j,c in enumerate(cols):
                out += '   * - ' if j == 0 else '     - '
                out += pypandoc.convert_text(
                    c, 'rst', format='md').replace('\n', ' ').replace('\r', '') + '\n'
    out += '```\n'
    return out
1088665
def tophat_general_stats_table(self):
        

        headers = OrderedDict()
        headers['overall_aligned_percent'] = {
            'title': '% Aligned',
            'description': 'overall read mapping rate',
            'max': 100,
            'min': 0,
            'suffix': '%',
            'scale': 'YlGn'
        }
        headers['aligned_not_multimapped_discordant'] = {
            'title': '{} Aligned'.format(config.read_count_prefix),
            'description': 'Aligned reads, not multimapped or discordant ({})'.format(config.read_count_desc),
            'min': 0,
            'scale': 'PuRd',
            'modify': lambda x: x * config.read_count_multiplier,
            'shared_key': 'read_count'
        }
        self.general_stats_addcols(self.tophat_data, headers)
752617
def hicpro_stats_table(self):
         
         headers = OrderedDict()

         headers['percent_duplicates'] = {
             'title': '% Duplicates',
             'description': 'Percent of duplicated valid pairs (%)',
             'max': 100,
             'min': 0,
             'suffix': '%',
             'scale': 'YlOrRd',
             'hidden': True
         }
            
         headers['valid_interaction_rmdup'] = {
             'title': '{} Valid Pairs Unique'.format(config.read_count_prefix),
             'description': 'Number of valid pairs after duplicates removal ({})'.format(config.read_count_desc),
             'min': 0,
             'scale': 'RdYlBu',
             'modify': lambda x: x * config.read_count_multiplier,
             'shared_key': 'read_count',
         }
                 
         headers['percent_valid'] = {
             'title': '% Valid Pairs',
             'description': 'Percentage of valid pairs over reported ones (%)',
             'max': 100,
             'min': 0,
             'suffix': '%',
             'scale': 'YlGn',
             'hidden': True
         }

         headers['valid_interaction'] = {
             'title': '{} Valid Pairs'.format(config.read_count_prefix),
             'description': 'Number of valid pairs ({})'.format(config.read_count_desc),
             'min': 0,
             'scale': 'RdYlBu',
             'modify': lambda x: x * config.read_count_multiplier,
             'shared_key': 'read_count',
             'hidden': True
         }
 
         headers['percent_paired_reads'] = {
             'title': '% Reported',
             'description': 'Percentage of paired reads (%) passing the mapping filters',
             'max': 100,
             'min': 0,
             'suffix': '%',
             'scale': 'YlGn',
             'hidden': True
         }

         headers['paired_reads'] = {
             'title': 'Reported Read Pairs',
             'description' : 'Total number of read pairs ({}) passing the mapping filters'.format(config.read_count_desc),
             'min' : '0',
             'scale' : 'RdYlBu',
             'modify': lambda x: x * config.read_count_multiplier,
             'shared_key' : 'read_count',
         }

         headers['percent_mapped_R2'] = {
             'title': '% Aligned [R2]',
             'description': 'Percentage of aligned reads [R2] (%)',
             'max': 100,
             'min': 0,
             'suffix': '%',
             'scale': 'YlGn',
             'hidden': True
         }

         headers['mapped_R2'] = {
             'title': 'Aligned [R2]',
             'description' : 'Total number of aligned reads [R2] ({})'.format(config.read_count_desc),
             'min' : '0',
             'scale' : 'RdYlBu',
             'modify': lambda x: x * config.read_count_multiplier,
             'shared_key' : 'read_count',
             'hidden': True
         }

         headers['percent_mapped_R1'] = {
             'title': '% Aligned [R1]',
             'description': 'Percentage of aligned reads [R1] (%)',
             'max': 100,
             'min': 0,
             'suffix': '%',
             'scale': 'YlGn',
             'hidden': True
         }

         headers['mapped_R1'] = {
             'title': 'Aligned [R1]',
             'description' : 'Total number of aligned reads [R1] ({})'.format(config.read_count_desc),
             'min' : '0',
             'scale' : 'RdYlBu',
             'modify': lambda x: x * config.read_count_multiplier,
             'shared_key' : 'read_count',
             'hidden': True
         }
         
         headers['total_R1'] = {
             'title': 'Total',
             'description' : 'Total Number of Read Pairs',
             'min' : '0',
             'scale' : 'RdYlBu',
             'modify': lambda x: x * config.read_count_multiplier,
             'shared_key' : 'read_count',
         }

         self.general_stats_addcols(self.hicpro_data, headers, 'HiC-Pro')
1207835
def load_eidos_curation_table():
    """"""
    url = 'https://raw.githubusercontent.com/clulab/eidos/master/' + \
        'src/main/resources/org/clulab/wm/eidos/english/confidence/' + \
        'rule_summary.tsv'
    # Load the table of scores from the URL above into a data frame
    res = StringIO(requests.get(url).text)
    table = pandas.read_table(res, sep='\t')
    # Drop the last "Grant total" row
    table = table.drop(table.index[len(table)-1])
    return table
314126
def _get_stats_columns(cls, table, relation_type):
        
        column_names = cls._get_stats_column_names()

        # agate does not handle the array of column names gracefully
        clustering_value = None
        if table.clustering_fields is not None:
            clustering_value = ','.join(table.clustering_fields)
        # cast num_bytes/num_rows to str before they get to agate, or else
        # agate will incorrectly decide they are booleans.
        column_values = (
            'Number of bytes',
            str(table.num_bytes),
            'The number of bytes this table consumes',
            relation_type == 'table',

            'Number of rows',
            str(table.num_rows),
            'The number of rows in this table',
            relation_type == 'table',

            'Location',
            table.location,
            'The geographic location of this table',
            True,

            'Partitioning Type',
            table.partitioning_type,
            'The partitioning type used for this table',
            relation_type == 'table',

            'Clustering Fields',
            clustering_value,
            'The clustering fields for this table',
            relation_type == 'table',
        )
        return zip(column_names, column_values)
362240
def _get_select_commands(self, source, tables):
        
        # Create dictionary of select queries
        row_queries = {tbl: self.select_all(tbl, execute=False) for tbl in
                       tqdm(tables, total=len(tables), desc='Getting {0} select queries'.format(source))}

        # Convert command strings into lists of commands
        for tbl, command in row_queries.items():
            if isinstance(command, str):
                row_queries[tbl] = [command]

        # Pack commands into list of tuples
        return [(tbl, cmd) for tbl, cmds in row_queries.items() for cmd in cmds]
737790
def extract_columns_from_table_definition_file(xmltag, table_definition_file):
    
    def handle_path(path):
        """Convert path from a path relative to table-definition file."""
        if not path or path.startswith("http://") or path.startswith("https://"):
            return path
        return os.path.join(os.path.dirname(table_definition_file), path)

    columns = list()
    for c in xmltag.findall('column'):
        scale_factor = c.get("scaleFactor")
        display_unit = c.get("displayUnit")
        source_unit = c.get("sourceUnit")

        new_column = Column(c.get("title"), c.text, c.get("numberOfDigits"),
                   handle_path(c.get("href")), None, display_unit, source_unit,
                   scale_factor, c.get("relevantForDiff"), c.get("displayTitle"))
        columns.append(new_column)

    return columns
1119358
def htseq_stats_table(self):
        

        headers = OrderedDict()
        headers['percent_assigned'] = {
            'title': '% Assigned',
            'description': '% Assigned reads',
            'max': 100,
            'min': 0,
            'suffix': '%',
            'scale': 'RdYlGn'
        }
        headers['assigned'] = {
            'title': '{} Assigned'.format(config.read_count_prefix),
            'description': 'Assigned Reads ({})'.format(config.read_count_desc),
            'min': 0,
            'scale': 'PuBu',
            'modify': lambda x: float(x) * config.read_count_multiplier,
            'shared_key': 'read_count'
        }
        self.general_stats_addcols(self.htseq_data, headers)
1283703
def conpair_general_stats_table(self):
        

        headers = {}
        headers['concordance_concordance'] = {
            'title': 'Concordance',
            'max': 100,
            'min': 0,
            'suffix': '%',
            'format': '{:,.2f}',
            'scale': 'RdYlGn'
        }
        headers['contamination_normal'] = {
            'title': 'N Contamination',
            'description': 'Normal sample contamination level',
            'max': 100,
            'min': 0,
            'suffix': '%',
            'format': '{:,.3f}',
            'scale': 'RdYlBu-rev'
        }
        headers['contamination_tumor'] = {
            'title': 'T Contamination',
            'description': 'Tumor sample contamination level',
            'max': 100,
            'min': 0,
            'suffix': '%',
            'format': '{:,.3f}',
            'scale': 'RdYlBu-rev'
        }
        self.general_stats_addcols(self.conpair_data, headers)
1168360
def table_from_data(data, column_names):
    ""

    # The agate table is generated from a list of dicts, so the column order
    # from `data` is not preserved. We can use `select` to reorder the columns
    #
    # If there is no data, create an empty table with the specified columns

    if len(data) == 0:
        return agate.Table([], column_names=column_names)
    else:
        table = agate.Table.from_object(data, column_types=DEFAULT_TYPE_TESTER)
        return table.select(column_names)
305314
def calc_flex(self, data, max_width, cols, preformatted=None):
        
        if preformatted is None:
            preformatted = []
        colstats = []
        for i in cols:
            lengths = [len(xx) for x in data
                       for xx in x[i].text().splitlines()]
            if self.headers:
                lengths.append(len(self.headers[i]))
            lengths.append(self.width_normalize(self.colspec[i]['minwidth']))
            counts = collections.Counter(lengths)
            colstats.append({
                "column": i,
                "preformatted": i in preformatted,
                "counts": counts,
                "offt": max(lengths),
                "chop_mass": 0,
                "chop_count": 0,
                "total_mass": sum(a * b for a, b in counts.items())
            })
        self.adjust_widths(max_width, colstats)
        required = sum(x['offt'] for x in colstats)
        justify = self.table.justify if self.table.justify is not None else \
            self.justify_default
        if required < max_width and justify:
            # Fill remaining space proportionately.
            remaining = max_width
            for x in colstats:
                x['offt'] = int((x['offt'] / required) * max_width)
                remaining -= x['offt']
            if remaining:
                dist = self._uniform_dist(len(cols), remaining)
                for adj, col in zip(dist, colstats):
                    col['offt'] += adj
        return [(x['column'], x['offt']) for x in colstats]
1033755
def to_tables(cols):
  
  tables = OrderedDict()
  for col in cols:
    tname = col["table_name"]
    if tname not in tables:
      tables[tname] = OrderedDict()
    tables[tname][col["column_name"]] = col
  return tables
1207518
def create_tables(name, runSetResults, rows, rowsDiff, outputPath, outputFilePattern, options):
    '''
    
    '''

    # get common folder of sourcefiles
    common_prefix = os.path.commonprefix([r.filename for r in rows]) # maybe with parts of filename
    common_prefix = common_prefix[: common_prefix.rfind('/') + 1] # only foldername
    for row in rows:
        Row.set_relative_path(row, common_prefix, outputPath)

    # compute nice name of each run set for displaying
    firstBenchmarkName = Util.prettylist(runSetResults[0].attributes['benchmarkname'])
    allBenchmarkNamesEqual = all(Util.prettylist(r.attributes['benchmarkname']) == firstBenchmarkName for r in runSetResults)
    for r in runSetResults:
        if not r.attributes['name']:
            r.attributes['niceName'] = r.attributes['benchmarkname']
        elif allBenchmarkNamesEqual:
            r.attributes['niceName'] = r.attributes['name']
        else:
            r.attributes['niceName'] = [Util.prettylist(r.attributes['benchmarkname']) + '.' + Util.prettylist(r.attributes['name'])]

    template_values = lambda: None # dummy object as dict replacement for simpler syntax
    template_values.head = get_table_head(runSetResults, common_prefix)
    template_values.run_sets = [runSetResult.attributes for runSetResult in runSetResults]
    template_values.columns = [[column for column in runSet.columns] for runSet in runSetResults]
    template_values.columnTitles =\
        [[column.format_title() for column in runSet.columns] for runSet in runSetResults]

    template_values.relevant_id_columns = select_relevant_id_columns(rows)
    template_values.count_id_columns = template_values.relevant_id_columns.count(True)

    template_values.lib_url = options.lib_url
    template_values.base_dir = outputPath
    template_values.href_base = os.path.dirname(options.xmltablefile) if options.xmltablefile else None
    template_values.version = __version__

    futures = []

    def write_table(table_type, title, rows, use_local_summary):
        # calculate statistics if necessary
        if not options.format == ['csv']:
            local_summary = get_summary(runSetResults) if use_local_summary else None
            stats, stats_columns = get_stats(rows, local_summary, options.correct_only)
        else:
            stats = stats_columns = None

        for template_format in (options.format or TEMPLATE_FORMATS):
            if outputFilePattern == '-':
                outfile = None
                logging.info('Writing %s to stdout...', template_format.upper().ljust(4))
            else:
                outfile = os.path.join(outputPath, outputFilePattern.format(name=name, type=table_type, ext=template_format))
                logging.info('Writing %s into %s ...', template_format.upper().ljust(4), outfile)

            this_template_values = dict(title=title, body=rows, foot=stats, foot_columns=stats_columns)
            this_template_values.update(template_values.__dict__)

            futures.append(parallel.submit(
                write_table_in_format,
                template_format, outfile, this_template_values,
                options.show_table and template_format == 'html',
                ))

    # write normal tables
    write_table("table", name, rows,
                use_local_summary=(not options.correct_only and not options.common))

    # write difference tables
    if rowsDiff:
        write_table("diff", name + " differences", rowsDiff, use_local_summary=False)

    return futures
62057
def getcolslice(self, blc, trc, inc=[], startrow=0, nrow=-1, rowincr=1):
        """"""
        return self._table.getcolslice(self._column, blc, trc, inc, startrow, nrow, rowincr)