Example #1
0
 def subsetFileMapping(self, file_type=None, sample_id=None):
     """
     subset by one or more values of different columns from sample file mapping
         file_type: file type/types, corresponding to 'FILE_TYPE' column
         sample_id: sample ID/IDs
     """
     subset = self.sampleFileMapping
     subset = utils.subsetBy(subset, "FILE_TYPE", file_type)
     subset = utils.subsetBy(subset, "ID", sample_id)
     return subset
Example #2
0
    def subsetSampleAnnotation(self,
                               column,
                               values,
                               subset=None,
                               exact_match=True):
        """
        subset by one or more values of different columns from sample file mapping
            :param column: valid column in sample annotation
            :param values: values of column to subset
            :param subset: subset sample annotation
            :param exact_match: whether to match substrings in the sample annotation, false allows substring matching
        """
        sa_cols = set(self.SAMPLE_ANNOTATION_COLUMNS)
        if subset is None:
            subset = self.annotationTable
        else:
            # check type for subset
            if not isinstance(subset, pd.DataFrame):
                raise TypeError(f"Is not pandas DataFrame\n {subset}")
            if not sa_cols <= set(
                    subset.columns):  # check if mandatory cols not contained
                raise ValueError(
                    f"Subset columns not the same as {sa_cols}\ngot: {subset.columns}"
                )

        # check if column is valid
        if column not in sa_cols:
            raise KeyError(
                f"Column '{column}' not present in sample annotation.")
        return utils.subsetBy(subset, column, values, exact_match=exact_match)
Example #3
0
    def subsetSampleAnnotation(self, column, values, subset=None):
        """
        subset by one or more values of different columns from sample file mapping
            :param column: valid column in sample annotation
            :param values: values of column to subset
            :param subset: subset sample annotation
        """
        sa_cols = set(self.SAMPLE_ANNOTATION_COLUMNS)
        if subset is None:
            subset = self.sa
        else:
            # check type for subset
            if not isinstance(subset, pd.DataFrame):
                raise TypeError(f"Is not pandas DataFrame\n {subset}")
            if not sa_cols <= set(subset.columns): # check if mandatory cols not contained
                raise ValueError(f"Subset columns not the same as {sa_cols}\ngot: {subset.columns}")

        # check if column is valid
        if not column in sa_cols:
            raise KeyError(f"Column '{column}' invalid for sample annotation")
        return utils.subsetBy(subset, column, values)