Skip to content

pyNBS.pyNBS_plotting.cluster_KMplot

Justin Huang edited this page Jan 27, 2018 · 1 revision

This function uses the Lifelines Python package to plot a Kaplan-Meier (KM) plot of the survival profile of each patient cluster. After plotting the survival curve for each cluster, this function can also perform a multi-class log-rank test to determine if the clusters are prognostically different from one another. This function requires a file describing the overall survival of patients in the cohort to be plotted. A detailed explanation of the file format for the required survival data is described here.


Function Call:

cluster_KMplot(cluster_assign, clin_data_fn, delimiter='\t', lr_test=True, tmax=-1, verbose=True, **save_args)

Parameters:

  • cluster_assign (required, pandas.Series): A pandas Series with an index of all patients and values as the cluster assignments for each patient. The cluster_assign output from the consensus_hclust_hard function is generally expected here.
  • clin_data_fn (required, str): This is a string of the file path to a valid patient survival file. See the survival data file format page for additional details.
  • delimiter (optional, str, default='\t'): Delimiter used in the patient survival data file between columns.
  • lr_test (optional, bool, default='True'): Determination of whether or not to perform a multi=-variate log-rank test on the full set (over the full length) of survival curves in the resulting KM plot. If True, this function will return the p-value of the log-rank test and add it to the title of the plot, otherwise, only the plot will be generated.
  • tmax (optional, int, default=-1): The number of days to cut off the KM plot display. The default (-1) shows the full length of all survival data, otherwise, tmax should be a positive integer. Making a shorter tmax will not affect the log-rank test p-values.
  • verbose (optional, bool, default=True): Verbosity flag to report intermediate results (such as the log-rank p-value) and indicate when the function is done running.
  • **save_args (optional, dict, default=None): Dictionary of strings for saving results.
    • save_args['outdir']: A string containing the directory path of which to save the KM plot. If this parameter is given within **save_args, the function will automatically write the KM plot as a .png to this location.
    • save_args['job_name']: A string containing a file prefix for the KM plot saved in save_args['outdir']. Otherwise the base file name will default to KM_plot.png. The job_name will also show up in the title of the plot.

Returns:

  • p (float): If the parameter for lr_test is True, then the function will return the p-value of the log-rank test performed. Otherwise, the function will return nothing.

Additional notes about this function:

This function is only currently produces .png files. Other image file extensions are not currently supported.

Clone this wiki locally