# Calculating match percentages from the reference population

### Input

To calculate the null distribution of the p-values for the archaic matche percentages, users can use samples from reference populations (i.e. populations without introgression). Uses should provide a VCF file for genotype data from reference and source populations and another two files containing names of individuals from reference and source populations, which are similar to the [input](https://sstar.readthedocs.io/en/latest/userguide/score/#input) for calculating S\* scores.

Users can estimate the null distribution with the following command:

	sstar rmatch --vcf test.data.vcf --ref-ind test.ref.ind.list --src-ind nean.ind.list --output test.ref.match.pct.results

### Output

An example for the output is below:

| count | hap_len | hap_mapped_len_bin | hap_match_num | hap_tot_num | hap_dSNP_per_site_num | match_pct |
| -     | -       | -                  | -             | -           | -                     | -         |
| 1 | 50000 | 50000 | 0.0 | 10 | 0.655556 | 0.0 |

The meaning of each column:

- The `count` column is the number of haplotypes with the same statistics listed below.
- The `hap_len` column is the length of the haplotype.
- The `hap_mapped_len_bin` column is the length of the mapped regions in the haplotype.
- The `hap_match_num` column is the number of varaints with derived alleles both on the current haplotype and the source genomes.
- The `hap_tot_num` column is  the number of variants with derived alleles either on the current haplotype or the source genomes
- The `hap_dSNP_per_site_num` column is the average number of derived variants per site per haplotype.
- The `match_pct` column is the archaic match percentages.

### Settings

By default, `sstar` assumes the reference allele is the ancestral allele and the alternative allele is the dervied allele. Users can use the argument `--anc-allele` with a BED format file (e.g. [test.anc.allele.bed](https://github.com/xin-huang/sstar/blob/main/tests/data/test.anc.allele.bed)) to define the ancestral allele for each variant. If `--anc-allele` is used, then variants without ancestral allele information will be removed. Users also can provide a BED file (e.g. [test.mapped.region.bed](https://github.com/xin-huang/sstar/blob/main/tests/data/test.mapped.region.bed)) defining non-overlapping mapped regions with the argument `--mapped-region`. Besides, `sstar` uses a window size with 50,000 bp and step size with 10,000 bp. Users can change these settings with the arguments `--win-len` and `--win-step`. Finally, users can use `--thread` to specifiy numbers of CPUs in order to speed up the calculation. If users do not specify numbers of CPUs, `sstar` will use all CPUs for calculating S\* scores.
