plot_motif_analysis shows the whole library: donor against recipient counts, one point per plasmid, with the carriers of each called motif highlighted, and beside it the log2FC distribution of each motif’s carriers against all plasmids. Plasmids absent from the recipient sit at y = 1, because a pseudocount is added before the log. It answers did this strain restrict anything, and does each call look like one shifted population rather than a handful of outliers.
plot_motif_depletion takes motifs you supply instead of the ones the pipeline found: a motif REBASE predicts for the strain, or one called in another strain. It tests a specific hypothesis, including when the answer is that the motif was not restricted.
Read either plot beside the result table, whose columns answer separate questions:
q_value: how sure we are that the carriers are depleted more than their background allows by chance — the depletion rate, in this sample, of plasmids with the same insert GC content. It grows with support, so a weak effect on many plasmids can be very significant.
fraction_depleted: how strong the effect is, the share of carriers depleted. For a weak motif, compare it with background (with all_motifs=True).
bimodality (with all_motifs=True): whether the carriers’ log2FC form one population or two. The row is flagged bimodal when they do (coefficient above 5/9) and one of the two groups is at background level: some carriers destroyed, others untouched, the signature of a motif that dilutes a different site.
The histogram shows log2FC as calculate_log2fc returns it, median-normalised: the median plasmid is at 0, and the pipeline’s default depletion threshold is at -0.5 on this axis.
(fig, axes); (None, None) when counts_df is empty or lacks either column
Example: JJ1886 on the 20 nt library
countsTable.csv.gz is a run of the 20 nt library (11,629 inserts) through 19 strains, with the donor MFDpir as reference. JJ1886 at the default settings:
counts_file="countsTable.csv.gz"file_path=os.path.join(data_path,counts_file)counts=pd.read_csv(file_path, index_col=0)counts = counts[[col for col in counts.columns if ("_T0"in col) or ("MFDpir"in col)]]log2fc_df = calculate_log2fc(counts, reference_column='MFDpir', count_threshold=20, pseudocount=1)
left, right ="GTCCTAGGTATAATACTAGT", "GTTTTAGAGCTAGAAATAGC"motifs = find_restricted_motifs(log2fc_df["JJ1886_T0"], left, right)motifs
667 candidate(s) across all patterns; 464 remain after step 3.
158 candidate(s) that need the vector flanks, without enough internal sites (15 would otherwise be called).
293 candidate(s) whose score was borrowed from a stronger one.
28 motif(s) scored.
1 degenerate site(s) reported as one motif:
RTACNNNNGTG <- ATACNNNNGTG + CACNNNNGTAC
3 motif(s) called.
The three calls are JJ1886’s three RM sites: AAAGNNNNGTT, GGTCTC, and RTACNNNNGTG, reported as one motif from its two variants, ATACNNNNGTG and GTACNNNNGTG (the second read on the other strand, CACNNNNGTAC). Every carrier is destroyed: fraction_depleted is 1.
all_motifs=True also returns the motifs scored but not called, 24 here. Thirteen would be calls but need the vector flank and lack internal sites (core, Sites completed by the flank): CACANNAGTA has 190 of its 192 carriers depleted, but 188 of them read part of it in the flank, and its 4 internal carriers are too few to stand on. The rest fail the bound on the depleted fraction: CTTNCACA has 10 of its 20 carriers depleted (q ≈ 10⁻⁴), which bounds the fraction at 0.30, short of 0.5.
Custom-motif depletion plot
Donor against recipient counts, coloured by motifs you supply. A plasmid carrying several takes the colour of the last one in the list. Requires plotnine: the function returns a ggplot rather than drawing it, so a caller can add layers or save it at a set size, p.save(filename, width=6, height=5, units="in").
read counts, one row per insert, one column per sample
sample_col
str
the recipient sample to plot
ref_col
str
the input-library column it is compared with
motif_list
list
motifs to colour by, in IUPAC letters and/or bracketed classes
left_context
str
vector sequence 5’ of the insert
right_context
str
vector sequence 3’ of the insert
pseudocount
float
1
added to the counts per million, before the log
palette
list
['#F0A226', '#0A795B', '#800074']
one colour per motif, at least as many as motif_list
Example: JJ1886 on the 150 nt panel
counts_panel.csv.gz holds UMI counts for eight strains in duplicate and the Control input library (counts_panel_key.csv says what each strain shows), flanked by the contexts below. The calls use the defaults: log2FC median-normalised by calculate_log2fc, a plasmid counted as depleted at log2FC < -0.5, and a motif kept when at least half of its carriers are depleted (score ≥ 0.5).
The same comparison for motifs you name, without running the search: here JJ1886’s three RM sites as REBASE gives them. [AG] and the IUPAC R are equivalent.