# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

import glob
import pickle
import probanno
import cobra

universal = cobra.io.load_json_model("../Data/GramPosUni.json")
rxn_ids = [x.id for x in universal.reactions]

# Get IDs for original Prob files
original_files = glob.glob('../likelihoods/*.probs')
genome_ids = [x.replace("../likelihoods/","").replace(".probs","") for x in original_files]
# Get IDs for existing Prob files
existing_files = glob.glob('../likelihoods_py3/*.probs')
existing_prob_py3s = [x.replace("../likelihoods_py3/","").replace(".probs","") for x in existing_files]

likelihoods = pickle.load(open('../likelihoods/'+ genome_ids[0] +'.probs'))
rxn_ids_w_probs = []
for rxn_id in rxn_ids:
    try:
        likelihoods[rxn_id]
        rxn_ids_w_probs.append(rxn_id)
    except:
        pass

len(rxn_ids_w_probs)

for genome_id in genome_ids:
    if not genome_id in existing_prob_py3s:
        try:
            likelihoods = pickle.load(open('../likelihoods/'+ genome_id +'.probs'))
            likelihoods_py3 = {}
            for rxn_id in rxn_ids_w_probs:
                try:
                    likelihoods_py3[rxn_id] = likelihoods[rxn_id]
                except:
                    pass
            pickle.dump(likelihoods_py3, open('../likelihoods_py3/'+ genome_id +'.probs', "wb"))
        except: 
            pass

likelihoods_py3[rxn_id]

StarcoderdataJupyterScriptsDedupFiltered