alethiotx.artemis.upset
def
prepare( breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular, mode):
4def prepare(breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular, mode): 5 """ 6 Prepare data for UpSet plot visualization. 7 8 This function processes disease-related data and converts it into a format 9 suitable for UpSet plot generation using the `from_contents` function. 10 11 :param breast: Breast cancer data. In ``ct`` mode, should be a DataFrame with 12 ``Target Gene`` column. In ``pg`` mode, should be a list. 13 :type breast: pandas.DataFrame or list 14 :param lung: Lung cancer data. In ``ct`` mode, should be a DataFrame with 15 ``Target Gene`` column. In ``pg`` mode, should be a list. 16 :type lung: pandas.DataFrame or list 17 :param prostate: Prostate cancer data. In ``ct`` mode, should be a DataFrame with 18 ``Target Gene`` column. In ``pg`` mode, should be a list. 19 :type prostate: pandas.DataFrame or list 20 :param melanoma: Melanoma data. In ``ct`` mode, should be a DataFrame with 21 ``Target Gene`` column. In ``pg`` mode, should be a list. 22 :type melanoma: pandas.DataFrame or list 23 :param bowel: Bowel cancer data. In ``ct`` mode, should be a DataFrame with 24 ``Target Gene`` column. In ``pg`` mode, should be a list. 25 :type bowel: pandas.DataFrame or list 26 :param diabetes: Diabetes data. In ``ct`` mode, should be a DataFrame with 27 ``Target Gene`` column. In ``pg`` mode, should be a list. 28 :type diabetes: pandas.DataFrame or list 29 :param cardiovascular: Cardiovascular disease data. In ``ct`` mode, should be a 30 DataFrame with ``Target Gene`` column. In ``pg`` mode, 31 should be a list. 32 :type cardiovascular: pandas.DataFrame or list 33 :param mode: Processing mode. ``ct`` extracts ``Target Gene`` column from DataFrames, 34 ``pg`` uses the data directly as lists. 35 :type mode: str 36 :return: Dictionary formatted for UpSet plot with disease names as keys and 37 gene lists or data lists as values. 38 :rtype: dict 39 :raises ValueError: If mode is not ``ct`` or ``pg``. 40 """ 41 if mode == 'ct': 42 return from_contents( 43 { 44 "breast": breast['Target Gene'].tolist(), 45 "lung": lung['Target Gene'].tolist(), 46 "prostate": prostate['Target Gene'].tolist(), 47 "melanoma": melanoma['Target Gene'].tolist(), 48 "bowel": bowel['Target Gene'].tolist(), 49 "diabetes": diabetes['Target Gene'].tolist(), 50 "cardiovascular": cardiovascular['Target Gene'].tolist() 51 } 52 ) 53 elif mode == 'pg': 54 return from_contents( 55 { 56 "breast": breast, 57 "lung": lung, 58 "prostate": prostate, 59 "melanoma": melanoma, 60 "bowel": bowel, 61 "diabetes": diabetes, 62 "cardiovascular": cardiovascular 63 } 64 ) 65 else: 66 raise ValueError("Mode must be either 'ct' or 'pg'")
Prepare data for UpSet plot visualization.
This function processes disease-related data and converts it into a format
suitable for UpSet plot generation using the from_contents function.
Parameters
- breast: Breast cancer data. In
ctmode, should be a DataFrame withTarget Genecolumn. Inpgmode, should be a list. - lung: Lung cancer data. In
ctmode, should be a DataFrame withTarget Genecolumn. Inpgmode, should be a list. - prostate: Prostate cancer data. In
ctmode, should be a DataFrame withTarget Genecolumn. Inpgmode, should be a list. - melanoma: Melanoma data. In
ctmode, should be a DataFrame withTarget Genecolumn. Inpgmode, should be a list. - bowel: Bowel cancer data. In
ctmode, should be a DataFrame withTarget Genecolumn. Inpgmode, should be a list. - diabetes: Diabetes data. In
ctmode, should be a DataFrame withTarget Genecolumn. Inpgmode, should be a list. - cardiovascular: Cardiovascular disease data. In
ctmode, should be a DataFrame withTarget Genecolumn. Inpgmode, should be a list. - mode: Processing mode.
ctextractsTarget Genecolumn from DataFrames,pguses the data directly as lists.
Returns
Dictionary formatted for UpSet plot with disease names as keys and gene lists or data lists as values.
Raises
- ValueError: If mode is not
ctorpg.
def
create(indications, min_subset_size):
68def create(indications, min_subset_size): 69 """ 70 Create an UpSet plot for visualizing set intersections. 71 72 :param indications: Data structure containing set membership information for creating the UpSet plot 73 :type indications: pandas.DataFrame or similar data structure compatible with UpSet 74 :param min_subset_size: Minimum size threshold for subsets to be displayed in the plot 75 :type min_subset_size: int 76 :return: An UpSet plot object configured with the specified parameters 77 :rtype: UpSet 78 :raises TypeError: If indications is not a compatible data structure 79 :raises ValueError: If min_subset_size is negative 80 81 .. note:: 82 83 The plot is configured with the following settings: 84 85 - subset_size: "count" - shows count of elements in each subset 86 - orientation: "vertical" - displays plot in vertical orientation 87 - show_counts: "{:d}" - formats counts as integers 88 - sort_by: ``cardinality`` - sorts subsets by their size 89 - sort_categories_by: ``input`` - maintains input order for categories 90 - min_subset_size: filters out subsets smaller than the specified threshold 91 92 .. seealso:: 93 94 `UpSet documentation <https://upsetplot.readthedocs.io/>`_ 95 """ 96 return UpSet( 97 indications, 98 subset_size="count", 99 orientation="vertical", 100 show_counts="{:d}", 101 sort_by='cardinality', 102 sort_categories_by = 'input', 103 min_subset_size = min_subset_size, 104 )
Create an UpSet plot for visualizing set intersections.
Parameters
- indications: Data structure containing set membership information for creating the UpSet plot
- min_subset_size: Minimum size threshold for subsets to be displayed in the plot
Returns
An UpSet plot object configured with the specified parameters
Raises
- TypeError: If indications is not a compatible data structure
- ValueError: If min_subset_size is negative
The plot is configured with the following settings:
- subset_size: "count" - shows count of elements in each subset
- orientation: "vertical" - displays plot in vertical orientation
- show_counts: "{:d}" - formats counts as integers
- sort_by:
cardinality- sorts subsets by their size - sort_categories_by:
input- maintains input order for categories - min_subset_size: filters out subsets smaller than the specified threshold
seealso: UpSet documentation