def test_histogram_file_type_unsupported(self): L = [1, 1, 1] with self.assertRaises(ValueError) as ex: data_viz.boxplot(L, 'test.py') self.assertEqual(str(ex.exception), 'Out file type unsupported.')
def test_boxplot_file_type(self): L = [8, 4, 1, 2, 6, 2] x_ticks = "sample1" with self.assertRaises(ValueError) as ex: dv.boxplot('test.jpeg', 'title', 'x_axis', 'y_axis', L, x_ticks) message = 'File type not supported' self.assertEqual(str(ex.exception), message)
def main(): parser = argparse.ArgumentParser( description='Read a file from stdin, generate a plot', prog='bay') parser.add_argument( '-o', # input file, from user '--out_file', type=str, help="File Name With Which to Save Plot", required=True) parser.add_argument( '-p', # desired column, from user '--plot_type', type=str, help="Types are: 'hist', 'box', 'combo'", required=True) args = parser.parse_args() file_out = args.out_file type = args.plot_type x = gt.read_stdin_col(0) y = gt.read_stdin_col(1) combined = np.vstack((x, y)).T combined = combined.tolist() if type == "hist": dv.histogram(combined, file_out) if type == "box": dv.boxplot(combined, file_out) if type == "combo": dv.combo(combined, file_out)
def main(): parser = argparse.ArgumentParser(description='Create plots' ' with data from stdin.') parser.add_argument('--output_file_name', type=str, help='Name of the output file', required=True) parser.add_argument( '--plot_type', type=str, help='The type of plot you wish to produce', required=True) args = parser.parse_args() # Read data from standard in try: V = get_data.read_stdin_col(0) except TypeError: print('Data could not be read from stdin') sys.exit(1) # plot generation if args.plot_type == str('boxplot'): data_viz.boxplot(V, args.output_file_name) if args.plot_type == str('histogram'): data_viz.histogram(V, args.output_file_name) if args.plot_type == str('combo'): data_viz.combo(V, args.output_file_name)
def main(): parser = argparse.ArgumentParser( description='Program that allows one to create a boxplot, ' + 'histogram, or combo of the two of a set of data.', prog='viz') parser.add_argument('--out_file_name', type=str, help='The output file name.', required=True) parser.add_argument('--col_num', type=int, help='The input column.', required=True) parser.add_argument('--plot_type', type=str, help='Choices are boxplot, histogram, or combo.', required=True) args = parser.parse_args() out_file_name = args.out_file_name col_num = args.col_num plot_type = args.plot_type data = gd.read_stdin_col(col_num) if plot_type == "boxplot": dv.boxplot(data, out_file_name) if plot_type == "histogram": dv.histogram(data, out_file_name) if plot_type == "combo": dv.combo(data, out_file_name)
def main(): # get argument by arg parser args = parse_args() # check if it is a valid file name if not os.access(args.out_file, os.W_OK): try: open(args.out_file, 'w').close() os.unlink(args.out_file) except OSError: print('Invalid file name') sys.exit(1) # get an array from STDIN L = get_data.read_stdin_col(args.col_num) if len(L) == 0: print('Empty list') sys.exit(1) # choose plot type if (args.plot_type == 'histogram'): data_viz.histogram(L, args.out_file) elif (args.plot_type == 'boxplot'): data_viz.boxplot(L, args.out_file) elif (args.plot_type == 'combo'): data_viz.combo(L, args.out_file) else: print('Invalid plot type') sys.exit(1) sys.exit(0)
def main(): # L coming from stdin from get_data method L = get_data.read_stdin_col(0) parser = argparse.ArgumentParser(description='inputs\ for file name and \ type of plot', prog='viz.py') parser.add_argument('--plot_type', type=str, help='Choice of plot: Boxplot, Histogram, or Combo', required=True) parser.add_argument('--out_file_name', type=str, help='Name of output file', required=True) args = parser.parse_args() try: if args.plot_type == 'Boxplot': data_viz.boxplot(L, args.out_file_name) elif args.plot_type == 'Histogram': data_viz.histogram(L, args.out_file_name) elif args.plot_type == 'Combo': data_viz.combo(L, args.out_file_name) else: print("Must choose from: 'Histogram', 'Boxplot', or 'Combo'") except ValueError: print('Must have correct file extension. Try .png?')
def test_boxplot_one_boxplot(self): file_name = 'out.png' data = [1, 2, 3] for i in range(100): data.append(random.randint(0,1000)) dv.boxplot(data,file_name, 'x', 'y', 'title') self.assertTrue(os.path.exists(file_name))
def test_boxplot_no_out_file_name(self): L = [] with self.assertRaises(TypeError) as ex: data_viz.boxplot(L, None) self.assertEqual(str(ex.exception), 'No file name given.')
def test_boxplot_out_file_type(self): L = [4, 6, 5, 9, 10, 3, 9] x_ticks = "sample1" with self.assertRaises(ValueError) as ex: dv.boxplot('test.jpeg', 'title', 'x_axis', 'y_axis', L, x_ticks) message = 'Can not support file extension. Try .png instead' self.assertEqual(str(ex.exception), message)
def test_boxplot_random_double_array(self): file_name = "test.png" rand_double_list = [random.random() for i in range(1000)] data_viz.boxplot(rand_double_list, file_name) self.assertEqual(os.path.exists(file_name), True) os.remove(file_name)
def test_dat_viz_exist(self): A = [] file_name = 'file1.png' file = open(file_name, 'w') file.close() with self.assertRaises(SystemExit) as ex: data_viz.boxplot(A, file_name) self.assertEqual(str(ex.exception), 'File already exits')
def test_data_viz_boxplot_exist(self): """This funtion test if the plot is saved properly. """ output_name = 'boxplot_test.png' check_bf = os.path.exists(output_name) data_viz.boxplot(L, output_name) check_af = os.path.exists(output_name) self.assertFalse(check_bf) self.assertTrue(check_af)
def test_boxplot_filename_already_exists(self): test_filename = "test_file" test_file = open(test_filename, "w") test_file.close() with self.assertRaises(Exception) as ex: data_viz.boxplot([1, 2], test_filename) output = str(ex.exception) self.assertEqual(output, "error, file already exists")
def main(): """ Read numerical data from the standard input, calculate the mean and standard deviation, and save data as a box plot or histogram Parameters ----------- --out_file : the desired name of the saved plot, with the png extension --plot_type : the type of plot to produce. Choices are histogram, boxplot, or combo. Returns -------- A plot saved as --out_file """ parser = argparse.ArgumentParser(description='produce a plot of data from ' 'stdin', prog='viz') parser.add_argument('--out_file', type=str, help='Name of output file', required=True) parser.add_argument('--plot_type', type=str, help='The plot type, lowercase', required=True) args = parser.parse_args() out_file_name = args.out_file plot = args.plot_type # hardcoding the columns output from gen_data.sh # output of read_stdin_col is a list col_1 = get_data.read_stdin_col(0) col_2 = get_data.read_stdin_col(1) # merge both lists into one for graphing L = [] for i in col_1: L.append(i) for j in col_2: L.append(j) try: if plot == "histogram": data_viz.histogram(L, out_file_name) if plot == "boxplot": data_viz.boxplot(L, out_file_name) if plot == "combo": data_viz.combo(L, out_file_name) except NameError: print('Plot type not available. Check help for available types') sys.exit(1)
def test_boxplot_file_already_exits(self): L = [] file_name = 'test.png' f = open(file_name, 'w') f.close() with self.assertRaises(SystemExit) as ex: data_viz.boxplot(L, file_name) self.assertEqual(str(ex.exception), 'File already exists.')
def test_boxplot_many_boxplot(self): file_name = 'many.png' data = [] for j in range(10): d = [] for i in range(100): d.append(random.randint(0,1000)) data.append(d) dv.boxplot(data,file_name, 'x', 'y', 'title') self.assertTrue(os.path.exists(file_name))
def main(): L = sys.stdin out_file = args.output_file plot = args.plot_type if plot == 'boxplot': data_viz.boxplot(L, out_file) if plot == 'histogram': data_viz.histogram(L, out_file) if plot == 'combo': data_viz.combo(L, out_file)
def test_boxplot_empty(self): self.data_lists = [] self.file = "boxplot_empty" self.label_list = [] self.title = "ACTA2" self.x_label = "SMTS" self.y_label = "Gene read counts" boxplot(self.data_lists, self.label_list, self.title, self.x_label, self.y_label, self.file) self.assertEqual(True, os.path.exists(self.file + ".png"))
def test_boxplot(self): V = [] # test array with 1000 random elements for _ in range(1000): r = random.randint(-1000, 1000) V.append(r) # plot boxplot and verify the png is generated data_viz.boxplot(V, 'test.png') self.assertTrue(os.path.exists('test.png')) os.remove('test.png')
def main(): args = getparser() data = get_data.read_stdin_col(args.col_num) if args.plot_type == 'boxplot': data_viz.boxplot(data, args.out_file) elif args.plot_type == 'histogram': data_viz.histogram(data, args.out_file) elif args.plot_type == 'combo': data_viz.combo(data, args.out_file) else: raise ValueError('Legal list for plot_type: boxplot, histogram, combo')
def test_boxplot_file_already_exists(self): file_name = "test.png" f = open(file_name, "w+") f.close() with self.assertRaises(FileExistsError) as ex: data_viz.boxplot([], file_name) self.assertEqual(str(ex.exception), "That file name already exists.") os.remove(file_name)
def test_boxplot(self): datapoints = 1000 normal = np.random.normal(1, 1, datapoints) uniform = np.random.uniform(1, 1, datapoints) data = [normal, uniform] data_viz.boxplot(data, ['Normal', 'Uniform'], 'Distributions', 'Distribution', 'y-value', 'testplot.png') self.assertTrue(os.path.exists('testplot.png')) os.remove('testplot.png')
def test_boxplot_name_boxes(self): file_name = 'nameboxes.png' data = [] groups = [] for j in range(10): d = [] groups.append('Sample ' + str(j)) for i in range(100): d.append(random.randint(0,1000)) data.append(d) dv.boxplot(data, file_name, 'x', 'y', 'title', groups) self.assertTrue(os.path.exists(file_name))
def test_boxplot_not_exist(self): self.data_lists = [] for i in range(4): self.data_lists.append(np.random.randint(0, 100, size=100)) self.file = "boxplot_test2" self.label_list = ['Sample1', 'Sample2', 'Sample3', 'Sample4'] self.title = "ACTA2" self.x_label = "SMTS" self.y_label = "Gene read counts" boxplot(self.data_lists, self.label_list, self.title, self.x_label, self.y_label, "bad_histogram") self.assertEqual(False, os.path.exists(self.file + ".png"))
def test_boxplot_len_L_plotlabels_not_equal(self): outfile = "output.png" L = [] plotlabels = [] for x in range(5): if x is not 0: plotlabels.append(str(x)) L.append([ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ]) dv.boxplot(L, outfile, "Title", plotlabels, "x", "y") os.remove(outfile)
def test_boxplot_random_int_array_2d(self): file_name = "test.png" rand_int_list = [] length = range(0, 10) for i in length: rand_int_list.append( [random.randrange(-100, 100) for i in range(100)]) data_viz.boxplot(rand_int_list, file_name, data_labels=[i for i in length]) self.assertEqual(os.path.exists(file_name), True) os.remove(file_name)
def main(): parser = argparse.ArgumentParser( description="plot data from stdin") parser.add_argument('--out_file_name', type=str, help='name of output file', required=True) parser.add_argument('--plot_type', type=string, help='take "histrogram" or "boxplot" or "combo"', required=True) parser.add_argument('--col_num', type=int, help='column num in stdin to get data from', required=True) args = parser.parse_args() try: data = get_data(args.col_num) except Exception: print("something went wrong in get_data") sys.exit(1) if(argparse.plot_type == "boxplot"): try: data_viz.boxplot(data, args.out_file_name) except Exception: print("something went wrong in data_viz.boxplot") sys.exit(1) if(argparse.plot_type == "histogram"): try: data_viz.histogram(data, args.out_file_name) except Exception: print("something went wrong in data_viz.histogram") sys.exit(1) if(argparse.plot_type == "boxplot"): try: data_viz.combo(data, args.out_file_name) except Exception: print("something went wrong in data_viz.combo") sys.exit(1) pass
def test_boxplot(self): random_dists = ['Normal', ' Lognormal', 'Exp', 'Gumbel', 'Triangular'] N = 500 norm = np.random.normal(1, 1, N) logn = np.random.lognormal(1, 1, N) expo = np.random.exponential(1, N) gumb = np.random.gumbel(6, 4, N) tria = np.random.triangular(2, 9, 11, N) # Generate 2d array data = [norm, logn, expo, gumb, tria] data_viz.boxplot(data, random_dists, 'Distribution', 'Value', 'Comparison', 'test_box_plot.png') # check the result is generated successfully or not self.assertTrue(os.path.exists('test_box_plot.png')) os.remove('test_box_plot.png')
def test_takes_list(self): L = [[1, 2, 3], [2, 2, 2], [3, 1, 2]] ticks = [1, 2, 3] r = data_viz.boxplot(L, 'test_outputfile.png', 'T', 'x', 'y', ticks) path = 'test_outputfile.png' isFile = os.path.isfile(path) self.assertTrue(isFile) os.remove('test_outputfile.png')