n.b. this is done to solve a memory leak inherant import_FCS_file. Perhaps there is a leak in loadFCS? @author: ngdavid """ from HEADER_Import_FCS import import_FCS_file from HEADER_ND_Binning import ND_Binning from HEADER_Generate_HDF5 import Bin_2_HDF5_File import HEADER_Program_Variables as Prog_Var import sys import json case_num = sys.argv[1] tubes = json.loads(sys.argv[2]) HDF5_Cases = Bin_2_HDF5_File(Prog_Var.output_file, overwrite=False) tube, binning = {}, {} for k in tubes.keys(): tube[k] = import_FCS_file(tubes[k], Prog_Var.comp_file, gate_coords=Prog_Var.coords, limits=True, strict=False) binning[k] = ND_Binning(tube[k], Prog_Var.parameters, bins=10) HDF5_Cases.push_case(case_num, tube, binning, ordering=Prog_Var.Pattern, saveFCS=False) print('{} has been pushed to {}'.format(case_num, Prog_Var.output_file))
else: bin_dict = pd.Series(bins,columns) elif isinstance(bins,dict): if bins.keys() not in columns or columns not in bins.keys(): raise RuntimeWarning("The bin keys do not match the provided columns") else: raise RuntimeWarning("bin dict not implemented") else: raise TypeError("provided bins parameter is not supported") return bin_dict def Return_Coordinates(self,index): """ Returns the bin parameters """ coords = self.histogram.indices[index] self.x = np.array(np.unravel_index(coords,list(self.bins)),dtype=np.float32).T return pd.DataFrame(self.x / np.array(self.bins)[np.newaxis], index = coords, columns=self.bins.index.values) if __name__ == "__main__": from HEADER_Import_FCS import import_FCS_file filename='/home/ngdavid/Desktop/Ubuntu_Dropbox/Myeloid_Data/Myeloid/12-00005/12-00005_Myeloid 2.fcs' comp_file='/home/ngdavid/Desktop/Ubuntu_Dropbox/Comp_Libs/M2_Comp_Lib_LSRA.txt' M4_tube=import_FCS_file(filename,comp_file,limits=True) parameters = [x for x in M4_tube.data.columns if x not in ['FSC-H','SSC-A','Time']] binned_data = ND_Binning(M4_tube,parameters,bins=10) print binned_data.Return_Coordinates([5,6,7,8,9])
"The bin keys do not match the provided columns") else: raise RuntimeWarning("bin dict not implemented") else: raise TypeError("provided bins parameter is not supported") return bin_dict def Return_Coordinates(self, index): """ Returns the bin parameters """ coords = self.histogram.indices[index] self.x = np.array(np.unravel_index(coords, list(self.bins)), dtype=np.float32).T return pd.DataFrame(self.x / np.array(self.bins)[np.newaxis], index=coords, columns=self.bins.index.values) if __name__ == "__main__": from HEADER_Import_FCS import import_FCS_file filename = '/home/ngdavid/Desktop/Ubuntu_Dropbox/Myeloid_Data/Myeloid/12-00005/12-00005_Myeloid 2.fcs' comp_file = '/home/ngdavid/Desktop/Ubuntu_Dropbox/Comp_Libs/M2_Comp_Lib_LSRA.txt' M4_tube = import_FCS_file(filename, comp_file, limits=True) parameters = [ x for x in M4_tube.data.columns if x not in ['FSC-H', 'SSC-A', 'Time'] ] binned_data = ND_Binning(M4_tube, parameters, bins=10) print binned_data.Return_Coordinates([5, 6, 7, 8, 9])
# -*- coding: utf-8 -*- """ Created on Wed Sep 10 12:15:34 2014 Command line file to be accessed via Main.py n.b. this is done to solve a memory leak inherant import_FCS_file. Perhaps there is a leak in loadFCS? @author: ngdavid """ from HEADER_Import_FCS import import_FCS_file from HEADER_ND_Binning import ND_Binning from HEADER_Generate_HDF5 import Bin_2_HDF5_File import HEADER_Program_Variables as Prog_Var import sys import json case_num = sys.argv[1] tubes = json.loads(sys.argv[2]) HDF5_Cases = Bin_2_HDF5_File(Prog_Var.output_file,overwrite=False) tube,binning = {},{} for k in tubes.keys(): tube[k] = import_FCS_file(tubes[k],Prog_Var.comp_file,gate_coords=Prog_Var.coords,limits=True,strict=False) binning[k] = ND_Binning(tube[k],Prog_Var.parameters,bins=10) HDF5_Cases.push_case(case_num,tube,binning,ordering = Prog_Var.Pattern,saveFCS=False) print('{} has been pushed to {}'.format(case_num,Prog_Var.output_file))