https://github.com/fjruizruano/ngs-protocols
Raw File
Tip revision: 39a091d1fa569a7fc717ac73c4b3de07f0a1204d authored by fjruizruano on 03 August 2023, 11:48:27 UTC
adding gfa2fas.py and extract_gfa.py
Tip revision: 39a091d
divnuc_plot.py
#!/usr/bin/python

import sys

print "Usage: divnuc_plot.py DivNucFile WindowSize"

try:
    file = sys.argv[1]
except:
    file = raw_input("Introduce DivNuc file: ")

try:
    win = sys.argv[2]
except:
    win = raw_input("Introduce Window Size (integer): ")

try:
    win = int(win)
except:
    print "Please, introduce an integer as Window Size"

def average(l):
    av = reduce(lambda x,y:x+y,l)/len(l)
    return av

data = open(file).readlines()

w = open(file+".plot."+str(win), "w")

for n in range(0,len(data)/win):
    subset = data[n*win:(n*win)+win]
    cov = []
    div = []
    for pos in subset:
        pos = pos.split()
        cov.append(int(pos[2]))
        div.append(float(pos[10]))
    w.write("%s\t%s\t%s\n" % (str(n*win),str(average(cov)),str(average(div))))

w.close()
back to top