def test_calccumsum_00_file(): data = loadfile(TESTDIR + "test00.21") cn, c1, yd, yo, zd, zo = calccumsum(data) assert_equal(cn, 1) assert_equal(c1, 1) assert_equal(yd, 1) assert_equal(yo, 1) assert_equal(zd, 1) assert_equal(zo, 1)
def main(filename, opt=6, label=None, n=0, opts=None, colorlist=[], stylelist=None): '''loads file and invokes makegraphs and printstats. Appends graphics from each file onto the figure. opt is a symbol for the graph type; n is the serial number of successful traces.''' logfh = open(opts["logfile"], "a") if opts["filetype"].upper() == "MGM": spectrum = getmgrkmerspectrum(filename, mgrkey=MGRKEY) elif opts["filetype"] == "file": spectrum = loadfile(filename) else: raise ValueError( "%s is invalid type (valid types are mgm and file)" % opts.filetype) if spectrum == []: # Abort this trace--but try to graph the others return n if label is None: label = filename if spectrum.shape[1] > 0: spectrum = spectrum[np.lexsort((spectrum[:, 1], spectrum[:, 0]))] sys.stderr.write("Making graphs for %s\n" % filename) try: makegraphs( spectrum, filename, option=opt, label=label, n=n, dump=opts["dump"], opts=opts, colorlist=colorlist, stylelist=stylelist) # sys.stderr.write("Printing stats in logfile %s %d\n" % # (opts.logfile, n)) printstats(spectrum, filename, filehandle=logfh, n=n) n += 1 except ValueError as err: # This catches no data or defective data sys.stderr.write("Error printing stats for %s\n" % filename) else: sys.stderr.write("Error with dataset %s\n" % filename) return n
def main(filename, opt=6, label=None, n=0, opts=None, colorlist=[], stylelist=None): '''loads file and invokes makegraphs and printstats. Appends graphics from each file onto the figure. opt is a symbol for the graph type; n is the serial number of successful traces.''' logfh = open(opts.logfile, "a") if opts.filetype.upper() == "MGM": spectrum = getmgrkmerspectrum(filename, mgrkey=MGRKEY) elif opts.filetype == "file": spectrum = loadfile(filename) else: raise ValueError( "%s is invalid type (valid types are mgm and file)" % opts.filetype) if spectrum == []: # Abort this trace--but try to graph the others return n if label is None: label = filename if spectrum.shape[1] > 0: spectrum = spectrum[np.lexsort((spectrum[:, 1], spectrum[:, 0]))] sys.stderr.write("Making graphs for %s\n" % filename) try: makegraphs( spectrum, filename, option=opt, label=label, n=n, dump=opts.dump, opts=opts, colorlist=colorlist, stylelist=stylelist) # sys.stderr.write("Printing stats in logfile %s %d\n" % # (opts.logfile, n)) printstats(spectrum, filename, filehandle=logfh, n=n) n += 1 except ValueError as err: # This catches no data or defective data sys.stderr.write("Error printing stats for %s\n" % filename) else: sys.stderr.write("Error with dataset %s\n" % filename) return n
# Loop over input identifiers, and skip if main() # fails to produce some traces spectra = [] labels = [] if opts.filelist: if not os.path.isfile(opts.filelist): sys.exit("File {} does not exist".format(opts.filelist)) IN_FILE = open(opts.filelist, "r") for line in IN_FILE: if line[0] != "#": a = line.strip().split("\t") if len(a[0]) > 0: if len(a) == 1: a.append(a[0]) sys.stderr.write("%s\t%s\n" % (a[0], a[1])) contents = loadfile(a[0]) if contents != []: spectra.append(contents) labels.append(a[1]) if opts.option == 0: plotstratifiedfracs(labels, spectra) elif opts.option == 1: plotstratifiedsizes(labels, spectra) elif opts.option == -1: summarizestrata(labels, spectra) sys.exit() else: sys.exit("Valid graph types are -g 0, 1, and -1") if opts.interactive: sys.stderr.write("Interactive mode (no file output)\n") plt.show()
"File {} does not exist".format(listfile) IN_FILE = open(listfile, "r").readlines() numplots = len(IN_FILE) for line in IN_FILE: if line[0] != "#": a = line.strip().split("\t") if len(a[0]) > 0: if len(a) == 1: a.append(a[0]) sys.stderr.write("%s %s \n" % (a[0], a[1])) filename = a[0] if len(a) == 3: selectedcolor = a[2] else: selectedcolor = COLORS[n % len(COLORS)] spectrum = loadfile(filename) if spectrum != []: plotme(spectrum, label=a[1], color=selectedcolor, thresholdlist=listofthresholds, numplots=numplots, dump=OPTS.dump, shaded=SHADED) n = n + 1 if OPTS.suppresslegend == 0: plt.legend(loc="upper left") plt.savefig(OUTFILE) else: # for v in ARGS: # print("#", v) # filename = v # spectrum = loadfile(filename) # plotme(spectrum, filename, thresholdlist=listofthresholds, # color=COLORS[n], dump=OPTS.dump, numplots=len(ARGS), shaded=SHADED)
def test_missingfile(): fixture = loadfile("nonexistentfile") assert fixture == []
def test_loadfile_khmer(): fixture = loadfile(TESTDIR + "test_khmer.21") assert type(fixture) == np.ndarray
def test_loadfile_stats(): fixture = loadfile(TESTDIR + "stats.txt") assert type(fixture) == np.ndarray
def test_loadfile_npo(): fixture = loadfile(TESTDIR + "test_1.npo") assert type(fixture) == np.ndarray
def test_loadfile_empty(): fixture = loadfile(TESTDIR + "emptyfile") print(type(fixture)) assert fixture == []
def test_loadfile_SRR(): FIXTURE2 = loadfile( "repeatresolutionpaper/counts-validationgenomedata/SRR000333.fastq.21")
[20000, 10000], [200000, 100], [1000000, 1], [2000000, 1]], dtype="float") FIXTURE3 = np.array([[2000, 1000000], [20000, 10000], [200000, 100], [1000000, 1], [2000000, 1]], dtype="int") FIXTUREBAD1 = np.array([[0, 0]], dtype="int") FIXTUREBAD2 = np.array([[0, 0]], dtype="float") FIXTUREBAD3 = loadfile(TESTDIR + "testF1.21") FIXTURE2 = loadfile( "repeatresolutionpaper/counts-validationgenomedata/SRR000333.fastq.21") def test_calccumsum_float(): data = FIXTURE1 cn, c1, yd, yo, zd, zo = calccumsum(data) def test_calccumsum_int(): data = FIXTURE3 cn, c1, yd, yo, zd, zo = calccumsum(data)
def test_01(): data = loadfile(TESTDIR + "test01.21") cn, c1, yd, yo, zd, zo = calccumsum(data) pass
"File {} does not exist".format(listfile) IN_FILE = open(listfile, "r").readlines() numplots = len(IN_FILE) for line in IN_FILE: if line[0] != "#": a = line.strip().split("\t") if len(a[0]) > 0: if len(a) == 1: a.append(a[0]) sys.stderr.write("%s %s \n" % (a[0], a[1])) filename = a[0] if len(a) == 3: selectedcolor = a[2] else: selectedcolor = COLORS[n % len(COLORS)] spectrum = loadfile(filename) if spectrum != []: plotme(spectrum, label=a[1], color=selectedcolor, thresholdlist=listofthresholds, numplots=numplots, dump=OPTS.dump, shaded=SHADED) n = n + 1 if OPTS.suppresslegend == 0: plt.legend(loc="upper left") plt.savefig(OUTFILE) else: # for v in ARGS: # print("#", v)