view ratio2circos.py @ 0:e46944a59b31 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/freec commit bec4fb59dc4776d33c2ce8c0bd614c90e5d4ecb2"
author iuc
date Thu, 13 Aug 2020 09:50:35 -0400
parents
children 2c6349fb175c
line wrap: on
line source

import argparse
import math
import os

parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', required=True, default='./output/sample.bam_ratio.BedGraph', type=str)
parser.add_argument('-o', '--output', required=True, default='./output/sample.bam_ratio_log2_circos.txt', type=str)
parser.add_argument('-p', '--ploidy', required=True, default=2, type=int)
args = parser.parse_args()

path = os.path.dirname(args.input)
output = os.path.join(path, args.output)

with open(args.input) as file:
    for line in file.readlines():
        ls = line.split()
        if ls[0] != "track" and float(ls[3]) > 0:
            log2_ratio = math.log2(float(ls[3]) / args.ploidy)
            with open(output, "a") as out:
                out.write("{}\t{}\t{}\t{}\n".format(ls[0], ls[1], ls[2], log2_ratio))