Create a partially-connected genome,
        with (unless no hidden nodes) no direct input-output connections.
184751
def connect_partial_nodirect(self, config):
        
        assert 0 <= config.connection_fraction <= 1
        all_connections = self.compute_full_connections(config, False)
        shuffle(all_connections)
        num_to_add = int(round(len(all_connections) * config.connection_fraction))
        for input_id, output_id in all_connections[:num_to_add]:
            connection = self.create_connection(config, input_id, output_id)
            self.connections[connection.key] = connection
266042
def configure_crossover(self, genome1, genome2, config):
        
        assert isinstance(genome1.fitness, (int, float))
        assert isinstance(genome2.fitness, (int, float))
        if genome1.fitness > genome2.fitness:
            parent1, parent2 = genome1, genome2
        else:
            parent1, parent2 = genome2, genome1

        # Inherit connection genes
        for key, cg1 in iteritems(parent1.connections):
            cg2 = parent2.connections.get(key)
            if cg2 is None:
                # Excess or disjoint gene: copy from the fittest parent.
                self.connections[key] = cg1.copy()
            else:
                # Homologous gene: combine genes from both parents.
                self.connections[key] = cg1.crossover(cg2)

        # Inherit node genes
        parent1_set = parent1.nodes
        parent2_set = parent2.nodes

        for key, ng1 in iteritems(parent1_set):
            ng2 = parent2_set.get(key)
            assert key not in self.nodes
            if ng2 is None:
                # Extra gene: copy from the fittest parent
                self.nodes[key] = ng1.copy()
            else:
                # Homologous gene: combine genes from both parents.
                self.nodes[key] = ng1.crossover(ng2)
116815
def _create_no_protein(self):
        """"""
        alt_data = AltTranscriptData([],
                                     None,
                                     None,
                                     False,
                                     None,
                                     self._transcript_data.protein_accession,
                                     is_ambiguous=False)
        return alt_data
1094094
def make_network(
            allele_encoding_dims,
            kmer_size,
            peptide_amino_acid_encoding,
            embedding_input_dim,
            embedding_output_dim,
            allele_dense_layer_sizes,
            peptide_dense_layer_sizes,
            peptide_allele_merge_method,
            peptide_allele_merge_activation,
            layer_sizes,
            dense_layer_l1_regularization,
            dense_layer_l2_regularization,
            activation,
            init,
            output_activation,
            dropout_probability,
            batch_normalization,
            embedding_init_method,
            locally_connected_layers):
        

        # We import keras here to avoid tensorflow debug output, etc. unless we
        # are actually about to use Keras.

        from keras.layers import Input
        import keras.layers
        from keras.layers.core import Dense, Flatten, Dropout
        from keras.layers.embeddings import Embedding
        from keras.layers.normalization import BatchNormalization

        if peptide_amino_acid_encoding == "embedding":
            peptide_input = Input(
                shape=(kmer_size,), dtype='int32', name='peptide')
            current_layer = Embedding(
                input_dim=embedding_input_dim,
                output_dim=embedding_output_dim,
                input_length=kmer_size,
                embeddings_initializer=embedding_init_method,
                name="peptide_embedding")(peptide_input)
        else:
            peptide_input = Input(
                shape=(
                    kmer_size,
                    vector_encoding_length(peptide_amino_acid_encoding)),
                dtype='float32',
                name='peptide')
            current_layer = peptide_input

        inputs = [peptide_input]

        kernel_regularizer = None
        l1 = dense_layer_l1_regularization
        l2 = dense_layer_l2_regularization
        if l1 > 0 or l2 > 0:
            kernel_regularizer = keras.regularizers.l1_l2(l1, l2)

        for (i, locally_connected_params) in enumerate(locally_connected_layers):
            current_layer = keras.layers.LocallyConnected1D(
                name="lc_%d" % i,
                **locally_connected_params)(current_layer)

        current_layer = Flatten(name="flattened_0")(current_layer)

        for (i, layer_size) in enumerate(peptide_dense_layer_sizes):
            current_layer = Dense(
                layer_size,
                name="peptide_dense_%d" % i,
                kernel_regularizer=kernel_regularizer,
                activation=activation)(current_layer)

        if batch_normalization:
            current_layer = BatchNormalization(name="batch_norm_early")(
                current_layer)

        if dropout_probability:
            current_layer = Dropout(dropout_probability, name="dropout_early")(
                current_layer)

        if allele_encoding_dims:
            allele_input = Input(
                shape=allele_encoding_dims,
                dtype='float32',
                name='allele')
            inputs.append(allele_input)
            allele_embedding_layer = Flatten(name="allele_flat")(allele_input)

            for (i, layer_size) in enumerate(allele_dense_layer_sizes):
                allele_embedding_layer = Dense(
                    layer_size,
                    name="allele_dense_%d" % i,
                    kernel_regularizer=kernel_regularizer,
                    activation=activation)(allele_embedding_layer)

            if peptide_allele_merge_method == 'concatenate':
                current_layer = keras.layers.concatenate([
                    current_layer, allele_embedding_layer
                ], name="allele_peptide_merged")
            elif peptide_allele_merge_method == 'multiply':
                current_layer = keras.layers.multiply([
                    current_layer, allele_embedding_layer
                ], name="allele_peptide_merged")
            else:
                raise ValueError(
                    "Unsupported peptide_allele_encoding_merge_method: %s"
                    % peptide_allele_merge_method)

            if peptide_allele_merge_activation:
                current_layer = keras.layers.Activation(
                    peptide_allele_merge_activation,
                    name="alelle_peptide_merged_%s" %
                         peptide_allele_merge_activation)(current_layer)
            
        for (i, layer_size) in enumerate(layer_sizes):
            current_layer = Dense(
                layer_size,
                activation=activation,
                kernel_regularizer=kernel_regularizer,
                name="dense_%d" % i)(current_layer)

            if batch_normalization:
                current_layer = BatchNormalization(name="batch_norm_%d" % i)\
                    (current_layer)

            if dropout_probability > 0:
                current_layer = Dropout(
                    dropout_probability, name="dropout_%d" % i)(current_layer)

        output = Dense(
            1,
            kernel_initializer=init,
            activation=output_activation,
            name="output")(current_layer)
        model = keras.models.Model(
            inputs=inputs,
            outputs=[output],
            name="predictor")
        return model
500121
def make_organisms(self, genome_list, genome_dir): 

        '''

            '''

        for genome in genome_list:

            genome_path = genome_dir + genome
            handle = open(genome_path, "rU")
            print 'Adding organism attributes for', genome

            try:
                seq_record = SeqIO.read(handle, "genbank")

                self.organisms.append(Organism(seq_record, genome_path, self))

                del(seq_record)

            except ValueError,e:
                print genome, str(e)

            except AssertionError,e:
                print genome, str(e)

            except UnboundLocalError,e:
                print genome, str(e)

            handle.close()
1230161
def shrink_to_node(self, scc):
        """"""
        assert not self.final, 'Trying to mutate a final graph.'
        self.graph.add_node(scc)
        edges = list(self.graph.edges)
        for k, v in edges:
            if k not in scc and v in scc:
                self.graph.remove_edge(k, v)
                self.graph.add_edge(k, scc)
            elif k in scc and v not in scc:
                self.graph.remove_edge(k, v)
                self.graph.add_edge(scc, v)
        for node in scc.nodes:
            self.graph.remove_node(node)
241545
def subset_to_genome(in_file, out_file, data):
    
    if not utils.file_uptodate(out_file, in_file):
        contigs = set([x.name for x in ref.file_contigs(dd.get_ref_file(data))])
        with utils.open_gzipsafe(in_file) as in_handle:
            with file_transaction(data, out_file) as tx_out_file:
                with open(tx_out_file, "w") as out_handle:
                    for line in in_handle:
                        parts = line.split()
                        if parts and parts[0] in contigs:
                            out_handle.write(line)
    return out_file
50144
def importRemoteGenome(name, batchSize = 100) :
	""""""
	try :
		dw = listRemoteDatawraps()["Flat"]["Reference genomes"][name]
	except AttributeError :
		raise AttributeError("There's no remote genome datawrap by the name of: '%s'" % name)

	finalFile = _DW(name, dw["url"])
	PG.importGenome(finalFile, batchSize)
908970
private void createMissingSpanningRelations(SDocumentGraph graph,
    FastInverseMap<Long, SNode> nodeByRankID,
    TreeMap<Long, SToken> tokenByIndex,
    Map<String, ComponentEntry> componentForSpan,
    AtomicInteger numberOfRelations)
  {

    // add the missing spanning relations for each continuous span of the graph
    for (SSpan span : graph.getSpans())
    {
      long pre=1;
      RelannisNodeFeature featSpan = RelannisNodeFeature.extract(span);      
      ComponentEntry spanComponent = componentForSpan.get(span.getId());
      if (spanComponent != null && featSpan != null 
        && featSpan.getLeftToken() >= 0 && featSpan.getRightToken() >= 0)
      {
        for (long i = featSpan.getLeftToken(); i <= featSpan.getRightToken();
          i++)
        {
          SToken tok = tokenByIndex.get(i);
          if (tok != null)
          {
            boolean missing = true;
            List<SRelation<SNode, SNode>> existingRelations = graph.getRelations(span.getId(),
              tok.getId());
            if (existingRelations != null)
            {
              for (Relation e : existingRelations)
              {
                if (e instanceof SSpanningRelation)
                {
                  missing = false;
                  break;
                }
              }
            } // end if relations exist

            if (missing)
            {
              String type = "c";

              SLayer layer
                = findOrAddSLayer(spanComponent.getNamespace(), graph);

              createNewRelation(graph, span, tok, null, type,
                spanComponent.getId(), layer,
                pre++, nodeByRankID, numberOfRelations);
            }
          } // end if token exists
        } // end for each covered token index
      }
    } // end for each span
  }
951981
def add_highdepth_genome_exclusion(items):
    
    out = []
    for d in items:
        d = utils.deepish_copy(d)
        if dd.get_coverage_interval(d) == "genome":
            e = dd.get_exclude_regions(d)
            if "highdepth" not in e:
                e.append("highdepth")
                d = dd.set_exclude_regions(d, e)
        out.append(d)
    return out
386255
function cloneNode (n) {
    var c = {
        __association_score: n.__association_score,
        __evidence_count: n.__evidence_count,
        id: n.id,
        __id: n.__id,
        __name: n.__name,
        target: {
            id: n.target.id,
            name: n.target.gene_info.name,
            symbol: n.target.gene_info.symbol
        },
        disease: cloneDisease(n.disease),
        association_score: cloneAssociationScore(n.association_score),
        evidence_count: cloneEvidenceCount(n.evidence_count)
    };
    if (n.is_direct) {
        c.is_direct = n.is_direct;
    }
    return c;
}
604776
def create_features(bam_in, loci_file, reference, out_dir):
    
    lenvec_plus = op.join(out_dir, 'genomic_lenvec.plus')
    lenvec_minus = op.join(out_dir, 'genomic_lenvec.minus')
    compute_genomic_cmd = ("compute_genomic_lenvectors "
                           "{bam_in} {lenvec_plus} "
                           "{lenvec_minus} "
                           "{min_len} "
                           "{max_len} ")
    index_genomic_cmd = ("index_genomic_lenvectors "
                         "{lenvec} ")
    genomic_lenvec = op.join(out_dir, 'genomic_lenvec')
    feat_len_file = op.join(out_dir, 'feat_lengths.txt')
    compute_locus_cmd = ("compute_locus_lenvectors "
                         "{loci_file} "
                         "{genomic_lenvec} "
                         "{min_len} "
                         "{max_len} "
                         "> {feat_len_file}")
    cov_S_file = op.join(out_dir, 'loci.cov_anti')
    coverage_anti_cmd = ("coverageBed -S -counts -b "
                         "{bam_in} -a {loci_file} "
                         "> {cov_S_file}")
    feat_posentropy = op.join(out_dir, 'feat_posentropy.txt')
    entropy_cmd = ("compute_locus_entropy.rb "
                   "{counts_reads} "
                   "> {feat_posentropy}")
    with utils.chdir(out_dir):
        run(compute_genomic_cmd.format(min_len=min_trimmed_read_len, max_len=max_trimmed_read_len, **locals()), "Run compute_genomic")
        run(index_genomic_cmd.format(lenvec=lenvec_plus), "Run index in plus")
        run(index_genomic_cmd.format(lenvec=lenvec_minus), "Run index in minus")
        run(compute_locus_cmd.format(min_len=min_trimmed_read_len, max_len=max_trimmed_read_len, **locals()), "Run compute locus")
        run(coverage_anti_cmd.format(**locals()), "Run coverage antisense")
        feat_antisense = _order_antisense_column(cov_S_file, min_trimmed_read_len)

        counts_reads = _reads_per_position(bam_in, loci_file, out_dir)
        run(entropy_cmd.format(**locals()), "Run entropy")

        rnafold = calculate_structure(loci_file, reference)
1241886
def clone(self, ignore=()):
        
        nodes = [
            clone(node, self.substitutions, ignore)
            for node in toposorted(self.nodes, self.edges)
        ]
        return DAG(nodes=nodes, substitutions=self.substitutions).build_edges()
1178598
def _add_non_batch(self, TX_nodes, PmtInf_nodes):
        
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtInfIdNode'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtMtdNode'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['BtchBookgNode'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['NbOfTxsNode'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CtrlSumNode'])

        PmtInf_nodes['SvcLvlNode'].append(PmtInf_nodes['Cd_SvcLvl_Node'])
        PmtInf_nodes['LclInstrmNode'].append(PmtInf_nodes['Cd_LclInstrm_Node'])
        PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['SvcLvlNode'])
        PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['LclInstrmNode'])
        PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['SeqTpNode'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtTpInfNode'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ReqdColltnDtNode'])

        PmtInf_nodes['CdtrNode'].append(PmtInf_nodes['Nm_Cdtr_Node'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrNode'])

        PmtInf_nodes['Id_CdtrAcct_Node'].append(
            PmtInf_nodes['IBAN_CdtrAcct_Node'])
        PmtInf_nodes['CdtrAcctNode'].append(PmtInf_nodes['Id_CdtrAcct_Node'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrAcctNode'])

        if 'BIC' in self._config:
            PmtInf_nodes['FinInstnId_CdtrAgt_Node'].append(
                PmtInf_nodes['BIC_CdtrAgt_Node'])
        PmtInf_nodes['CdtrAgtNode'].append(
            PmtInf_nodes['FinInstnId_CdtrAgt_Node'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrAgtNode'])

        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ChrgBrNode'])

        if self.schema == 'pain.008.001.02':
            PmtInf_nodes['CdtrSchmeIdNode'].append(PmtInf_nodes['Nm_CdtrSchmeId_Node'])
        PmtInf_nodes['OthrNode'].append(PmtInf_nodes['Id_Othr_Node'])
        PmtInf_nodes['SchmeNmNode'].append(PmtInf_nodes['PrtryNode'])
        PmtInf_nodes['OthrNode'].append(PmtInf_nodes['SchmeNmNode'])
        PmtInf_nodes['PrvtIdNode'].append(PmtInf_nodes['OthrNode'])
        PmtInf_nodes['Id_CdtrSchmeId_Node'].append(PmtInf_nodes['PrvtIdNode'])
        PmtInf_nodes['CdtrSchmeIdNode'].append(
            PmtInf_nodes['Id_CdtrSchmeId_Node'])
        PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrSchmeIdNode'])

        TX_nodes['PmtIdNode'].append(TX_nodes['EndToEndIdNode'])
        TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['PmtIdNode'])
        TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['InstdAmtNode'])

        TX_nodes['MndtRltdInfNode'].append(TX_nodes['MndtIdNode'])
        TX_nodes['MndtRltdInfNode'].append(TX_nodes['DtOfSgntrNode'])
        TX_nodes['DrctDbtTxNode'].append(TX_nodes['MndtRltdInfNode'])
        TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DrctDbtTxNode'])

        if 'BIC_DbtrAgt_Node' in TX_nodes and TX_nodes['BIC_DbtrAgt_Node'].text is not None:
            TX_nodes['FinInstnId_DbtrAgt_Node'].append(
                TX_nodes['BIC_DbtrAgt_Node'])
        TX_nodes['DbtrAgtNode'].append(TX_nodes['FinInstnId_DbtrAgt_Node'])
        TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrAgtNode'])

        TX_nodes['DbtrNode'].append(TX_nodes['Nm_Dbtr_Node'])
        TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrNode'])

        TX_nodes['Id_DbtrAcct_Node'].append(TX_nodes['IBAN_DbtrAcct_Node'])
        TX_nodes['DbtrAcctNode'].append(TX_nodes['Id_DbtrAcct_Node'])
        TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrAcctNode'])

        TX_nodes['RmtInfNode'].append(TX_nodes['UstrdNode'])
        TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['RmtInfNode'])
        PmtInf_nodes['PmtInfNode'].append(TX_nodes['DrctDbtTxInfNode'])
        CstmrDrctDbtInitn_node = self._xml.find('CstmrDrctDbtInitn')
        CstmrDrctDbtInitn_node.append(PmtInf_nodes['PmtInfNode'])
1348439
def build(self):
        ''''''
        # right now we do not worry about status of nodes
        # connecting the output to the input of other nodes
        #
        # NOTE: This is implemented in the least efficient way just for
        # testing. It has to be re-implemented.
        #
        # refer to http://stackoverflow.com/questions/33494376/networkx-add-edges-to-graph-from-node-attributes
        #
        # several cases triggers dependency.
        if 'DAG' in env.config['SOS_DEBUG'] or 'ALL' in env.config['SOS_DEBUG']:
            env.log_to_file('DAG', 'build DAG')
        for wf in range(self._forward_workflow_id + 1):
            indexed = [x for x in self.nodes() if x._wf_index == wf]
            indexed.sort(key=lambda x: x._node_index)

            for idx, node in enumerate(indexed):
                # 1. if a node changes context (using option alias), all later steps
                # has to rely on it.
                if node._context['__changed_vars__']:
                    for later_node in indexed[idx + 1:]:
                        if node._context['__changed_vars__'] & (
                                later_node._context['__signature_vars__']
                                | later_node._context['__environ_vars__']):
                            self.add_edge(node, later_node)

                # 2. if the input of a step is undetermined, it has to be executed
                # after all its previous steps.
                if not node._input_targets.valid() and idx > 0:
                    # if there is some input specified, it does not use default
                    # input, so the relationship can be further looked before
                    if node._input_targets.undetermined():
                        # if the input is dynamic, has to rely on previous step...
                        if 'dynamic' in node._context['__environ_vars__']:
                            self.add_edge(indexed[idx - 1], node)
                        else:
                            # otherwise let us look back.
                            for prev_node in indexed[idx - 1::-1]:
                                if node._context[
                                        '__environ_vars__'] & prev_node._context[
                                            '__changed_vars__']:
                                    self.add_edge(prev_node, node)
                    else:
                        self.add_edge(indexed[idx - 1], node)
        #
        # 3. if the input of a step depends on the output of another step
        for target, in_node in self._all_depends_files.items():
            if target not in self._all_output_files:
                continue
            # it is possible that multiple nodes satisfy the same target
            out_node = self._all_output_files[target]
            for i in in_node:
                for j in out_node:
                    if j != i:
                        self.add_edge(j, i)
        self.mark_dirty()
574248
def create_bare(self):
        
        self.instances = []
        for ip in self.settings['NODES']:
            new_instance = Instance.new(settings=self.settings, cluster=self)
            new_instance.ip = ip
            self.instances.append(new_instance)
411
def _createunbound(kls, **info):
    """"""
    
    if issubclass(kls, Bitfield):
        nodetype = UnboundBitfieldNode
    elif hasattr(kls, '_fields_'):
        nodetype = UnboundStructureNode
    elif issubclass(kls, ctypes.Array):
        nodetype = UnboundArrayNode
    else:
        nodetype = UnboundSimpleNode        
    return nodetype(type=kls, **info)