<jupyter_start><jupyter_text>1- Generate the deletions<jupyter_code>#Load the appropriate model and set the constraints correctly to ensure that the minimal genome predictions take that into account
model = cobra.io.load_json_model('final_iJL208_28_07_2020.json')
#Load the different files and paths
# model = load_latest_model()
#Load the sensitivity analysis model that was used last 
data_path = '../data/minGenome'
#Essential genes file
essential_genes_file = os.path.join(data_path,"essentialGene.txt") 
#TUs
parameters_file = os.path.join(data_path,"genes_and_promoters.csv")
#Regulator genes
regulators_file = os.path.join(data_path,"regulatorGenes.txt")
#Promoters
TU_Json_file = os.path.join(data_path,"gene_promoter_dict.json")
#lp output filename
lpfilename = os.path.join(data_path,"mingenome_iJL208_10_15_2019.lp")
out_path = os.path.join(data_path,'Output')
growth_rate = model.slim_optimize()

minGenome.build_MIP_by_Cobrapy(model, 
                               growth_rate, 
                               essential_genes_file,
                               parameters_file,
                               regulators_file,
                               TU_Json_file,
                               out_path,
                               verbose=True,
                               solver='gurobi',
                               iterations=50)<jupyter_output>add reaction indicator
add GSM constraint
add cutting constraints
add TU constraint
add no start and essential genes
----------- 1 ------------
Status: Optimal
----------- 2 ------------
Status: Optimal
----------- 3 ------------
Status: Optimal
----------- 4 ------------
Status: Optimal
----------- 5 ------------
Status: Optimal
----------- 6 ------------
Status: Optimal
----------- 7 ------------
Status: Optimal
----------- 8 ------------
Status: Optimal
----------- 9 ------------
Status: Optimal
----------- 10 ------------
Status: Optimal
----------- 11 ------------
Status: Optimal
----------- 12 ------------
Status: Optimal
----------- 13 ------------
Status: Optimal
----------- 14 ------------
Status: Optimal
----------- 15 ------------
Status: Optimal
----------- 16 ------------
Status: Optimal
----------- 17 ------------
Status: Optimal
----------- 18 ------------
Status: Optimal
----------- 19 ------------
Status: Optimal
----------- 20 ------------
Status: Optimal
----------- [...]<jupyter_text>2- Analyze the deletions<jupyter_code>#Install tqdm 
#The exclamation mark sends this command to the terminal
# ! pip install tqdm --user
from tqdm import tqdm
#Load files
genes_and_promoters_file = os.path.join(data_path,"genes_and_promoters.csv")
genes_and_promoters = pd.read_csv(genes_and_promoters_file, index_col=0)
comparison_syn3_file = os.path.join(data_path, 'conservation_essentiality_syn3.csv')
comparison_syn3 = pd.read_csv(comparison_syn3_file, index_col=0) #add this file to the data folder
deletions_file = os.path.join(out_path, 'deletion_results_49.csv')
max_deletion_df = pd.read_csv(deletions_file, index_col=0)
max_deletion_df
#Get the deletion results
all_deletion_results = minGenome.get_deletion_results(max_deletion_df, genes_and_promoters, comparison_syn3) 
result_df = pd.DataFrame.from_records(all_deletion_results, 
                          columns=['Number of deleted genes',
                                   'Deleted genes',
                                   'Total length of deletions (bp)', 
                                   'MCC'])
#The result dataframe shows:
# - Total number of deleted genes at given deletion
# - The genes deleted by the current deletion
# - Total length of deletions at the current deletion
# - The Matthews Correlation Coefficient (MCC) of the gene deletions as compared to JCVI-syn3.0
result_df<jupyter_output><empty_output><jupyter_text>3- Visualize the results<jupyter_code>#Load the genbank sequence
from Bio import SeqIO
genbank = SeqIO.read('../Genomes/Mflorum.gbff','genbank')
#Add the number of deletions and genome size columns
result_df['Number of deletions'] = np.arange(1,len(result_df)+1)
result_df['Genome size'] = (len(genbank.seq) - result_df['Total length of deletions (bp)'])/1000
#Plot the number of deletions and final genome size
sb.set_style('whitegrid')
sb.set_context("talk",rc={'font.size':30.,
                            'grid.linewidth': .5,
                            'lines.linewidth': 1.,
                            'lines.markersize': 0.5,
                            'patch.linewidth': 0.5})

colors = sb.color_palette('cubehelix',10)
fontsize = 10
major_fontsize= 12
fig = plt.figure(figsize=(8,4))
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
#Plot the Number of deleted genes
result_df[:150].plot.scatter(x='Number of deletions',
                             y='Number of deleted genes',
                             color=[colors[5]],
                             ax=ax1)

ax1_xticks = np.arange(0, result_df[:150]['Number of deletions'].max()+10, 25)
ax1_yticks = np.arange(0, round(result_df[:150]['Number of deleted genes'].max()+10,-1), 25)

ax1.set_xticks(ax1_xticks)
ax1.set_xticklabels(ax1_xticks, fontsize=fontsize)
ax1.set_xlabel('Number of deletions', fontsize=major_fontsize)
ax1.set_yticks(ax1_yticks)
ax1.set_yticklabels(ax1_yticks,fontsize=fontsize)
ax1.set_ylabel('Deleted genes', fontsize=major_fontsize)
ax1.legend(['Deleted genes'],fontsize=fontsize,loc=3)
ax1.xaxis.grid(False)
ax1.yaxis.grid(False)

result_df[:150].plot.scatter(x='Number of deletions',
                             y='Genome size',
                             color=[colors[1]],
                             ax=ax2)

ax2_yticks = np.arange(0, round(result_df[:150]['Genome size'].max()+10,-2), 50).astype(int)
ax2.set_yticks(ax2_yticks)
ax2.set_yticklabels(ax2_yticks,fontsize=fontsize)
ax2.set_ylabel('Genome size (kbp)',fontsize=major_fontsize)
ax2.legend(['Genome size'],fontsize=fontsize,loc=4)
ax2.yaxis.grid(False)
plt.tight_layout()
ax2.plot([index_at_plateau,index_at_plateau],[490,result_df['Genome size'].max()],'--',linewidth=1.5,c='grey')
ax2.plot([0,result_df[:150]['Number of deletions'].max()],[531,531],'--',linewidth=1.5,c=colors[5])
plt.tight_layout()
# t = f"{max(result_df['Number of deleted genes'])} genes removed"
# plt.text(45,80,s=t,fontsize=20)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17657342657342656, 'fraction_numerical': 0.02940241576605213, 'mean_word_length': 2.496111111111111, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '542414', 'license': 'MIT', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1938, 'n_words': 410, 'path': 'Tutorials/4_Using_minGenome.ipynb', 'repo_name': 'Spherotob/iJL208', 'size': '6292'}