# core


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L38"
target="_blank" style="float:right; font-size:smaller">source</a>

### filter_variants

>  filter_variants ()

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L28"
target="_blank" style="float:right; font-size:smaller">source</a>

### count_variants

>  count_variants (vcf_file)

*Count the number of variants in a VCF file using subprocess.*

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L75"
target="_blank" style="float:right; font-size:smaller">source</a>

### read_vcf

>  read_vcf (vcf_file)

*Reads a VCF file, automatically detecting the header and using correct
column names.*

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L96"
target="_blank" style="float:right; font-size:smaller">source</a>

### expand_multiallelic_variants

>  expand_multiallelic_variants (df_vcf)

*Extracts allele counts (RO, AO, DP) for each sample from the VCF
DataFrame and expands multi-allelic variants into separate rows.*

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L91"
target="_blank" style="float:right; font-size:smaller">source</a>

### find_index

>  find_index (format_value, field)

*Finds the index of a specific field (e.g., RO, AO, DP) in the FORMAT
column.*

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L154"
target="_blank" style="float:right; font-size:smaller">source</a>

### compute_frequencies

>  compute_frequencies (df_counts)

*Computes allele frequency (AF = AO / DP) for each sample in the
dataset.*

    /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/fastcore/docscrape.py:230: UserWarning: Unknown section Parameters:
      else: warn(msg)
    /opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/fastcore/docscrape.py:230: UserWarning: Unknown section Returns:
      else: warn(msg)

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L227"
target="_blank" style="float:right; font-size:smaller">source</a>

### add_ann_info_to_df

>  add_ann_info_to_df (df, info_column='INFO')

*Extract the first ANN annotation from the INFO field and add as
separate columns to a DataFrame.*

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L175"
target="_blank" style="float:right; font-size:smaller">source</a>

### extract_first_ann

>  extract_first_ann (info_field)

*Extract the first ANN annotation from a VCF INFO field.*

``` python
# Test with the example
info_field = 'AB=0;ABP=0;AC=1;AF=0.142857;AN=7;AO=248;CIGAR=1X;DP=664;DPB=664;DPRA=0;EPP=13.1322;EPPR=3.03118;GTI=0;LEN=1;MEANALT=1;MQM=60;MQMR=60;NS=7;NUMALT=1;ODDS=61.2192;PAIRED=0.991935;PAIREDR=0.995192;PAO=0;PQA=0;PQR=0;PRO=0;QA=8364;QR=13932;RO=416;RPL=137;RPP=8.92931;RPPR=9.04449;RPR=111;RUN=1;SAF=122;SAP=3.15039;SAR=126;SRF=210;SRP=3.09382;SRR=206;TYPE=snp;technology.illumina=1;ANN=G|synonymous_variant|LOW|cgd1_340|cgd1_340|transcript|cgd1_340-RA|protein_coding|1/1|c.357A>G|p.Ser119Ser|570/1483|357/1194|119/397||,G|upstream_gene_variant|MODIFIER|cgd1_320|cgd1_320|transcript|cgd1_320-RA|protein_coding||c.-4699T>C|||||4675|,G|upstream_gene_variant|MODIFIER|cgd1_330|cgd1_330|transcript|cgd1_330-RA|protein_coding||c.-1174T>C|||||1095|,G|upstream_gene_variant|MODIFIER|cgd1_350|cgd1_350|transcript|cgd1_350-RA|protein_coding||c.-1490A>G|||||1323|,G|downstream_gene_variant|MODIFIER|cgd1_360|cgd1_360|transcript|cgd1_360-RA|protein_coding||c.*4665T>C|||||4665|'
result = extract_first_ann(info_field)
print(result)
# Should output: {'allele': 'G', 'type': 'synonymous_variant', 'impact': 'LOW', 'gene_id': 'cgd1_340'}
```

    {'allele': 'G', 'type': 'synonymous_variant', 'impact': 'LOW', 'gene_id': 'cgd1_340'}

``` python
```

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }
&#10;    .dataframe tbody tr th {
        vertical-align: top;
    }
&#10;    .dataframe thead th {
        text-align: right;
    }
</style>

<table class="dataframe" data-quarto-postprocess="true" data-border="1">
<thead>
<tr style="text-align: right;">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">REF</th>
<th data-quarto-table-cell-role="th">ALT</th>
<th data-quarto-table-cell-role="th">AF_M7</th>
<th data-quarto-table-cell-role="th">AF_M5</th>
<th data-quarto-table-cell-role="th">AF_M4</th>
<th data-quarto-table-cell-role="th">AF_M6</th>
<th data-quarto-table-cell-role="th">AF_C3</th>
<th data-quarto-table-cell-role="th">AF_C2</th>
<th data-quarto-table-cell-role="th">AF_C1</th>
<th data-quarto-table-cell-role="th">INFO</th>
<th data-quarto-table-cell-role="th">variant_type</th>
<th data-quarto-table-cell-role="th">impact</th>
<th data-quarto-table-cell-role="th">gene_id</th>
<th data-quarto-table-cell-role="th">allele</th>
</tr>
<tr>
<th data-quarto-table-cell-role="th">#CHROM</th>
<th data-quarto-table-cell-role="th">POS</th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="5" data-quarto-table-cell-role="th"
data-valign="top">CM000429</td>
<td data-quarto-table-cell-role="th">76625</td>
<td>A</td>
<td>G</td>
<td>0.269231</td>
<td>0.350000</td>
<td>0.404762</td>
<td>0.314607</td>
<td>0.566265</td>
<td>0.303571</td>
<td>0.437500</td>
<td>AB=0;ABP=0;AC=1;AF=0.142857;AN=7;AO=248;CIGAR=...</td>
<td>synonymous_variant</td>
<td>LOW</td>
<td>cgd1_340</td>
<td>G</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">82019</td>
<td>A</td>
<td>T</td>
<td>0.908163</td>
<td>0.705882</td>
<td>0.779070</td>
<td>0.833333</td>
<td>0.628571</td>
<td>0.617284</td>
<td>0.690141</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=410;CIGAR=1X;DP=5...</td>
<td>synonymous_variant</td>
<td>LOW</td>
<td>cgd1_360</td>
<td>T</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">82192</td>
<td>G</td>
<td>A</td>
<td>0.894231</td>
<td>0.701493</td>
<td>0.666667</td>
<td>0.745098</td>
<td>0.471698</td>
<td>0.619565</td>
<td>0.602410</td>
<td>AB=0;ABP=0;AC=6;AF=0.857143;AN=7;AO=398;CIGAR=...</td>
<td>missense_variant</td>
<td>MODERATE</td>
<td>cgd1_360</td>
<td>A</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">106518</td>
<td>C</td>
<td>G</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=530;CIGAR=1X;DP=5...</td>
<td>missense_variant</td>
<td>MODERATE</td>
<td>cgd1_493</td>
<td>G</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">116718</td>
<td>C</td>
<td>A</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>0.989796</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=525;CIGAR=1X;DP=5...</td>
<td>upstream_gene_variant</td>
<td>MODIFIER</td>
<td>cgd1_520</td>
<td>A</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">...</td>
<td data-quarto-table-cell-role="th">...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td rowspan="5" data-quarto-table-cell-role="th"
data-valign="top">CM000436</td>
<td data-quarto-table-cell-role="th">1198389</td>
<td>T</td>
<td>A</td>
<td>1.000000</td>
<td>0.981818</td>
<td>1.000000</td>
<td>1.000000</td>
<td>0.987654</td>
<td>1.000000</td>
<td>1.000000</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=531;CIGAR=1X;DP=5...</td>
<td>missense_variant</td>
<td>MODERATE</td>
<td>cgd8_4800</td>
<td>A</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">1198626</td>
<td>A</td>
<td>C</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>0.987013</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=626;CIGAR=1X;DP=6...</td>
<td>3_prime_UTR_variant</td>
<td>MODIFIER</td>
<td>cgd8_4800</td>
<td>C</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">1198636</td>
<td>G</td>
<td>A</td>
<td>1.000000</td>
<td>1.000000</td>
<td>0.988889</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=650;CIGAR=1X;DP=6...</td>
<td>3_prime_UTR_variant</td>
<td>MODIFIER</td>
<td>cgd8_4800</td>
<td>A</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">1198801</td>
<td>C</td>
<td>G</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>1.000000</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=447;CIGAR=1X;DP=4...</td>
<td>3_prime_UTR_variant</td>
<td>MODIFIER</td>
<td>cgd8_4800</td>
<td>G</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">1210605</td>
<td>C</td>
<td>T</td>
<td>0.827586</td>
<td>0.718310</td>
<td>0.711111</td>
<td>0.781818</td>
<td>0.673684</td>
<td>0.735294</td>
<td>0.747573</td>
<td>AB=0;ABP=0;AC=7;AF=1;AN=7;AO=464;CIGAR=1X;DP=6...</td>
<td>synonymous_variant</td>
<td>LOW</td>
<td>cgd8_4840</td>
<td>T</td>
</tr>
</tbody>
</table>

<p>515 rows × 14 columns</p>
</div>

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L304"
target="_blank" style="float:right; font-size:smaller">source</a>

### clean_axes

>  clean_axes (ax, offset=10)

*Customizes a matplotlib axes by removing top and right spines, and
creating a broken axis effect where x and y axes don’t touch.*

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L267"
target="_blank" style="float:right; font-size:smaller">source</a>

### mod_hist_legend

>  mod_hist_legend (ax, title=False)

\*Creates a cleaner legend for histogram plots by using line elements
instead of patches.

Motivation: - Default histogram legends show rectangle patches which can
be visually distracting - This function creates a more elegant legend
with simple lines matching histogram edge colors - Positions the legend
outside the plot to avoid overlapping with data\*

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L340"
target="_blank" style="float:right; font-size:smaller">source</a>

### make_circos_plot

>  make_circos_plot (data)

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L564"
target="_blank" style="float:right; font-size:smaller">source</a>

### elbow_point

>  elbow_point (values)

*Find the elbow point in a curve using the maximum curvature method.*

<table>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>values</td>
<td>list</td>
<td>The y-values of the curve.</td>
</tr>
<tr>
<td><strong>Returns</strong></td>
<td><strong>int</strong></td>
<td><strong>The index of the elbow point.</strong></td>
</tr>
</tbody>
</table>

------------------------------------------------------------------------

<a
href="https://github.com/mtinti/cryptosporidium_host_adaptation/blob/main/cryptosporidium_host_adaptation/core.py#L416"
target="_blank" style="float:right; font-size:smaller">source</a>

### kmeans_cluster_analysis

>  kmeans_cluster_analysis (df, cluster_sizes, random_state=42,
>                               features=None, figsize=(12, 6),
>                               standardize=False, fill_na=False)

*Perform K-means clustering analysis on a pandas DataFrame and visualize
the results with both normalized inertia and silhouette scores on the
same plot.*

<table>
<colgroup>
<col style="width: 6%" />
<col style="width: 25%" />
<col style="width: 34%" />
<col style="width: 34%" />
</colgroup>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>df</td>
<td>pandas.DataFrame</td>
<td></td>
<td>The input data to cluster.</td>
</tr>
<tr>
<td>cluster_sizes</td>
<td>list</td>
<td></td>
<td>List of cluster sizes (k values) to evaluate.</td>
</tr>
<tr>
<td>random_state</td>
<td>int</td>
<td>42</td>
<td>Random seed for reproducibility (default: 42).</td>
</tr>
<tr>
<td>features</td>
<td>NoneType</td>
<td>None</td>
<td>List of column names to use for clustering. If None, all columns are
used.</td>
</tr>
<tr>
<td>figsize</td>
<td>tuple</td>
<td>(12, 6)</td>
<td>Figure size for the output plot (default: (12, 6)).</td>
</tr>
<tr>
<td>standardize</td>
<td>bool</td>
<td>False</td>
<td>Whether to standardize the features (default: False).</td>
</tr>
<tr>
<td>fill_na</td>
<td>bool</td>
<td>False</td>
<td>Whether to fill missing values with column means (default:
False).</td>
</tr>
<tr>
<td><strong>Returns</strong></td>
<td><strong>tuple</strong></td>
<td></td>
<td><strong>(figure, inertia_values, silhouette_values) - The matplotlib
figure object,<br>the list of inertia values, and the list of silhouette
scores.</strong></td>
</tr>
</tbody>
</table>
