Metadata-Version: 2.4
Name: randseq
Version: 0.1.0
Summary: Infer the DNA motifs bacterial defence systems restrict, from RandSeq random-insert plasmid libraries
Author-email: dbikard <dbikard@gmail.com>
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/dbikard/randseq
Project-URL: Documentation, https://dbikard.github.io/randseq
Project-URL: Changelog, https://github.com/dbikard/randseq/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/dbikard/randseq/issues
Keywords: restriction-modification,restriction site,defence systems,motif discovery,RandSeq,bacteria
Classifier: Natural Language :: English
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastcore
Requires-Dist: pandas
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: matplotlib
Requires-Dist: seaborn
Requires-Dist: tqdm
Requires-Dist: plotnine
Provides-Extra: fast
Requires-Dist: numba>=0.60; extra == "fast"
Dynamic: license-file

# randseq


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

## Installation

``` sh
$ pip install randseq
```

Optionally, with a compiled scan that is about 13x faster on 8 cores and gives identical results:

``` sh
$ pip install "randseq[fast]"
```

The development version installs from the GitHub [repository](https://github.com/dbikard/randseq):

``` sh
$ pip install git+https://github.com/dbikard/randseq.git
```

## Usage

RandSeq conjugates a library of plasmids with random inserts from a donor into a recipient strain
and counts each plasmid on both sides. A plasmid that carries a site the recipient’s defences
recognise is lost. The example here, `counts_panel.csv.gz`, is a library of 150 nt random inserts
counted in the donor (two replicates, `Control_R1` and `Control_R2`) and in 8 recipient strains in
two replicates each; `counts_panel_key.csv` says what each strain shows.

``` python
from randseq import calculate_log2fc, find_restricted_motifs, plot_motif_analysis, get_example_data_dir
import pandas as pd
```

``` python
# Read counts per plasmid: the donor library and 8 recipient strains, two replicates each
counts = pd.read_csv(os.path.join(get_example_data_dir(), "counts_panel.csv.gz"), index_col=0)
left, right = "GTCTAGGGCGGCGGTAAAAC", "ACTAGAGCACCAGAAGTCTA"   # vector sequence flanking the insert

# log2 fold change of each plasmid in each sample, against the first donor replicate
log2fc_df = calculate_log2fc(counts, reference_column="Control_R1")
```

[`find_restricted_motifs`](https://dbikard.github.io/randseq/core.html#find_restricted_motifs) searches one sample’s log2 fold changes for the motifs whose carriers
are depleted. It prints a log of its steps (not shown here) and returns the motifs it calls, in five
columns. For JJ1886 these are its three restriction-modification sites, the Type I site written as
one degenerate motif, `RTACNNNNGTG`:

``` python
motifs = find_restricted_motifs(log2fc_df["JJ1886_R1"], left, right)
```

``` python
motifs
```

<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>

|     | motif       | num_sequences | fraction_depleted | avg_log2fc | q_value      |
|-----|-------------|---------------|-------------------|------------|--------------|
| 0   | AAAGNNNNGTT | 913           | 0.997809          | -3.425663  | 0.000000e+00 |
| 1   | RTACNNNNGTG | 963           | 1.000000          | -3.285517  | 0.000000e+00 |
| 2   | GGTCTC      | 55            | 0.981818          | -2.851532  | 2.999895e-43 |

</div>

- `num_sequences`: the plasmids carrying the motif, of the 30,108 that pass the donor count filter.
- `fraction_depleted`: the share of them depleted, at log2FC below −0.5 after normalising to the
  sample’s median.
- `avg_log2fc`: the mean change of the carriers, relative to the sample’s median plasmid.
- `q_value`: significance, adjusted for the false-discovery rate across the hundreds of thousands
  of motifs tested. A motif is called when q \< 0.05 and most of its carriers are confidently
  depleted.

The plot shows the called motifs’ carriers among all plasmids, and their log2FC distribution:

``` python
fig, axes = plot_motif_analysis(counts, "JJ1886_R1", "Control_R1", motifs, left, right)
```

![](https://raw.githubusercontent.com/dbikard/randseq/v0.1.0/index_files/figure-commonmark/cell-6-output-1.png)

`all_motifs=True` also returns the motifs that were scored but not called, with diagnostic columns
and the reason for each verdict.
[Reading the result table](https://dbikard.github.io/randseq/core.html#reading-the-result-table)
in the core documentation explains them, and *The example panel at a glance* there runs every
strain of the panel.

## Documentation

The documentation is at [dbikard.github.io/randseq](https://dbikard.github.io/randseq/): one page per
module, each a walkthrough of the code with examples. The changes between versions are in
[CHANGELOG.md](https://github.com/dbikard/randseq/blob/main/CHANGELOG.md).
