Mutate DNA with 1/mutation_chance chance
174177
def mutate(dna, dna_size, tune_params):
    """"""
    dna_out = []
    mutation_chance = 10
    for i in range(dna_size):
        if int(random.random()*mutation_chance) == 1:
            dna_out.append(random_val(i, tune_params))
        else:
            dna_out.append(dna[i])
    return dna_out
576359
def batch_mutate(self, mutation_map, consistency_level):
    
    self._seqid += 1
    d = self._reqs[self._seqid] = defer.Deferred()
    self.send_batch_mutate(mutation_map, consistency_level)
    return d
828380
function MUTATE_PROP_x(state, payload, PROP_SUBPROP, conf, propValue) {
    if (!isWhat.isArray(payload))
        payload = [payload];
    var ids = getIdsFromPayload(payload, conf, PROP_SUBPROP);
    if (!checkIdWildcardRatio(ids, PROP_SUBPROP, conf))
        return;
    var lastId = ids.pop();
    var propPathWithoutLast = PROP_SUBPROP.slice(0, -1);
    var pathWithIds = fillinPathWildcards(ids, propPathWithoutLast, state, conf);
    var ref = getDeepRef(state, pathWithIds);
    var newValue = getValueFromPayloadPiece(payload.pop());
    if (isWhat.isObject(newValue))
        newValue.id = lastId;
    if (isWhat.isObject(propValue))
        newValue = merge(propValue, newValue);
    return Vue.set(ref, lastId, newValue);
}
652768
def random_dna(n):
    '''

    '''
    return coral.DNA(''.join([random.choice('ATGC') for i in range(n)]))
1041829
def mutate(self, config):
        

        if config.single_structural_mutation:
            div = max(1,(config.node_add_prob + config.node_delete_prob +
                         config.conn_add_prob + config.conn_delete_prob))
            r = random()
            if r < (config.node_add_prob/div):
                self.mutate_add_node(config)
            elif r < ((config.node_add_prob + config.node_delete_prob)/div):
                self.mutate_delete_node(config)
            elif r < ((config.node_add_prob + config.node_delete_prob +
                       config.conn_add_prob)/div):
                self.mutate_add_connection(config)
            elif r < ((config.node_add_prob + config.node_delete_prob +
                       config.conn_add_prob + config.conn_delete_prob)/div):
                self.mutate_delete_connection()
        else:
            if random() < config.node_add_prob:
                self.mutate_add_node(config)

            if random() < config.node_delete_prob:
                self.mutate_delete_node(config)

            if random() < config.conn_add_prob:
                self.mutate_add_connection(config)

            if random() < config.conn_delete_prob:
                self.mutate_delete_connection()

        # Mutate connection genes.
        for cg in self.connections.values():
            cg.mutate(config)

        # Mutate node genes (bias, response, etc.).
        for ng in self.nodes.values():
            ng.mutate(config)
686242
public List<Biomorph> apply(List<Biomorph> selectedCandidates, Random rng)
    {
        List<Biomorph> mutatedPopulation = new ArrayList<Biomorph>(selectedCandidates.size());
        int mutatedGene = 0;
        int mutation = 1;
        for (Biomorph b : selectedCandidates)
        {
            int[] genes = b.getGenotype();

            mutation *= -1; // Alternate between incrementing and decrementing.
            if (mutation == 1) // After gene has been both incremented and decremented, move to next one.
            {
                mutatedGene = (mutatedGene + 1) % Biomorph.GENE_COUNT;
            }
            genes[mutatedGene] += mutation;
            int min = mutatedGene == Biomorph.LENGTH_GENE_INDEX ? Biomorph.LENGTH_GENE_MIN : Biomorph.GENE_MIN;
            int max = mutatedGene == Biomorph.LENGTH_GENE_INDEX ? Biomorph.LENGTH_GENE_MAX : Biomorph.GENE_MAX;
            if (genes[mutatedGene] > max)
            {
                genes[mutatedGene] = min;
            }
            else if (genes[mutatedGene] < min)
            {
                genes[mutatedGene] = max;
            }

            mutatedPopulation.add(new Biomorph(genes));
        }
        return mutatedPopulation;
    }
1232506
private static Mutation createMutation(byte[] colName, byte[] colValue, long timestamp) {
        if (colValue == null) {
            colValue = EMPTY_BYTES;
        }
        Column col = new Column();
        col.setName(colName);
        col.setValue(colValue);
        col.setTimestamp(timestamp);
        
        ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
        cosc.setColumn(col);
        
        Mutation mutation = new Mutation();
        mutation.setColumn_or_supercolumn(cosc);
        return mutation;
    }
222479
def generate_complementary_strand(strand1):
        """"""
        rise_adjust = (
            strand1.rise_per_nucleotide * strand1.axis.unit_tangent) * 2
        strand2 = NucleicAcidStrand.from_start_and_end(
            strand1.helix_end - rise_adjust, strand1.helix_start - rise_adjust,
            generate_antisense_sequence(strand1.base_sequence),
            phos_3_prime=strand1.phos_3_prime)
        ad_ang = dihedral(strand1[0]["C1'"]._vector, strand1.axis.start,
                          strand2.axis.start + rise_adjust,
                          strand2[-1]["C1'"]._vector)
        strand2.rotate(
            225.0 + ad_ang, strand2.axis.unit_tangent,
            point=strand2.helix_start)  # 225 is the base adjust
        return strand2
1344575
def mutate(self, info_in):
        
        # check self is not failed
        if self.failed:
            raise ValueError("{} cannot mutate as it has failed.".format(self))

        from transformations import Mutation
        info_out = type(info_in)(origin=self,
                                 contents=info_in._mutated_contents())
        Mutation(info_in=info_in, info_out=info_out)
1196006
def downsample(data, percent):
    
    n_genes = data.shape[0]
    n_cells = data.shape[1]
    new_data = data.copy()
    total_count = float(data.sum())
    to_remove = total_count*percent
    # sum of read counts per cell
    cell_sums = data.sum(0).astype(float)
    # probability of selecting genes per cell
    cell_gene_probs = data/cell_sums
    # probability of selecting cells
    cell_probs = np.array(cell_sums/total_count).flatten()
    cells_selected = np.random.multinomial(to_remove, pvals=cell_probs)
    for i, num_selected in enumerate(cells_selected):
        cell_gene = np.array(cell_gene_probs[:,i]).flatten()
        genes_selected = np.random.multinomial(num_selected, pvals=cell_gene)
        if sparse.issparse(data):
            genes_selected = sparse.csc_matrix(genes_selected).T
        new_data[:,i] -= genes_selected
    new_data[new_data < 0] = 0
    return new_data
1085293
def random_variant(variants, weights):
    
    total = 0
    accumulator = []
    for w in weights:
        total += w
        accumulator.append(total)

    r = randint(0, total - 1)
    yield variants[bisect(accumulator, r)]
920682
def mutate_stream (instream, outstream):
    """"""

    chunk = None
    key = None
    data = None
    misclines = []

    for fullline in instream:
        line = fullline.split ('#', 1)[0]

        m = sectionre.match (line)
        if m is not None:
            # New chunk
            if chunk is not None:
                if key is not None:
                    chunk.data.set_one (key, data.strip ().decode ('utf8'))
                    key = data = None
                yield chunk
                chunk.emit (outstream)

            chunk = FileChunk ()
            for miscline in misclines:
                chunk._addLine (miscline, None)
            misclines = []
            chunk.data.section = m.group (1)
            chunk._addLine (fullline, None)
            continue

        if len (line.strip ()) == 0:
            if key is not None:
                chunk.data.set_one (key, data.strip ().decode ('utf8'))
                key = data = None
            if chunk is not None:
                chunk._addLine (fullline, None)
            else:
                misclines.append (fullline)
            continue

        m = escre.match (fullline)
        if m is not None:
            if chunk is None:
                raise InifileError ('key seen without section!')
            if key is not None:
                chunk.data.set_one (key, data.strip ().decode ('utf8'))
            key = m.group (1)
            data = m.group (2).replace (r'\"', '"').replace (r'\n', '\n').replace (r'\\', '\\')
            chunk.data.set_one (key, data.decode ('utf8'))
            chunk._addLine (fullline, key)
            key = data = None
            continue

        m = keyre.match (line)
        if m is not None:
            if chunk is None:
                raise InifileError ('key seen without section!')
            if key is not None:
                chunk.data.set_one (key, data.strip ().decode ('utf8'))
            key = m.group (1)
            data = m.group (2)
            if not data[-1].isspace ():
                data += ' '
            chunk._addLine (fullline, key)
            continue

        if line[0].isspace () and key is not None:
            data += line.strip () + ' '
            chunk._addLine (fullline, key)
            continue

        raise InifileError ('unparsable line: ' + line[:-1])

    if chunk is not None:
        if key is not None:
            chunk.data.set_one (key, data.strip ().decode ('utf8'))
        yield chunk
        chunk.emit (outstream)
988220
public List<Biomorph> apply(List<Biomorph> selectedCandidates, Random rng)
    {
        List<Biomorph> mutatedPopulation = new ArrayList<Biomorph>(selectedCandidates.size());
        for (Biomorph biomorph : selectedCandidates)
        {
            mutatedPopulation.add(mutateBiomorph(biomorph, rng));
        }
        return mutatedPopulation;
    }
432456
def add_gene(self, gene):
        
        logger.debug("Adding gene {0} to variant {1}".format(
            gene, self['variant_id']))
        self['genes'].append(gene)
983899
def create_random(cls, length, **kwargs):
        
        dna = ''.join([random.choice(cls.GENETIC_MATERIAL_OPTIONS) for _ in range(length)])
        return cls(dna, **kwargs)
1014825
def mutate_add_connection(self, config):
        '''
        
        '''
        possible_outputs = list(iterkeys(self.nodes))
        out_node = choice(possible_outputs)

        possible_inputs = possible_outputs + config.input_keys
        in_node = choice(possible_inputs)

        if in_node == out_node:
            return

        # # Don't duplicate connections.
        # key = (in_node, out_node)
        # if key in self.connections:
        #     return

        cg = self.create_connection(config, in_node, out_node)
        self.connections[cg.key] = cg
1123336
def _next_mutation(self):
        '''
        
        '''
        if self._keep_running():
            current_idx = self.model.current_index()
            self.session_info.current_index = current_idx
            next_idx = self._test_list.current()
            if next_idx is None:
                return False
            skip = next_idx - current_idx - 1
            if skip > 0:
                self.model.skip(skip)
            self._test_list.next()
            resp = self.model.mutate()
            return resp
        return False