|
| 1 | +import argparse |
| 2 | +from typing import List |
| 3 | +from SigProfilerAssignment import decomposition as decomp |
| 4 | + |
| 5 | + |
| 6 | +def parse_arguments_common(args: List[str], description: str) -> argparse.Namespace: |
| 7 | + parser = argparse.ArgumentParser(description=description) |
| 8 | + |
| 9 | + parser.add_argument( |
| 10 | + "samples", |
| 11 | + help="Path to the input somatic mutations file (if using segmentation file/mutational matrix) or input folder (mutation calling file/s).", |
| 12 | + ) |
| 13 | + parser.add_argument("output", help="Path to the output folder.") |
| 14 | + parser.add_argument( |
| 15 | + "--signatures", help="Path to the signatures file.", default=None |
| 16 | + ) |
| 17 | + parser.add_argument( |
| 18 | + "--signature_database", |
| 19 | + help="Path to the signature database file.", |
| 20 | + default=None, |
| 21 | + ) |
| 22 | + parser.add_argument( |
| 23 | + "--nnls_add_penalty", type=float, default=0.05, help="NNLS add penalty." |
| 24 | + ) |
| 25 | + parser.add_argument( |
| 26 | + "--nnls_remove_penalty", type=float, default=0.01, help="NNLS remove penalty." |
| 27 | + ) |
| 28 | + parser.add_argument( |
| 29 | + "--initial_remove_penalty", |
| 30 | + type=float, |
| 31 | + default=0.05, |
| 32 | + help="Initial remove penalty.", |
| 33 | + ) |
| 34 | + parser.add_argument( |
| 35 | + "--genome_build", |
| 36 | + default="GRCh37", |
| 37 | + help="The reference genome build (default: GRCh37). Supported genomes: {GRCh37, GRCh38, mm9, mm10, rn6}.", |
| 38 | + ) |
| 39 | + parser.add_argument( |
| 40 | + "--cosmic_version", |
| 41 | + type=float, |
| 42 | + default=3.4, |
| 43 | + help="COSMIC version (default: 3.4). Valid options: {1, 2, 3, 3.1, 3.2, 3.3, 3.4}.", |
| 44 | + ) |
| 45 | + parser.add_argument( |
| 46 | + "--make_plots", type=bool, default=True, help="Generate plots (default: True)." |
| 47 | + ) |
| 48 | + parser.add_argument( |
| 49 | + "--collapse_to_SBS96", |
| 50 | + type=bool, |
| 51 | + default=True, |
| 52 | + help="Collapse to SBS96 (default: True).", |
| 53 | + ) |
| 54 | + parser.add_argument( |
| 55 | + "--connected_sigs", |
| 56 | + type=bool, |
| 57 | + default=True, |
| 58 | + help="Connected signatures (default: True).", |
| 59 | + ) |
| 60 | + parser.add_argument( |
| 61 | + "--verbose", type=bool, default=False, help="Verbose output (default: False)." |
| 62 | + ) |
| 63 | + parser.add_argument( |
| 64 | + "--new_signature_thresh_hold", |
| 65 | + type=float, |
| 66 | + default=0.8, |
| 67 | + help="New signature threshold (default: 0.8).", |
| 68 | + ) |
| 69 | + parser.add_argument( |
| 70 | + "--exclude_signature_subgroups", |
| 71 | + default=None, |
| 72 | + help="Remove specific signature subgroups.", |
| 73 | + ) |
| 74 | + parser.add_argument( |
| 75 | + "--exome", |
| 76 | + type=bool, |
| 77 | + default=False, |
| 78 | + help="Use exome renormalized COSMIC signatures (default: False).", |
| 79 | + ) |
| 80 | + parser.add_argument( |
| 81 | + "--input_type", |
| 82 | + default="matrix", |
| 83 | + help="""Three accepted input types: "vcf", "seg:TYPE", "matrix". Default: "matrix". The accepted callers for TYPE are the following {"ASCAT", "ASCAT_NGS", "SEQUENZA", "ABSOLUTE", "BATTENBERG", "FACETS", "PURPLE", "TCGA"}.""", |
| 84 | + ) |
| 85 | + parser.add_argument( |
| 86 | + "--context_type", |
| 87 | + default="96", |
| 88 | + help="""Required context type if `input_type` is "vcf". Valid options: "96", "288", "1536", "DINUC", "ID". Default: "96".""", |
| 89 | + ) |
| 90 | + parser.add_argument( |
| 91 | + "--export_probabilities", |
| 92 | + type=bool, |
| 93 | + default=True, |
| 94 | + help="Export probabilities matrix per mutational context (default: True).", |
| 95 | + ) |
| 96 | + parser.add_argument( |
| 97 | + "--export_probabilities_per_mutation", |
| 98 | + type=bool, |
| 99 | + default=False, |
| 100 | + help="Export probabilities matrices per mutation (default: False).", |
| 101 | + ) |
| 102 | + |
| 103 | + return parser.parse_args(args) |
| 104 | + |
| 105 | + |
| 106 | +class CliController: |
| 107 | + def dispatch_decompose_fit(self, user_args: List[str]) -> None: |
| 108 | + parsed_args = parse_arguments_common( |
| 109 | + user_args, "Perform decomposition fitting on the input samples." |
| 110 | + ) |
| 111 | + decomp.spa_analyze( |
| 112 | + samples=parsed_args.samples, |
| 113 | + output=parsed_args.output, |
| 114 | + signatures=parsed_args.signatures, |
| 115 | + signature_database=parsed_args.signature_database, |
| 116 | + nnls_add_penalty=parsed_args.nnls_add_penalty, |
| 117 | + nnls_remove_penalty=parsed_args.nnls_remove_penalty, |
| 118 | + initial_remove_penalty=parsed_args.initial_remove_penalty, |
| 119 | + genome_build=parsed_args.genome_build, |
| 120 | + cosmic_version=parsed_args.cosmic_version, |
| 121 | + make_plots=parsed_args.make_plots, |
| 122 | + collapse_to_SBS96=parsed_args.collapse_to_SBS96, |
| 123 | + connected_sigs=parsed_args.connected_sigs, |
| 124 | + verbose=parsed_args.verbose, |
| 125 | + decompose_fit_option=True, |
| 126 | + denovo_refit_option=False, |
| 127 | + cosmic_fit_option=False, |
| 128 | + new_signature_thresh_hold=parsed_args.new_signature_thresh_hold, |
| 129 | + exclude_signature_subgroups=parsed_args.exclude_signature_subgroups, |
| 130 | + exome=parsed_args.exome, |
| 131 | + input_type=parsed_args.input_type, |
| 132 | + context_type=parsed_args.context_type, |
| 133 | + export_probabilities=parsed_args.export_probabilities, |
| 134 | + export_probabilities_per_mutation=parsed_args.export_probabilities_per_mutation, |
| 135 | + ) |
| 136 | + |
| 137 | + def dispatch_denovo_fit(self, user_args: List[str]) -> None: |
| 138 | + parsed_args = parse_arguments_common( |
| 139 | + user_args, "Perform de novo fitting on the input samples." |
| 140 | + ) |
| 141 | + decomp.spa_analyze( |
| 142 | + samples=parsed_args.samples, |
| 143 | + output=parsed_args.output, |
| 144 | + signatures=parsed_args.signatures, |
| 145 | + signature_database=parsed_args.signature_database, |
| 146 | + nnls_add_penalty=parsed_args.nnls_add_penalty, |
| 147 | + nnls_remove_penalty=parsed_args.nnls_remove_penalty, |
| 148 | + initial_remove_penalty=parsed_args.initial_remove_penalty, |
| 149 | + genome_build=parsed_args.genome_build, |
| 150 | + cosmic_version=parsed_args.cosmic_version, |
| 151 | + new_signature_thresh_hold=parsed_args.new_signature_thresh_hold, |
| 152 | + make_plots=parsed_args.make_plots, |
| 153 | + collapse_to_SBS96=parsed_args.collapse_to_SBS96, |
| 154 | + connected_sigs=parsed_args.connected_sigs, |
| 155 | + verbose=parsed_args.verbose, |
| 156 | + decompose_fit_option=False, |
| 157 | + denovo_refit_option=True, |
| 158 | + cosmic_fit_option=False, |
| 159 | + exome=parsed_args.exome, |
| 160 | + input_type=parsed_args.input_type, |
| 161 | + context_type=parsed_args.context_type, |
| 162 | + export_probabilities=parsed_args.export_probabilities, |
| 163 | + export_probabilities_per_mutation=parsed_args.export_probabilities_per_mutation, |
| 164 | + ) |
| 165 | + |
| 166 | + def dispatch_cosmic_fit(self, user_args: List[str]) -> None: |
| 167 | + parsed_args = parse_arguments_common( |
| 168 | + user_args, "Perform COSMIC fitting on the input samples." |
| 169 | + ) |
| 170 | + decomp.spa_analyze( |
| 171 | + samples=parsed_args.samples, |
| 172 | + output=parsed_args.output, |
| 173 | + signatures=parsed_args.signatures, |
| 174 | + signature_database=parsed_args.signature_database, |
| 175 | + nnls_add_penalty=parsed_args.nnls_add_penalty, |
| 176 | + nnls_remove_penalty=parsed_args.nnls_remove_penalty, |
| 177 | + initial_remove_penalty=parsed_args.initial_remove_penalty, |
| 178 | + genome_build=parsed_args.genome_build, |
| 179 | + cosmic_version=parsed_args.cosmic_version, |
| 180 | + make_plots=parsed_args.make_plots, |
| 181 | + collapse_to_SBS96=parsed_args.collapse_to_SBS96, |
| 182 | + connected_sigs=parsed_args.connected_sigs, |
| 183 | + verbose=parsed_args.verbose, |
| 184 | + decompose_fit_option=False, |
| 185 | + denovo_refit_option=False, |
| 186 | + cosmic_fit_option=True, |
| 187 | + exclude_signature_subgroups=parsed_args.exclude_signature_subgroups, |
| 188 | + exome=parsed_args.exome, |
| 189 | + input_type=parsed_args.input_type, |
| 190 | + context_type=parsed_args.context_type, |
| 191 | + export_probabilities=parsed_args.export_probabilities, |
| 192 | + export_probabilities_per_mutation=parsed_args.export_probabilities_per_mutation, |
| 193 | + sample_reconstruction_plots=False, |
| 194 | + ) |
0 commit comments