<jupyter_start><jupyter_text>Compare Transposon Counts<jupyter_code># A lot of this is not used, but we import it so we have it later!
import os
import sys
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import pandas as pd
import seaborn as sns
import numpy as np

import math
import re

from PhiSpyAnalysis import theils_u, DateConverter, printmd
from PhiSpyAnalysis import read_phages, read_gtdb, read_checkv, read_base_pp, read_categories, read_metadata, read_transposons

from scipy.stats import pearsonr, f_oneway
from sklearn.linear_model import LinearRegression
from sklearn import decomposition
from sklearn.ensemble import RandomForestClassifier

import statsmodels.api as sm
from statsmodels.formula.api import ols
from statsmodels.stats.multicomp import pairwise_tukeyhsd, tukeyhsd, MultiComparison
from statsmodels.multivariate.manova import MANOVA
phagesdf = read_phages(maxcontigs=-1)
phagesdf
tndf = read_transposons()
tndf
ptn = pd.merge(phagesdf, tndf, on='assembly_accession', how='inner')
ptn
ptn['Non-phage Transposases'] = ptn['Genome Transposases'] - ptn['Prophage Transposases']
#ptn['gtkb'] = ptn['non phage transposons']/(ptn['Genome length']-ptn['bp prophage'])*1000
ptn['gtkb'] = ptn['Non-phage Transposases']/ptn['Genome length']*1000
ptn['ptkb'] = (ptn['Prophage Transposases']/ptn['bp prophage'])*2000
ptn['gtkbr'] = round(ptn['gtkb'], 2)
ptn['ptkbr'] = round(ptn['ptkb'], 2)
ptn['ratio'] = ptn['ptkb']/ptn['gtkb']
ptn['ratio'].replace([np.inf, -np.inf], np.nan, inplace=True)
ptn
ptn['ratio'].replace([np.inf, -np.inf], np.nan, inplace=True)
ptnb = ptn[(ptn['gtkb'] > 0) & (ptn['ptkb'] > 0)]
ptnb['ratio'].max()
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(11, 8))
sns.scatterplot(x='gtkb', y='ptkb', data=ptn, label="Each genome", alpha=0.3, ax=ax)
sns.lineplot(x='gtkbr', y='ptkbr', data=ptnb, label="Mean + 95%CI", color='r', ax=ax)
xlim = ax.get_xlim()
xlim = (-0.005, 0.2)
ylim = ax.get_ylim()
sns.lineplot(x=[0,1], y=[0,1], style=True, legend=False, color='k', dashes=[(2,2)], ax=ax)
l = ax.set_xlim(xlim)
l = ax.set_ylim(ylim)
l = ax.set_xlabel("Transposons per kb genomic DNA")
l = ax.set_ylabel("Transposons per kb prophage DNA")
ax.spines['bottom'].set_position('zero')
ax.spines['left'].set_position('zero')
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
#l = plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.tight_layout()
#fig.savefig(f"images/transposons_per_kb.svg") ## too big!
fig.savefig(f"images/transposons_per_kb.png")
# read gtdb
gtdb = read_gtdb()
ptnc = pd.merge(ptn, gtdb[['assembly_accession', 'checkm_completeness']], on='assembly_accession', how='inner')
ptnc
maxx = max(ptn['gtkb'])
maxy = max(ptn['ptkb'])
ax = sns.scatterplot(x='gtkb', y='ptkb', data=ptnc, hue='checkm_completeness', palette=sns.color_palette("flare", as_cmap=True))
xlim = ax.get_xlim()
ylim = ax.get_ylim()
sns.lineplot(x=[0,1], y=[0,1], style=True, legend=False, color='k', dashes=[(2,2)], ax=ax)
l = ax.set_xlim(xlim)
l = ax.set_ylim(ylim)
l = plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1747448979591837, 'fraction_numerical': 0.017857142857142856, 'mean_word_length': 7.343085106382978, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '134604', 'license': 'MIT', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1269, 'n_words': 259, 'path': 'DataAnalysis/TransposonAnalysis.ipynb', 'repo_name': 'linsalrob/PhispyAnalysis', 'size': '3136'}