#######################################################################################################################################
##### We will start this example file by reconstructing networks for just 20 samples from the TCGA dataset (10 LumA, 10 LumB).
##### After reconstructing the networks (Stage 2), we will use a larger dataset with more LumA and LumB samples. This is just 
##### to cut down on the length of computational time for this tutorial.
#######################################################################################################################################

# Stage 1: Preprocess data to remove genes not expressed in enough samples
# example: sisana preprocess ./example_inputs/params.yml
preprocess:
  exp_file: ./example_inputs/BRCA_TCGA_20_LumA_LumB_samps_5000_genes_exp.tsv # Path to expression file, which MUST CONTAIN A HEADER
  number: 5 # number of samples a gene must be expressed in
  outdir: ./output/preprocess # The directory to save the output to

# Stage 2: Reconstruct networks and calculate degrees
# example: sisana generate ./example_inputs/params.yml
generate:
  exp: ./output/preprocess/BRCA_TCGA_20_LumA_LumB_samps_5000_genes_exp_preprocessed.txt # Path to the expression file (RNA-Seq or microarray). Must be in matrix format with genes as rows and sample names as columns.
  motif: ./example_inputs/motif_prior_names_2024.tsv # Path to the motif prior file. This file is generated with SPONGE and for most users, this file can be used for their analysis as well.
  ppi: ./example_inputs/ppi_prior_2024.tsv # Path to the PPI prior file. This file is generated with SPONGE and for most users, this file can be used for their analysis as well.
  method: lioness # Which method to use, either "panda" to run just PANDA or "lioness", which runs PANDA first, then LIONESS
  pandafilepath: ./output/network/panda_network.txt # Path to the PANDA output file to be created. Must have a .txt extension.

  # The following commands are used if you specified "lioness" for the "method" arg
  compute: cpu # Whether to use "gpu" or "cpu" for computing LIONESS networks
  ncores: 20 # Number of cores to use for calculating LIONESS networks. Must be less than or equal to the number of samples.
  lionessfilepath: ./output/network/lioness_networks.npy # Path to the lioness output file to be created. Must have a .npy extension.

#######################################################################################################################################
##### Note: Now we will begin running the downstream analysis on a superset of the samples used for stages 1 and 2. This superset
##### contains 100 LumA samples and 100 LumB samples, all from the TCGA dataset. This is to save on computational time for this
##### tutorial. For your data, you will continue using the files produced by stage 1 and stage 2 in your analysis.
#######################################################################################################################################

# Stage 3: Compare experimental groups. Specify which comparison type to perform in the "sisana compare <comparison_type>" command.
compare:

  # Use the following if you wish to perform either a t-test, Mann-Whitney test, or their paired alternatives on the 
  # in-degree, out-degree, or expression data.
  # example: sisana compare means ./example_inputs/params.yml
  means: 
    datafile: ./example_inputs/lioness_df_indegree_3_decimal_places_subset_200_LumALumB_samps.csv # Path to the data file (either expression, in-degree, or out-degree)
    mapfile: ./example_inputs/BRCA_TCGA_200_LumA_LumB_samps_mapping_w_header.csv # Path to the mapping file, which maps sample name (column 1) to sample group (column 2). Header must be in the format of "name,group".
    datatype: degree # The type of data being used (example: "expression" or "degree")
    groups:  # Names of the two groups (from the second column of mapfile) to be compared. The difference in means/medians will be calculated by doing group2-group1
      - LumA
      - LumB
    testtype: mw # Type of comparison to perform, either "tt" for Student's t-test, "mw" for Mann-Whitney U, "paired_tt", or "wilcoxon"
    filetype: csv # The type of data file ("csv" or "txt" or "tsv") being used
    rankby: mediandiff # The statistic to rank the .rnk output file by for GSEA. Choices are "mediandiff" (the difference in medians between groups), "mwu" (the Mann-Whitney U test statistic), "neglogp" (-log(p-value)), and "meandiff" (the difference in means between groups)
    outdir: ./output/compare_means/ # The directory to save the output to

  # Use the following if you wish to perform a survival analysis between two sample groups
  # example: sisana compare survival ./example_inputs/params.yml
  survival:
    metadata: ./example_inputs/BRCA_TCGA_200_LumA_LumB_samps_survival_data.csv # Path to file ("csv" or "txt") containing the survival status and mapping to groups. Must contain a column describing the survival status (see alivestatus_colname param)
    filetype: csv # Type of file for metadata. Enter "csv" or "txt" for this.
    sampgroup_colname: PAM50_subtype # Name of column containing sample group names
    alivestatus_colname: Survival_status(False_equals_alive) # Name of column that contains the status of the individual. Must contain True/False values only, where True = dead (event occurred) and False = alive.
    days_colname: days_to_death_or_last_followup # Name of column containing either the number of days an individual survived or the number of days to the last follow up.
    groups: # The names of the two groups (from the metadata file) to compare
      - LumA
      - LumB
    outdir: ./output/survival/ # The directory to save the output to

# Stage 4: Perform gene set enrichment analysis (GSEA). Must run "sisana compare means" first
# example: sisana gsea ./example_inputs/params.yml
gsea:
  genefile: ./output/compare_means/comparison_mw_between_LumA_LumB_degree_ranked_mediandiff.rnk # Path to file (.rnk format, which is two columns, tab delimited, no header) containing the genes and test statistics to do enrichment on. This file is generated with "sisana compare means"
  gmtfile: ./example_inputs/Hallmark.v2023.2.Hs.symbols.gmt # Path to the gene set file in gmt format
  geneset: Hallmarks # The gene set type used for gmtfile. This is just a string that gets added to the output file name, so you can describe the specific version used for your GMT file in this name.
  outdir: ./output/gsea/ # The directory to save the output to

# Stage 4: Visualize the differences between experimental groups. Specify which visualization to perform with "sisana visualize <visualization_type>" command
visualize:
  
  # Use the following option if you wish to make a volcano plot of the in-degree and out-degree, plotting both the difference in median degree (x axis) and FDR (y axis) of genes
  # example: sisana visualize volcano ./example_inputs/params.yml
  volcano: 
    statsfile: ./output/compare_means/comparison_mw_between_LumA_LumB_degree.txt # Path to TSV file containing the difference in mean/median degree, p-value, and FDR. This file is generated with "sisana compare means".
    diffcol: difference_of_medians_(LumB-LumA) # The name of the column containing the values for the x-axis. For networks, this should be the difference in median degree between the two groups
    adjpcol: FDR # The name of the column containing the adj. p-value
    xaxisthreshold: 50 # Threshold to use for the x-axis (value will also be applied to the negative end of the x axis, meaning a value of 50 really means +/- 50)"
    adjpvalthreshold: 0.25 # Threshold to use for the adjusted p-value (y-axis)
    difftype: median # Choices are 'median' or 'mean'. Enter whether you are plotting the differences in medians or means. 
    outdir: ./output/volcano/ # The directory to save the output to
    genelist: ./example_inputs/volcano_plot_genes.txt # [OPTIONAL, BUT DON'T DELETE] If you have a list of genes you want to label in a .txt file, no header, enter the file name here. Otherwise, keep this blank and only the top genes (number dictated by numlabels) will be labeled 
    numlabels: # [OPTIONAL, BUT DON'T DELETE] Maximum number of values to label on each half of the plot. Default value is 15. Will not be used if a file is given for genelist.

  # Use the following option if you wish to make a boxplot or violin plot. Specify which plot type in the command with "sisana visualize <plot_type>"
  # example: sisana visualize quantity ./example_inputs/params.yml
  quantity: 
    datafile: ./example_inputs/lioness_df_indegree_3_decimal_places_subset_200_LumALumB_samps.csv # Path to file containing the expression, in-degree, or out-degree of each gene per sample.
    statsfile: ./output/compare_means/comparison_mw_between_LumA_LumB_degree.txt # Path to TSV file containing the difference in mean/median degree, p-value, and FDR. This file is generated with "sisana compare means".
    filetype: csv # Type of the datafile file. Must be either "csv", "txt", or "tsv", where csv implies comma separated values and txt/tsv implies tab-separated
    metadata: ./example_inputs/BRCA_TCGA_200_LumA_LumB_samps_mapping_w_header.csv # Path to the csv metadata file mapping samples to groups (the names of groups in the group column must match names of the groupnames arg). Header must be in the format of "name,group". 
    plottype: boxplot # The type of plot to create. Choices are "boxplot" or "violin"
    groups:  # The names of the groups to plot, should ideally be a list of 5 names or less. Groups will be plotted in the order they are written in this argument
      - LumA
      - LumB    
    colors:  # The colors for each group, in the same order the groups appear in the groupnames arg. Supports matplotlib named colors (https://matplotlib.org/stable/gallery/color/named_colors.html)
      - cornflowerblue
      - orange        
    prefix: LumA_LumB_indegree # Prefix to use for the output figures. For example, "expression_group1_group2" would produce "expression_group1_group2_box_plot.png" (assuming boxplot was used for plottype)
    yaxisname: Indegree # Name to use for the y-axis
    outdir: ./output/plot_quantity/ # Path to directory to output file to
    genelist:  # [OPTIONAL, BUT DON'T DELETE] .txt file containing a list of genes to plot, must match the name of genes in the datafile. Recommended to not use more than 10 genes, otherwise use a clustermap/heatmap.
    numgenes: 5 # [OPTIONAL, BUT DON'T DELETE] Number of top genes (or TFs) based on p-value to plot. Default value is 10. Will not be used if a file is given for genelist.

  # Use the following option if you wish to make a heatmap
  # example: sisana visualize heatmap params.yml
  heatmap: 
    datafile: ./example_inputs/lioness_df_indegree_3_decimal_places_subset_200_LumALumB_samps.csv # Path to file containing the expression or indegrees of each gene per sample
    filetype: csv # Type of input file, must be either "csv", "txt", or "tsv", where csv implies comma separated values and txt/tsv implies tab-separated
    statsfile: ./output/compare_means/comparison_mw_between_LumA_LumB_degree.txt # [OPTIONAL, BUT DON'T DELETE] Path to file with the comparison output performed between two groups. This file is created with "sisana compare means".
    metadata: ./example_inputs/BRCA_TCGA_200_LumA_LumB_samps_mapping_w_header.csv # Path to the csv metadata file mapping samples to groups (groups must match names of the groupnames arg), must have a header of the format 'name,group'.
    genelist: ./example_inputs/heatmap_genes.txt # .txt file containing a list of genes to plot, must match the name of genes in the datafile. 
    column_cluster: False # Flag ("True" or "False") for if you wish to perform hierarchical clustering on the columns. If False, then the samples will only be grouped according to the first category in category_label_columns   
    row_cluster: True # Flag ("True" or "False") for if you wish to perform hierarchical clustering on the genes   
    plot_gene_names: True # Flag ("True" or "False") for whether to plot the names of the genes on the rows of the heatmap
    plot_sample_names: False # Flag ("True" or "False") for whether to plot the names of the samples on the columns of the heatmap
    category_label_columns: # The names of columns (categories of samples) in the metadata file you wish to use for coloring the columns in the clustermap. The clustermap will be grouped by the first name given, unless column_cluster=True
      - group
    category_column_colors: # The matplotlib color codes you wish to use for the sub-categories given in category_label_columns. For example, a category called "Sex" may want to use ["pink", "blue"] as their colors (though SiSaNA has no way of determining which samples are female or male, so you may need to change the order you give the colors)
      - {'LumA': 'cornflowerblue', 
         'LumB': 'orange'}
    outdir: ./output/heatmap/ # Path to directory to output file to
    prefix: TCGA_200_LumA_LumB_samps # Prefix to use for the output file; note that the output file will automatically be generated with the suffix '_clustermap.png'

# Stage 5: Extract edges that connect to specified TFs or genes. Specify whether to use "genes" or "tfs" in the "sisana extract" command.
# example: sisana extract params.yml
extract:
  pickle: ./tmp/lioness.pickle # The path to the pickle file created in the "generate" step. By default, this will be made in the tmp directory.
  sampnames: ./tmp/samples.txt # The path to the tmp/samples.txt file, which is a text file that is generated in the preprocess step. By default, this will be made in the tmp directory.
  symbols: ./example_inputs/genes_to_extract.txt # The path to the file that contains the gene symbols of the TFs or genes (and their associated edges) you wish to extract
  outdir: ./output/extract/ # The directory to save the output file to
