Exemplo n.º 1
0
def bin_setup(chr, adir, bdir, context):
    am = MethylGroup(adir)[chr]
    bm = MethylGroup(bdir)[chr]
    return am.as_context(context), bm.as_context(context)
def bin_setup(chr, adir, bdir, context):
    am = MethylGroup(adir)[chr]
    bm = MethylGroup(bdir)[chr]
    return am.as_context(context), bm.as_context(context)
import sys
import os.path as op
sys.path.insert(0, "/home/brentp/src/methylcode/methylcoder/")

from methyl import MethylGroup
prefix = sys.argv[1] # something like: out1234n/thaliana_v9
acontext = sys.argv[2] # CHH or CHG or CG
window = 50

script = op.basename(sys.argv[0])

mg = MethylGroup(prefix)


fh = open(mg.dir + mg.prefix + ".test.%ibp.%s.gff" % (window, acontext), "w")
print >>sys.stderr, "writing to %s" % (fh.name, )
print >>fh, "##gff-version 3"
sys.argv[1] = op.abspath(sys.argv[1])
print >>fh, "#%s" % " ".join(sys.argv)

for chr, m in mg.iteritems():
    
    cs, ts, mask = m.as_context(acontext)
    bp_max = len(ts)
    for start in range(0, bp_max + 1, window):
        end = min(start + window, bp_max)
        t_count = ts[start:end].sum()
        c_count = cs[start:end].sum()

        n = mask[start:end].sum()
Exemplo n.º 4
0
import sys
import os.path as op
sys.path.insert(0, op.join(op.dirname(__file__), "../code"))
from methyl import MethylGroup
mg = MethylGroup(sys.argv[1])
contexts = ('CG', 'CHG', 'CHH')

print "#", mg.prefix, mg.dir, mg.pattern

total_cs = dict((ctx, 0) for ctx in contexts)
total_ts = dict((ctx, 0) for ctx in contexts)

M = dict((ctx, 0) for ctx in contexts)
P = dict((ctx, 0) for ctx in contexts)

print "seqid,context,p_methylated,total_possible_sites,possible_sites_covered_by_reads,cs,ts,cs/(cs + ts)"
for seqid, meth in mg.iteritems():
    for context in contexts:
        if seqid in 'CcMm': continue
        cg_cs, cg_ts, cg_mask = meth.as_context(context)
        total_sites = cg_mask.sum()
        mask = (cg_cs + cg_ts) > 0
        cg_cs = cg_cs[mask]
        cg_ts = cg_ts[mask]
        cg_mask = cg_mask[mask]
        methylation = cg_cs.astype('f') / (cg_ts + cg_cs)
        n_methylated = (cg_cs > 0).sum()
        possible_methylated = cg_mask.sum()
        P[context] += possible_methylated
        M[context] += n_methylated
        proportion_methylated = float(n_methylated) / possible_methylated
Exemplo n.º 5
0
import sys
import os.path as op

sys.path.insert(0, "/home/brentp/src/methylcode/methylcoder/")

from methyl import MethylGroup

prefix = sys.argv[1]  # something like: out1234n/thaliana_v9
acontext = sys.argv[2]  # CHH or CHG or CG
window = 50

script = op.basename(sys.argv[0])

mg = MethylGroup(prefix)

fh = open(mg.dir + mg.prefix + ".test.%ibp.%s.gff" % (window, acontext), "w")
print >> sys.stderr, "writing to %s" % (fh.name, )
print >> fh, "##gff-version 3"
sys.argv[1] = op.abspath(sys.argv[1])
print >> fh, "#%s" % " ".join(sys.argv)

for chr, m in mg.iteritems():

    cs, ts, mask = m.as_context(acontext)
    bp_max = len(ts)
    for start in range(0, bp_max + 1, window):
        end = min(start + window, bp_max)
        t_count = ts[start:end].sum()
        c_count = cs[start:end].sum()

        n = mask[start:end].sum()
import sys
import os.path as op
sys.path.insert(0, op.join(op.dirname(__file__), "../code"))
from methyl import MethylGroup
mg = MethylGroup(sys.argv[1])
contexts = ('CG', 'CHG', 'CHH')

 
print "#", mg.prefix, mg.dir, mg.pattern
 
total_cs = dict((ctx, 0) for ctx in contexts)
total_ts = dict((ctx, 0) for ctx in contexts)

M = dict((ctx, 0) for ctx in contexts)
P = dict((ctx, 0) for ctx in contexts)

print "seqid,context,p_methylated,total_possible_sites,possible_sites_covered_by_reads,cs,ts,cs/(cs + ts)"
for seqid, meth in mg.iteritems():
    for context in contexts:
        if seqid in 'CcMm': continue
        cg_cs, cg_ts, cg_mask = meth.as_context(context)
        total_sites = cg_mask.sum()
        mask = (cg_cs + cg_ts) > 0
        cg_cs = cg_cs[mask]
        cg_ts = cg_ts[mask]
        cg_mask = cg_mask[mask]
        methylation = cg_cs.astype('f') / (cg_ts + cg_cs)
        n_methylated = (cg_cs > 0).sum()
        possible_methylated = cg_mask.sum()
        P[context] += possible_methylated
        M[context] += n_methylated