"""Script to build GENREs using ModelSEEDpy and DNNGIORModelSEEDpy v0.4.2 comes with a hard constraint, it needs scikit-learn 0.24.2 which is compatible only with Python < 3.10Also, numpy needs to be 1.26.4Thus, this script needs to be performed with Python 3.9."""importosimportcobraimportargparsefrompathlibimportPath
[docs]defreconstruct(faa,outdir=None):frommodelseedpyimportMSBuilder,MSGenome# Set modelIdfaa_path=Path(faa)modelId=faa_path.stem# Init a MSGenome instancemsGenome=MSGenome.from_fasta(faa,split=' ')# Build your GEMmodel=MSBuilder.build_metabolic_model(model_id=modelId,genome=msGenome,index="0",classic_biomass=True,gapfill_model=False,gapfill_media=None,annotate_with_rast=True,allow_all_non_grp_reactions=True)# Save the GEM as a .sbml filemodelname=".".join([modelId,"draft.xml"])modelfile=os.path.join(outdir,modelname)cobra.io.write_sbml_model(cobra_model=model,filename=modelfile)returnmodelname
[docs]defgapfill(draft_model,outdir=None,medium=None):""" draft_model: Path to draft .xml medium: path to tab-separated file .tsv """importdnngiordraft_model_path=Path(draft_model)outdir=Path(outdir)ifoutdirisnotNoneelsePath(outdir)model_id=draft_model_path.stem.replace(".draft","")dng_gf=dnngior.Gapfill(draftModel=draft_model,medium=medium,objectiveName='bio1')print("Number of reactions added:",len(dng_gf.added_reactions))gapfilled_model=dng_gf.gapfilledModel.copy()modelfile=str(outdir/f"{model_id}.xml")try:cobra.io.write_sbml_model(cobra_model=gapfilled_model,filename=modelfile)print("✅ SBML successfully written:",modelfile)exceptExceptionase:print("❌ Failed to write SBML:",e)draft_model_path.unlink()
[docs]defmain():parser=argparse.ArgumentParser(description="Reconstruct a genome-scale metabolic network with ModelSEEDpy and DNNGIOR")parser.add_argument("--reconstruct","-r",action="store_true",help="Reconstruct with ModelSEEDpy")parser.add_argument("--gapfill","-g",action="store_true",help="Set true if you wish to gap-fill the draft reconstruction using DNNGIOR.")parser.add_argument("--faa","-f",help="Path to the protein file to be used.")parser.add_argument("--draft-model","-d",help="Path to the draft model to be gapfilled.")parser.add_argument("--outdir","-o",help="Path to directory where models will be saved.")parser.add_argument("--medium","-m",help="Path to 3-column tab separated file describing medium to be used for the gap-filling step.")args=parser.parse_args()ifargs.reconstruct:_=reconstruct(args.faa,args.outdir)ifargs.gapfill:gapfill(args.draft_model,args.outdir,args.medium)