def load_scores_wiggle(fname, chrom_buffer_size=3):
    """
    Read a wiggle file and return a dict of BinnedArray objects keyed
    by chromosome.
    """
    scores_by_chrom = dict()
    try:
        for chrom, pos, val in bx.wiggle.Reader(UCSCOutWrapper(open(fname))):
            if chrom not in scores_by_chrom:
                if chrom_buffer_size:
                    scores_by_chrom[chrom] = BinnedArray()
                    chrom_buffer_size -= 1
                else:
                    scores_by_chrom[chrom] = PositionalScoresOnDisk()
            scores_by_chrom[chrom][pos] = val
    except UCSCLimitException:
        # Wiggle data was truncated, at the very least need to warn the user.
        print(
            'Encountered message from UCSC: "Reached output limit of 100000 data values", so be aware your data was truncated.'
        )
    except IndexError:
        stop_err(
            'Data error: one or more column data values is missing in "%s"' %
            fname)
    except ValueError:
        stop_err(
            'Data error: invalid data type for one or more values in "%s".' %
            fname)
    return scores_by_chrom
예제 #2
0
def main():
    if len(sys.argv) > 1:
        in_file = open(sys.argv[1])
    else:
        in_file = open(sys.stdin)

    if len(sys.argv) > 2:
        out_file = open(sys.argv[2], "w")
    else:
        out_file = sys.stdout

    try:
        for fields in bx.wiggle.IntervalReader(UCSCOutWrapper(in_file)):
            out_file.write("%s\n" % "\t".join(map(str, fields)))
    except UCSCLimitException:
        # Wiggle data was truncated, at the very least need to warn the user.
        print(
            'Encountered message from UCSC: "Reached output limit of 100000 data values", so be aware your data was truncated.'
        )
    except ValueError as e:
        in_file.close()
        out_file.close()
        stop_err(str(e))

    in_file.close()
    out_file.close()
예제 #3
0
def main():
    with open(sys.argv[1]) as in_file, open(sys.argv[2], "w") as out_file:
        try:
            for fields in bx.wiggle.IntervalReader(UCSCOutWrapper(in_file)):
                out_file.write("%s\n" % "\t".join(map(str, fields)))
        except UCSCLimitException:
            # Wiggle data was truncated, at the very least need to warn the user.
            sys.stderr.write(
                'Encountered message from UCSC: "Reached output limit of 100000 data values", so be aware your data was truncated.'
            )