Ejemplo n.º 1
0
def expand_row(row):
    """Parse a BED row.

    Args:
        List[str]: BED row

    Returns:
        dict: formatted BED row as a dict

    Raises:
        BedFormattingError: failure to parse first three columns
    """
    try:
        data = {
            'chrom': row[0],
            'chromStart': int(row[1]),
            'chromEnd': int(row[2])
        }
    except IndexError:
        raise BedFormattingError('make sure fields are tab-separated')
    except ValueError:
        raise BedFormattingError("positions malformatted: {}".format(row))

    try:
        data['score'] = int(list_get(row, 4))
    except ValueError:
        raise BedFormattingError('invalid BED syntax, score column is int')

    data['name'] = list_get(row, 3)
    data['strand'] = list_get(row, 5)
    element_combos = extra_fields(row[6:8])
    data['elements'] = element_combos
    data['extra_fields'] = row[8:]
    return data
Ejemplo n.º 2
0
def expand_row(row):
    """Parse a BED row.

    Args:
        List[str]: BED row

    Returns:
        dict: formatted BED row as a dict

    Raises:
        BedFormattingError: failure to parse first three columns
    """
    try:
        data = {"chrom": row[0], "chromStart": int(row[1]), "chromEnd": int(row[2])}
    except IndexError:
        raise BedFormattingError("make sure fields are tab-separated")
    except ValueError:
        raise BedFormattingError("positions malformatted: {}".format(row))

    try:
        data["score"] = int(list_get(row, 4))
    except ValueError:
        raise BedFormattingError("invalid BED syntax, score column is int")

    data["name"] = list_get(row, 3)
    data["strand"] = list_get(row, 5)
    element_combos = extra_fields(row[6:8])
    data["elements"] = element_combos
    data["extra_fields"] = row[8:]
    return data
Ejemplo n.º 3
0
 def completeness_levels(self):
     """Return a list of included completeness levels."""
     metrics = (self.query(ExonStatistic.metric).distinct(
         ExonStatistic.metric))
     # for all completeness levels, extract the level as int and full name
     levels = ((int(field[0].split('_')[-1]), field[0]) for field in metrics
               if field[0].startswith('completeness'))
     # sort them based on the level int
     sorted_levels = sorted(levels, key=lambda level: list_get(level, 0))
     return sorted_levels
Ejemplo n.º 4
0
 def completeness_levels(self):
     """Return a list of included completeness levels."""
     metrics = (self.query(ExonStatistic.metric)
                    .distinct(ExonStatistic.metric))
     # for all completeness levels, extract the level as int and full name
     levels = ((int(field[0].split('_')[-1]), field[0])
               for field in metrics
               if field[0].startswith('completeness'))
     # sort them based on the level int
     sorted_levels = sorted(levels, key=lambda level: list_get(level, 0))
     return sorted_levels