示例#1
0
    def count_items(self, independent=True, seed=None, read=True):
        """Parse data to count items: cells, colonies, lineages, containers

        Parameters
        ----------
        independent : bool {True, False}
            lineage decomposition parameter
        seed : int, or None
            lineage decomposition parameter
        read : bool {True, False}
            try to read it in analysis folder
        """
        # 1. try to read
        try:
            if read:
                # get analysis path

                analysis_path = analysis.get_analysis_path(self, write=False)
                i, filter_path = analysis.get_filter_path(analysis_path, self.fset,
                                                      write=False)
                counts = analysis.read_count_file(filter_path)
                self._counts = counts
            else:
                raise text.MissingFileError  # mock it to go to exception
        except (text.MissingFileError, text.MissingFolderError, text.CorruptedFileError):
            self._count_items(independent=independent, seed=seed, write=True)
        print(self._count_summary())
示例#2
0
 def import_from_text(self, analysis_folder=None):
     try:
         for key, val in self._items.items():
             val.read_text(analysis_folder)
         exp = self.exp
         fset = self.exp.fset
         analysis_path = analysis.get_analysis_path(
             exp, user_abspath=analysis_folder, write=False)
         res = analysis.get_filter_path(analysis_path, fset, write=False)
         index_filter, filter_path = res
         o1, o2 = [uni.obs for uni in self.univariates]
         basename = 'data_{}_{}---{}'.format(self.label, o1.name, o2.name)
         text_file = os.path.join(filter_path, basename + '.csv')
         if not os.path.exists(text_file):
             raise analysis.MissingFileError
         df = pd.read_csv(text_file, index_col=False)
         # convert column dtypes
         for col_name in df.columns:
             dtype = _dtype_converter(col_name)
             if dtype is not None:
                 df[col_name] = df[col_name].astype(dtype)
         self.dataframe = df
     except (analysis.MissingFileError, analysis.MissingFolderError):
         raise StationaryBivariateIOError
     return
示例#3
0
 def _erase_count_file(self):
     try:
         analysis_path = analysis.get_analysis_path(self, write=False)
         i, filter_path = analysis.get_filter_path(analysis_path, self.fset,
                                                   write=False)
         filename = os.path.join(filter_path, '.counts.yml')
         if os.path.exists(filename):
             os.remove(filename)
     except (text.MissingFileError, text.MissingFolderError):
         pass
示例#4
0
 def _get_obs_path(self, user_root=None, write=False):
     """Get observable path"""
     obs = self.obs
     exp = self.exp
     fset = self.exp.fset
     analysis_path = analysis.get_analysis_path(exp,
                                                user_abspath=user_root,
                                                write=write)
     res = analysis.get_filter_path(analysis_path, fset, write=write)
     index_filter, filter_path = res
     obs_path = analysis.get_observable_path(filter_path, obs, write=write)
     return obs_path
示例#5
0
 def export_text(self, analysis_folder=None):
     # write each condition
     try:
         for key, val in self._items.items():
             val.write_text(analysis_folder)
     # when not possible it means single object has not been exported yet
     except analysis.MissingFolderError:
         self.single.export_text(analysis_folder)
         for key, val in self._items.items():
             val.write_text(analysis_folder)
     # export dataframe as csv file
     if self.dataframe is not None:
         exp = self.univariate.exp
         fset = self.univariate.exp.fset
         analysis_path = analysis.get_analysis_path(
             exp, user_abspath=analysis_folder, write=True)
         res = analysis.get_filter_path(analysis_path, fset, write=True)
         index_filter, filter_path = res
         basename = 'data_{}_{}'.format(self.label, self.obs.name)
         text_file = os.path.join(filter_path, basename + '.csv')
         self.dataframe.to_csv(text_file, index=False)
     return
示例#6
0
 def analysis_path(self):
     """Get analysis path (with appropriate filterset path)"""
     analysis_path = analysis.get_analysis_path(self, write=True)
     index, filterset_path = analysis.get_filter_path(analysis_path, self.fset, write=True)
     return filterset_path
示例#7
0
 def _path_to_file(self, write=False):
     analysis_path = analysis.get_analysis_path(self.exp, write=write)
     text_file = os.path.join(analysis_path, 'regions.tsv')
     if not os.path.exists(text_file) and not write:
         raise RegionsIOError
     return text_file