Esempio n. 1
0
    def make(self) -> None:

        self.genome = GenomeLibrary()
        self.genome.make(bg_size=300,
                         bg_gc_content=0.45,
                         bg_rnd=self.make_generator())
        self.genome.bind(host=self)

        self.genexpr = GenomeExpression()
        self.genexpr.make(
            opt_primer_len=20,
            infl_prom_str=40,
            species_prom_str=0.057,
            regressor_file=DATADIR / 'expression_predictor' /
            'Ecol-Promoter-predictor.pkl',
            addparams_file=DATADIR / 'expression_predictor' /
            'Ecol-Promoter-AddParams.pkl',
        )
        self.genexpr.bind(host=self, genome=self.genome)

        path = DATADIR / 'metabolic_model' / 'e_coli_core.xml'
        model = cobra.io.read_sbml_model(str(path))
        self.metflux = MetabolicFlux()
        self.metflux.make(model=model)
        self.metflux.bind(host=self)
Esempio n. 2
0
    def make(self, opt_growth_temp: int, max_biomass: int, infl_prom_str: int,
             species_prom_str: int, opt_primer_len: int, regressor_file: Path,
             addparams_file: Path) -> None:

        if not alldef(opt_growth_temp, max_biomass, infl_prom_str,
                      species_prom_str, opt_primer_len, regressor_file,
                      addparams_file):
            raise HostException(
                "Host not initialized. Reason: incomplete arguments.")

        # Setup GenomeList module
        self.genome = GenomeList()
        self.genome.make()
        self.genome.bind(host=self)

        # Setup GenomeExpression module
        self.genexpr = GenomeExpression()
        self.genexpr.make(opt_primer_len=opt_primer_len,
                          infl_prom_str=infl_prom_str,
                          species_prom_str=species_prom_str,
                          regressor_file=regressor_file,
                          addparams_file=addparams_file)
        self.genexpr.bind(host=self, genome=self.genome)

        # Setup GrowthBehaviour module
        self.growth = GrowthBehaviour()
        self.growth.make(opt_growth_temp=opt_growth_temp,
                         max_biomass=max_biomass)
        self.growth.bind(host=self, genexpr=self.genexpr)
Esempio n. 3
0
    def copy(self, ref: 'EcolFluxHost') -> None:

        self.genome = GenomeLibrary()
        self.genome.copy(ref=ref.genome)
        self.genome.bind(host=self)

        self.genexpr = GenomeExpression()
        self.genexpr.copy(ref=ref.genexpr)
        self.genexpr.bind(host=self, genome=self.genome)

        self.metflux = MetabolicFlux()
        self.metflux.copy(ref=ref.metflux)
        self.metflux.bind(host=self)
Esempio n. 4
0
class EcolFluxHost(Host):

    genome: GenomeLibrary
    genexpr: GenomeExpression
    metflux: MetabolicFlux

    def make(self) -> None:

        self.genome = GenomeLibrary()
        self.genome.make(bg_size=300,
                         bg_gc_content=0.45,
                         bg_rnd=self.make_generator())
        self.genome.bind(host=self)

        self.genexpr = GenomeExpression()
        self.genexpr.make(
            opt_primer_len=20,
            infl_prom_str=40,
            species_prom_str=0.057,
            regressor_file=DATADIR / 'expression_predictor' /
            'Ecol-Promoter-predictor.pkl',
            addparams_file=DATADIR / 'expression_predictor' /
            'Ecol-Promoter-AddParams.pkl',
        )
        self.genexpr.bind(host=self, genome=self.genome)

        path = DATADIR / 'metabolic_model' / 'e_coli_core.xml'
        model = cobra.io.read_sbml_model(str(path))
        self.metflux = MetabolicFlux()
        self.metflux.make(model=model)
        self.metflux.bind(host=self)

    def copy(self, ref: 'EcolFluxHost') -> None:

        self.genome = GenomeLibrary()
        self.genome.copy(ref=ref.genome)
        self.genome.bind(host=self)

        self.genexpr = GenomeExpression()
        self.genexpr.copy(ref=ref.genexpr)
        self.genexpr.bind(host=self, genome=self.genome)

        self.metflux = MetabolicFlux()
        self.metflux.copy(ref=ref.metflux)
        self.metflux.bind(host=self)

    def sync(self) -> None:
        self.sync_modules([self.genome, self.genexpr, self.metflux])

    def edit_gene(self, gene_name: str, new_promoter: Seq) -> None:
        found_genes = [
            gene for gene in self.genome.locgenes if gene_name == gene.name
        ]
        if len(found_genes) > 0:
            self.emit(AlterGenePromoterEvent(found_genes[0], new_promoter))

    def optimize(self) -> CobraSolution:
        return self.metflux.optimize()
Esempio n. 5
0
    def copy(self, ref: RecHost) -> None:

        # Setup GenomeList module using the ref
        self.genome = GenomeList()
        self.genome.copy(ref=ref.genome)
        self.genome.bind(host=self)

        # Setup GenomeExpression module using the ref
        self.genexpr = GenomeExpression()
        self.genexpr.copy(ref=ref.genexpr)
        self.genexpr.bind(host=self, genome=self.genome)

        # Setup GrowthBehaviour module using the ref
        self.growth = GrowthBehaviour()
        self.growth.copy(ref=ref.growth)
        self.growth.bind(host=self, genexpr=self.genexpr)
Esempio n. 6
0
class RecHost(Host):

    growth: GrowthBehaviour

    genome: GenomeList

    genexpr: GenomeExpression

    ref_prom: str = 'GCCCATTGACAAGGCTCTCGCGGCCAGGTATAATTGCACG'

    def make(self, opt_growth_temp: int, max_biomass: int, infl_prom_str: int,
             species_prom_str: int, opt_primer_len: int, regressor_file: Path,
             addparams_file: Path) -> None:

        if not alldef(opt_growth_temp, max_biomass, infl_prom_str,
                      species_prom_str, opt_primer_len, regressor_file,
                      addparams_file):
            raise HostException(
                "Host not initialized. Reason: incomplete arguments.")

        # Setup GenomeList module
        self.genome = GenomeList()
        self.genome.make()
        self.genome.bind(host=self)

        # Setup GenomeExpression module
        self.genexpr = GenomeExpression()
        self.genexpr.make(opt_primer_len=opt_primer_len,
                          infl_prom_str=infl_prom_str,
                          species_prom_str=species_prom_str,
                          regressor_file=regressor_file,
                          addparams_file=addparams_file)
        self.genexpr.bind(host=self, genome=self.genome)

        # Setup GrowthBehaviour module
        self.growth = GrowthBehaviour()
        self.growth.make(opt_growth_temp=opt_growth_temp,
                         max_biomass=max_biomass)
        self.growth.bind(host=self, genexpr=self.genexpr)

    def copy(self, ref: RecHost) -> None:

        # Setup GenomeList module using the ref
        self.genome = GenomeList()
        self.genome.copy(ref=ref.genome)
        self.genome.bind(host=self)

        # Setup GenomeExpression module using the ref
        self.genexpr = GenomeExpression()
        self.genexpr.copy(ref=ref.genexpr)
        self.genexpr.bind(host=self, genome=self.genome)

        # Setup GrowthBehaviour module using the ref
        self.growth = GrowthBehaviour()
        self.growth.copy(ref=ref.growth)
        self.growth.bind(host=self, genexpr=self.genexpr)

    def sync(self) -> None:
        self.sync_modules([self.genome, self.genexpr, self.growth])

    def find_gene_or_abort(self, gene_name: str) -> Gene:
        """
        Find a gene by a given name or abort with an exception.
        Throws: HostException
        """
        gene: Optional[Gene] = first(self.genome.genes,
                                     lambda g: g.name == gene_name)
        # Find the first gene matching the name.
        if gene is None:
            raise HostException(
                "Host has not found the gene '{}'".format(gene_name))
        return gene

    def insert_gene(self, gene: Gene) -> None:
        self.emit(InsertGeneEvent(gene=gene, locus=0))

    def print_status(self) -> None:
        print("Host [{}]:".format(self.name))
        print("  seed plus counter = {} + {}".format(self.rnd_seed,
                                                     self.rnd_counter))
        print("  optimal growth temperature = {}".format(
            self.growth.opt_growth_temp))
        print("  max biomass = {}".format(self.growth.max_biomass))
        print("  optimal primer length = {}".format(
            self.genexpr.opt_primer_len))
        print("  Gene List: {} genes".format(len(self.genome.genes)))
        for gene in self.genome.genes:
            print("  - {} = {} * {}".format(gene.name, gene.prom, gene.orf))
        print("  Event History: {} events".format(len(self.event_log)))
        for el in self.event_log:
            print("  - {}".format(el))