view ratio2circos.py @ 2:f923c54a17ee draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/freec commit 30718e775cd7cd2a7746608a0c99e86521cf8d7b"
author iuc
date Sat, 13 Nov 2021 18:28:40 +0000
parents 2c6349fb175c
children
line wrap: on
line source

import math
import sys

ploidy = int(sys.argv[1])

with open("./output/sample.bam_ratio.BedGraph") as bed:
    with open("./output/sample.bam_ratio_log2_circos.txt", "w+") as olog2r:
        for line in bed.readlines():
            ls = line.split()
            if ls[0] != "track" and float(ls[3]) > 0:
                log2_ratio = math.log2(float(ls[3]) / ploidy)
                olog2r.write("{}\t{}\t{}\t{}\n".format(ls[0], ls[1], ls[2], log2_ratio))

with open("./genome.fa.fai") as fai:
    with open("./output/karyotype_circos.txt", "w+") as ochr:
        for line in fai.readlines():
            ls = line.split()
            ochr.write("chr - {}\t{}\t0\t{}\t{}\n".format(ls[0], ls[0].strip("chr").lower(), ls[1], ls[0]))