Project: s41467-024-44907-x | Function: form_gamete1 (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Form gamete for dsx locus implementing gene drive homing mechanism with anti-drive inhibition

**KEY TERMS:** {
  "DRIVE": "gene drive allele",
  "ANTI_DRIVE": "anti-drive allele",
  "homing": "super-Mendelian inheritance",
  "mendelian": "standard Mendelian inheritance"
}

**CONTEXT CODE:**         '''
        self.age += time_step
        if self.stage == 'egg' and self.hatching and self.age >= self.time_to_hatch:
            self.stage = 'larva'
        elif self.stage == 'larva' and self.larva and self.age >= self.time_to_pupa:
            self.stage = 'pupa'
        elif self.stage == 'pupa' and self.pupa and self.age >= self.time_to_maturation:
            self.age = 0
            self.stage = 'adult'

    def will_develop(self):
        '''Will this individual develop into an adult?

        Returns:
           will_develop (bool)
               Wether the individual will eventually develop into an adult
        '''
        if self.stage == 'egg' and not self.hatching:
            return False
        elif self.stage == 'larva' and not self.larva:
            return False
        else:
            return True

    def is_alive(self):
        '''Is this individual still alive?

        Based on age, stage and development probabilities

        Returns:
           is_alive (bool)
               Wether the individual is still alive
        '''
        if self.stage == 'adult' and self.age > self.death:
            return False
        elif self.stage == 'egg' and not self.hatching:
            return False
        elif self.stage == 'larva' and not self.larva:
            return False
        elif self.stage == 'pupa' and not self.pupa:
            return False
        else:
            return True

    def _mendelian(self, genotype):
        if random.random() < 0.5:
            return sorted(genotype)[0]
        else:
            return sorted(genotype)[1]

    def form_gamete1(self, ):
        '''Form a gamete for locus 1 (dsx)

        If het. DRIVE homing may happen;
        the genotype at locus 2 may block homing

        Returns:
            genotype (str)
                Genotype at locus 1 for this gamete

        Example:
        >>> i.form_gamete1()
        W
        '''
        # MASKED: Form gamete for dsx locus implementing gene drive homing mechanism with anti-drive inhibition implementation
        raise NotImplementedError("This function is masked for testing purposes.")

    def form_gamete2(self):
        '''Form a gamete for locus 2 (antidote)

        Returns:
            genotype (str)
                Genotype at locus 2 for this gamete

        Example:
        >>> i.form_gamete2()
        A
        '''
        if self.hom2:
            return tuple(self.genotype2)[0]
        else:
            # anti-drive present?
            if self.p['ANTI_DRIVE'] in self.genotype2:
                if random.random() <= self.p['ANTIDOTE_INHERITANCE'][self.sex
                        ].get(self.get_genotype(), 1):
                    return self.p['ANTI_DRIVE']
                else:
                    # return the other allele
                    try:
                        return sorted(set(self.genotype1).difference((self.p['ANTI_DRIVE'],)))[0]
                    except Exception as e:
                        raise RuntimeError(self.genotype1, self.genotype2, str(e))
            # simple mendelian
            return self._mendelian(self.genotype2)

    def get_egg_mod(self):
        '''Get the genotype-specific modifier for the number of eggs

        Returns:
            modifier (float)
                Modifier for this genotype

        Example:
        >>> i.get_egg_mod()
        0.95
        '''
        return self.p['EGGS_MOD'][self.sex].get(self.get_genotype(), 1.)

    def get_hatching_mod(self):
        '''Get the genotype-specific modifier for the hatching rate

        Returns:
            modifier (float)
                Modifier for this genotype

        Example:
        >>> i.get_hatching_mod()
        0.95
        '''
        return self.p['HATCHING_MOD'][self.sex].get(self.get_genotype(), 1.)

    def get_deposition_mod(self):
        '''Get the genotype-specific modifier for the deposition prob

        Returns:
            modifier (float)
                Modifier for this genotype

        Example:
        >>> i.get_deposition_mod()
        0.95
        '''
        return self.p['DEPOSITION_MOD'][self.sex].get(self.get_genotype(), 1.)


def mate_all(population, p=None,
             multiple_mating_female=None,
             multiple_mating_male=None):
    '''Randomly mate all adults that can mate

    Args:
        population (iterable)
            All individuals in the population
        p (dict)
            Parameters
        multiple_mating_female (bool)
            Wether females can mate multiple times in their lifetime
        multiple_mating_male (bool)
            Wether males can mate multiple times in their lifetime



Complete the function implementation replacing "raise NotImplementedError".