# Generate CCFs/gene-level calls

## 1. via `facets-suite`

* use `annotate-maf-wrapper.R` to generate CCFs&#x20;
* use `run-facets-wrapper.R` with `--everything` flag to generate gene/arm level calls

NOTE: Neither one is "review-aware". That is if a fit has manual reviews, then it is up to the analyst to choose the right now.&#x20;

## 2. via `facets-preview`

The `facets-preview` package contains two functions that are "review-aware" and enable generation of genomic calls both at sample- as well as cohort-level independent of the GUI.

### 2.1 `facetsPreview::generate_genomic_annotations`

This function generate `ccf.maf`, `gene-level` and `arm-level` calls for **every fit** for a given sample. For each fit manual reviews are incorporated and the "use purity run only?", "used edited cncf", "use purity" values are taken into consideration when generating ccfs. By default, the facets\_qc.txt is regenerated, although this is not always necessary. **Note**: mutations are expected to be in the file `<sample_id>.maf` in the top level directory. CCF annotation is ignored if the .maf is not found.

```
facetsPreview::generate_genomic_annotations(sample_id, sample_path, config_file, regenerate_qc = T)
```

### 2.2 `facetsPreview::compile_cohort_annotations`

Iterates through each sample in `samples_to_annotate` object (a data.frame/data.table with two columns: `sample_id` and `sample_path`), identifies the best fit and generates cohort level `gene-level.txt`, `arm-level.txt` and `ccf.maf`files. Note that this does not generate the genomic annotations and expects as a pre-requisite that `generate_genomic_annotations()` is already run for each sample. A fit is identified from the `facets_qc.txt`with the following order of precedence: (1) if a manually reviewed best fit is available, (2) if there is a `default` fit, and, if neither, (3) then choose an arbitrary fit.&#x20;

This function generates four output files:

* \<output\_prefix>.ccf.maf
* \<output\_prefix>.gene\_level.txt
* \<output\_prefix>.arm\_level.txt
* \<output\_prefix>.cohort.txt. This file contains the fit that was chosen.

*TODO*: Need to allow choosing a fit independent of the facets\_review. For example, through a column called `selected_fit` added to `samples_to_annotate`.

```
facetsPreview::compile_cohort_annotations(samples_to_annotate, output_prefix, ncores=10)
```
