def setUp(self): import os self.cwd = os.path.dirname(os.path.abspath(__file__)) self.ex = flow.ImportOp(conditions = {}, tubes = [flow.Tube(file = self.cwd + '/data/tasbe/blank.fcs', conditions = {})]).apply() self.op = flow.AutofluorescenceOp( blank_file = self.cwd + '/data/tasbe/blank.fcs', channels = ["Pacific Blue-A", "FITC-A", "PE-Tx-Red-YG-A"]) self.op.estimate(self.ex)
def __init__(self, file_id='default', ch1=False, ch2=False, transformation='hlog', bins=100): fcs_file_name = file_id + '_fcs_file.fcs' self.file_id = file_id self.transformation = transformation self.bins = bins self.response = {} self.channel_name1 = ch1 self.channel_name2 = ch2 print('ML setting ch names from params', ch1, ch2) # Check if images already exist if self.check_if_images_exist(): return None # Locate sample data included with this package print('Raw dir in init :', SHARED_RAW_DIR) fcs_file_path = os.path.join(SHARED_RAW_DIR, fcs_file_name) print('FCS File', fcs_file_path) fcs_file_a4_path = os.path.join(SHARED_RAW_DIR, FCS_FILE_A4) print('FCS File 4', fcs_file_a4_path) af_op = flow.AutofluorescenceOp() # Get channel_names if not ch1 or not ch2: URL = 'http://basicanalysis:3000?id=' + file_id r = requests.get(URL) self.channel_names = r.json() self.channel_name1 = self.channel_names[0] self.channel_name2 = self.channel_names[1] print(r.json()) tube1 = flow.Tube(file=fcs_file_path, conditions={"Dox": 10.0}) tube2 = flow.Tube(file=fcs_file_a4_path, conditions={"Dox": 1.0}) import_op = flow.ImportOp(conditions={"Dox": "float"}, tubes=[tube1, tube2], channels={ self.channel_name1: self.channel_name1, self.channel_name2: self.channel_name2 }) ex = import_op.apply() flow.HistogramView(scale='logicle', channel=self.channel_name2).plot(ex) png_file = os.path.join(SHARED_PLOT_DIR, self.get_file_name('histogram.png')) print(png_file) grid(True) savefig(png_file) self.response['histogram'] = self.get_file_name('histogram.png') g = flow.GaussianMixtureOp(name="Gauss", channels=[self.channel_name1], scale={self.channel_name1: "logicle"}, num_components=2) g.estimate(ex) g.default_view().plot(ex) ex2 = g.apply(ex) g.default_view().plot(ex2) png_file = os.path.join(SHARED_PLOT_DIR, self.get_file_name('gausian.png')) print(png_file) grid(True) savefig(png_file) self.response['gausian'] = self.get_file_name('gausian.png') print(type(ex2.data.head())) png_file = os.path.join(SHARED_PLOT_DIR, self.get_file_name('gausian_table.png')) self.__df_to_png(ex2.data.head(), png_file) self.response['gausian_table'] = self.get_file_name( 'gausian_table.png') subplots(clear=True) g = flow.GaussianMixtureOp(name="Gauss", channels=[self.channel_name1], scale={self.channel_name1: "logicle"}, num_components=2, posteriors=True) g.estimate(ex) ex2 = g.apply(ex) g.default_view().plot(ex2) png_file = os.path.join(SHARED_PLOT_DIR, self.get_file_name('gausian_posterior.png')) savefig(png_file) self.response['gausian_posterior'] = self.get_file_name( 'gausian_posterior.png') png_file = os.path.join( SHARED_PLOT_DIR, self.get_file_name('gausian_posterior_table.png')) self.__df_to_png(ex2.data.head(), png_file) self.response['gausian_posterior_table'] = self.get_file_name( 'gausian_posterior_table.png') # We can use this second metadata column to filter out events with low posterior probabilities: ex2.query( "Gauss_1_posterior > 0.9 | Gauss_2_posterior > 0.9").data.head() flow.HistogramView( channel=self.channel_name1, huefacet="Gauss", scale="logicle", subset="Gauss_1_posterior > 0.9 | Gauss_2_posterior > 0.9").plot( ex2) png_file = os.path.join( SHARED_PLOT_DIR, self.get_file_name('gausian_filtered_low_posterior.png')) savefig(png_file) self.response['gausian_filtered_low_posterior'] = self.get_file_name( 'gausian_filtered_low_posterior.png') subplots(clear=True) # Basic usage, assigning each event to one of the mixture components: (the isolines in the default_view() are 1, 2 and 3 standard deviations away from the mean.) g = flow.GaussianMixtureOp( name="Gauss", channels=[self.channel_name1, self.channel_name2], scale={ self.channel_name1: "logicle", self.channel_name2: "logicle" }, num_components=2) g.estimate(ex) ex2 = g.apply(ex) g.default_view().plot(ex2, alpha=0.1) png_file = os.path.join( SHARED_PLOT_DIR, self.get_file_name('gausian_mixture_model_two_channels.png')) savefig(png_file) self.response[ 'gausian_mixture_model_two_channels'] = self.get_file_name( 'gausian_mixture_model_two_channels.png') subplots(clear=True) # K-Means self.k_means(ex) # FlowPeaks """ ecoli_file_path = os.path.join(SHARED_RAW_DIR, ECOLI_FILE) print('Ecoli ', ecoli_file_path) ex = flow.ImportOp(tubes=[flow.Tube(file=ecoli_file_path)]).apply() flow.ScatterplotView(xchannel=self.channel_name1, xscale='log', ychannel=self.channel_name2, yscale='log').plot(ex) png_file = os.path.join(SHARED_PLOT_DIR, 'flow_peaks.png') savefig(png_file) self.response['flow_peaks'] = 'flow_peaks.png' """ # K-MEANS2 self.k_means2(ex)