####################################################################################################################################### 
##### 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 # (Required) Path to expression file, which MUST CONTAIN A HEADER
  filetype: tsv # (Required) The type of data file ("csv" or "tsv") being used.
  number: 5 # (Default: 5) The number of samples a gene must be expressed in. Genes not expressed in at least this number of samples will be removed.
  outdir: ./output/preprocess # (Optional, Default: ./output/preprocess) The directory to save the output to.

# Stage 2: Reconstruct networks and calculate degrees
# example: sisana reconstruct ./example_inputs/params.yml
reconstruct:
  exp: ./output/preprocess/BRCA_TCGA_20_LumA_LumB_samps_5000_genes_exp_preprocessed.txt # (Required) Path to the expression file (RNA-Seq or microarray). Must be in matrix format with unique genes as rows and sample names as columns.
  motif: ./example_inputs/motif_prior_names_2024.tsv # (Required) Path to the motif prior file. This file is generated with SPONGE. For most users, this file can be used for their analysis as well.
  ppi: ./example_inputs/ppi_prior_2024.tsv # (Required) Path to the PPI prior file. This file is generated with SPONGE. For most users, this file can be used for their analysis as well.
  method: lioness # (Optional, Default: lioness) Which method to use, either "panda" to run just PANDA or "lioness", which runs PANDA first, then LIONESS
  modeProcess: intersection # (Optional, Default: intersection) From netZooPy documentation: "legacy" refers to the processing mode in netZooPy<=0.5. "union" takes the union of all TFs and genes across priors and fills the missing genes in the priors with zeros. "intersection" takes the intersection of input genes and TFs across priors and removes the missing TFs/genes.
  pandafilepath: ./output/network/panda_network.txt # (Optional, Default: ./output/network/panda_network.txt) Path to the PANDA output file to be created. Must have a .txt extension.
  compute: cpu # (Optional, Default: cpu) Whether to use "gpu" or "cpu" for computing networks

  # The following commands are used if you specified "lioness" for the "method" arg
  ncores: 2 # (Optional, Default: 2) 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 # (Optional, Default: ./output/network/lioness_networks.npy) Path to the lioness output file to be created. Must have a .npy extension.
  start: # (Optional, Default: None, [meaning no parameter set in yaml]) An integer. To start from nth sample. The background is always what is used for PANDA and stays the same. If this value and the end value are not specified, then all samples will be used.
  end: # (Optional, Default: None, [meaning no parameter set in yaml]) An integer. To end at nth sample. Must be used when a value for "start" is specified. The background is always what is used for PANDA and stays the same

# Stage 2.5 (OPTIONAL): Combine the multiple degree files into a single output file. Only use if samples were "batched" when creating the single-sample 
#                       networks in the previous step (i.e. when "start" and "end" are set) and multiple "sets" of networks were created
# example: sisana combine ./example_inputs/params.yml
combine:
  degree_dir: ./output/network/ # (Optional, Default: ./output/network/) Directory where the degree files are stored 
  panda_file: ./output/network/panda_network.txt # (Optional, Default: ./output/network/panda_network.txt) Path to the panda network file
  networks: True # (Optional, Default: True) Flag for whether to also combine the resulting numpy networks from the previous step. Will result in significantly more RAM usage.
  delete_intermediate_files: True # (Optional, Default: True) Flag for whether to delete the intermediate output files from when specifying the start and end samples

#######################################################################################################################################
##### 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" command.
# Use the following if you wish to perform either a t-test, Mann-Whitney test, or their paired alternatives
# example: sisana compare ./example_inputs/params.yml
compare: 
  datafile: ./example_inputs/lioness_df_indegree_3_decimal_places_subset_200_LumALumB_samps.csv # (Required) Path to the data file (either expression, indegree, or outdegree)
  data_filetype: csv # (Required) Type of the datafile file. Must be either "csv", "txt", or "tsv", where csv implies comma separated values and txt/tsv implies tab-separated
  mapfile: ./example_inputs/BRCA_TCGA_200_LumA_LumB_samps_mapping_w_header.csv # (Required) Path to the mapping file, which maps sample name (column 1) to sample group (column 2). Groups cannot have "-" in the name. Assumes file has a header.
  map_filetype: csv # (Required) The type of mapping file ("csv" or "txt" or "tsv") being used
  groups:  # (Required) Names of the two groups (from the second column of mapfile) to be compared. The second group listed will be used as the numerator in the fold change calulation.
    - LumA
    - LumB
  datatype: degree # (Optional, Default: degree) The type of data being used (example: "expression" or "degree")
  testtype: mw # (Optional, Default: mw) Type of comparison to perform, either "tt" for Student's t-test, "mw" for Mann-Whitney U, "paired_tt", or "wilcoxon"
  rankby: mediandiff # (Optional, Default: mediandiff) The statistic to rank the .rnk output file by for GSEA. Choices are "mediandiff", "mwu", "neglogp", and "meandiff"
  outdir: ./output/compare_means/ # (Optional, Default: ./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 survival ./example_inputs/params.yml
survival:
  metadata: ./example_inputs/BRCA_TCGA_200_LumA_LumB_samps_survival_data.csv # (Required) 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 # (Required) Type of file, used to indicate the delimiter to use for metadata. Enter "csv" or "txt" for this.
  sampgroup_colname: PAM50_subtype # (Required) Name of column containing sample group names
  alivestatus_colname: Survival_status(False_equals_alive) # (Required) 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 # (Required) Name of column containing either the number of days an individual survived or the number of days to the last follow up.
  groups: # (Required) The names of the two groups (from the metadata file) to compare
    - LumA
    - LumB
  colors:  # (Required) The colors for each group, in the same order the groups appear in the groups arg. Supports matplotlib named colors (https://matplotlib.org/stable/gallery/color/named_colors.html)
    - cornflowerblue
    - orange  
  outdir: ./output/survival/ # (Optional, Default: ./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 # (Required) 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/c2.cp.reactome.v2023.2.Hs.symbols.gmt # (Required) Path to the gene set file in gmt format
  geneset: Reactome # (Required) 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.
  color: viridis # (Optional, Default: viridis) The color scheme to use for the dot plot (e.g. "Reds", "Blues", "viridis", etc.). See https://matplotlib.org/stable/tutorials/colors/colormaps.html for options.
  outdir: ./output/gsea/ # (Optional, Default: ./output/gsea/) The directory to save the output to

# Stage 5: 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 # (Required) 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) # (Required) 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
    groups:  # (Required) The names of the groups to plot
      - LumA
      - LumB    
    colors:  # (Required) The colors for each group, in the same order the groups appear in the groups arg. Supports matplotlib named colors (https://matplotlib.org/stable/gallery/color/named_colors.html)
      - cornflowerblue
      - orange
    adjpcol: FDR # (Optional, Default: FDR) The name of the column containing the adj. p-value
    xaxisthreshold: 50 # (Optional, Default: 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 # (Optional, Default: 0.05) Threshold to use for the adjusted p-value (y-axis)
    difftype: median # (Optional, Default: median) Choices are 'median' or 'mean'. Enter whether you are plotting the differences in medians or means. 
    outdir: ./output/volcano/ # (Optional, Default: ./output/volcano/) The directory to save the output to
    genelist: ./example_inputs/volcano_plot_genes.txt # (Required to have a 'genelist' parameter in this file. Do not set any value for this parameter (e.g. use "genelist: " instead of "genelist: file.txt") if you do not want to use a gene list and then set "top" to True). If you have a list of genes you want to label in a .txt file (with no header), enter the file name here. 
    top: False # (Required to have a 'top' value set in this file. Set to "False" if you do not want to label the top genes and then give a file as input to "genelist"). Flag for whether to automatically label the top values. Finds the top genes based on FDR and fold change.
    # numlabels: 15 # (Optional, Default: 15) Maximum number of values to label on each half of the plot. Will only be used if 'top' if set to True.

  # 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 # (Required) Path to file containing the expression, in-degree, or out-degree of each gene per sample.
    data_filetype: csv # (Required) Type of the datafile 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 # (Required) Path to TSV file containing the difference in mean/median degree, p-value, and FDR. This file is generated with "sisana compare means".
    metadata: ./example_inputs/BRCA_TCGA_200_LumA_LumB_samps_mapping_w_header.csv # (Required) Path to the csv metadata file mapping samples to groups (the names of groups in the group column must match names of the groups arg). Header must be in the format of "name,group". 
    metadata_filetype: csv # (Required) Type of the metadata file. Must be either "csv", "txt", or "tsv", where csv implies comma separated values and txt/tsv implies tab-separated
    groups:  # (Required) 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:  # (Required) The colors for each group, in the same order the groups appear in the groups arg. Supports matplotlib named colors (https://matplotlib.org/stable/gallery/color/named_colors.html)
      - cornflowerblue
      - orange      
    yaxisname: Indegree # (Required) Name to use for the y-axis
    plottype: boxplot # (Optional, Default: boxplot) The type of plot to create. Choices are "boxplot" or "violin"
    prefix: LumA_LumB_indegree # (Optional, Default: results) 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)
    outdir: ./output/plot_quantity/ # (Optional, Default: ./output/plot_quantity/) Path to directory to output file to
    genelist: ./example_inputs/quantity_plot_genes.txt # (Required to have a 'genelist' value set in this file. Do not set any value for this parameter (e.g. use "genelist: " instead of "genelist: file.txt") if you do not want to use a gene list and then set "top" to True) If you have a list of genes you want to label in a .txt file (with no header), enter the file name here. Recommended to not list more than 10 genes, otherwise visualize via a clustermap/heatmap.
    top: False # (Required to have a 'top' value set in this file. Set to "False" if you do not want to plot the top values and then give a file as input to "genelist"). Flag for whether to automatically plot the top values (e.g. TFs or genes). Finds the top genes based on FDR and fold change. 
    # numgenes: 5 # (Optional, Default: 10) Number of top genes (or TFs) based on p-value to plot. Will only be used if 'top' if set to True. Recommended to not list more than 10 genes, otherwise visualize via a clustermap/heatmap.

  # 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 # (Required) Path to file containing the expression or indegrees of each gene per sample
    data_filetype: csv # (Required) Type of the datafile 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 # (Required) 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 # (Required) 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'.
    metadata_filetype: csv # (Required) Type of metadata file, must be either "csv", "txt", or "tsv", where csv implies comma separated values and txt/tsv implies tab-separated
    genelist: ./example_inputs/heatmap_genes.txt # (Required) .txt file containing a list of genes to plot, must match the name of genes in the datafile. 
    category_label_columns: # (Required) The name of column (category 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: # (Required) The matplotlib color codes you wish to use for the sub-category given in category_label_column. For example, a category called "Sex" may want to use "pink" and "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'}
    data_color: RdBu_r # (Optional, Default: RdBu_r) The color scheme to use for the dot plot (e.g. "Reds", "Blues", "viridis", etc.). See https://matplotlib.org/stable/tutorials/colors/colormaps.html for options.
    column_cluster: False # (Optional, Default: 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 # (Optional, Default: True) Flag ("True" or "False") for if you wish to perform hierarchical clustering on the genes   
    plot_gene_names: True # (Optional, Default: False) Flag ("True" or "False") for whether to plot the names of the genes on the rows of the heatmap
    plot_sample_names: False # (Optional, Default: False) Flag ("True" or "False") for whether to plot the names of the samples on the columns of the heatmap
    outdir: ./output/heatmap/ # (Optional, Default: ./output/heatmap/) Path to directory to output file to
    prefix: TCGA_200_LumA_LumB_samps # (Optional, Default: results) Prefix to use for the output file; note that the output file will automatically be generated with the suffix '_clustermap.png'

############################################
# Additional commands you may wish to use
############################################
# 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:
  symbols: ./example_inputs/genes_to_extract.txt # (Required) The path to the file that contains the gene symbols of the TFs or genes (and their associated edges) you wish to extract
  pickle: ./tmp/lioness.pickle # (Optional, Default: ./tmp/lioness.pickle) The path to the pickle file created in the "reconstruct" step. By default, this will be made in the tmp directory.
  sampnames: ./tmp/samples.txt # (Optional, Default: ./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.
  outdir: ./output/extract/ # (Optional, Default: ./output/extract/) The directory to save the output file to

