Beispiel #1
0
def getRawAlignments(fn):
    '''fn is the filename
       returns An iterator over raw M4Records'''
    itemIterator = lambda f : lineRecordIterator(f, M4Record, M4RecordTypes)
    return fileIterator(fn, itemIterator)
Beispiel #2
0
if not len(sys.argv) > 1:
    sys.exit(getHelpStr(description, arguments) + "\n")

(p_arg_map, args_remaining) = parseArgs(sys.argv[1:], arguments)

if not len(args_remaining) == 2:
    sys.exit(getHelpStr(description, arguments) + "\n")

igetter = attrgetter("pctsimilarity", "qseqlength")

mpl.rc('font', family='normal', weight="normal", size=10)
mpl.rc('xtick', labelsize=5)
mpl.rc('ytick', labelsize=5)

with open(args_remaining[1]) as fh:
    records = lineRecordIterator(fh, M4Record, M4RecordTypes)
    items = map(igetter, records)
    (pctids, lens) = zip(*items)

    pp = PdfPages("out.pdf")

    (fig, axScatter) = plt.subplots(figsize=(8.5, 5.5))
    axScatter.scatter(lens, pctids, color="blue", s=0.001)
    axScatter.set_xticks(range(0, 80000, 2000))
    axScatter.set_yticks(range(0, 100, 5))
    fig.suptitle(args_remaining[0])
    plt.xlabel("Read Length (bp)")
    plt.ylabel("Alignment Identity (%)")

    divider = make_axes_locatable(axScatter)
    axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
Beispiel #3
0
argument_list = [["span","span", argflag, False, "Only alignments that span the region"]]

arguments = map(CLArgument._make, argument_list)

(p_arg_map, args_remaining) = parseArgs(sys.argv[1:], arguments)

if not len(args_remaining) == 2:
    sys.exit(getHelpStr(description,arguments) + "\n")


inm4 = args_remaining[0]
(chrom, rest) = args_remaining[1].split(":")
(start,end) = map(int,rest.split("-"))

it = lambda fh : lineRecordIterator(fh, M4Record, M4RecordTypes)

cond = lambda r : r.tname == chrom and not r.tend < start and not r.tstart > end
if p_arg_map["span"]:
    cond = lambda r : r.tname == chrom and r.tstart < start and r.tend > end

filt_records = ifilter(cond,fileIterator(inm4, it))

for r in imap(recordToString, filt_records):
    print r





Beispiel #4
0
def getRawAlignments(fn):
    '''fn is the filename
       returns An iterator over raw M4Records'''
    itemIterator = lambda f: lineRecordIterator(f, M4Record, M4RecordTypes)
    return fileIterator(fn, itemIterator)
Beispiel #5
0
args = map(CLArgument._make, argument_list)

(parg_map, args_remaining) = parseArgs(sys.argv[1:],args)

if not len(args_remaining) >= 3:
    sys.exit(getHelpStr(description,args) + "\n")

title = args_remaining[0]
igetter = attrgetter("qseqlength")

flens = []
for fname in args_remaining[1:]:
    with open(fname) as fh:
        if parg_map["lenfiles"] < 0:
            records = lineRecordIterator(fh, M4Record, M4RecordTypes)
            flens.append( map(igetter, records) )
        else:
            getter = itemgetter(parg_map["lenfiles"])
            flens.append( map(int, imap(getter, lineItemIterator(fh) )))

pp = PdfPages("hist.pdf")
fig = plt.figure()
fig.suptitle(args_remaining[0])
len_binsize = 250

plt.xlabel("Read Length")
plt.ylabel("Frequency")

if parg_map["ymax"] > 0:
    plt.ylim(1,parg_map["ymax"])
Beispiel #6
0
from args import parseArgs, getHelpStr, argflag, CLArgument

description = ("Usage: m4region.py [options] input.m4 chr:start-end\n"
               "Returns alignments that touch a region\n")

argument_list = [[
    "span", "span", argflag, False, "Only alignments that span the region"
]]

arguments = map(CLArgument._make, argument_list)

(p_arg_map, args_remaining) = parseArgs(sys.argv[1:], arguments)

if not len(args_remaining) == 2:
    sys.exit(getHelpStr(description, arguments) + "\n")

inm4 = args_remaining[0]
(chrom, rest) = args_remaining[1].split(":")
(start, end) = map(int, rest.split("-"))

it = lambda fh: lineRecordIterator(fh, M4Record, M4RecordTypes)

cond = lambda r: r.tname == chrom and not r.tend < start and not r.tstart > end
if p_arg_map["span"]:
    cond = lambda r: r.tname == chrom and r.tstart < start and r.tend > end

filt_records = ifilter(cond, fileIterator(inm4, it))

for r in imap(recordToString, filt_records):
    print r