No percolator XML for protein tables
776306
def prepare(self):
        """"""
        self.target = self.fn
        self.targetheader = reader.get_tsv_header(self.target)
        self.decoyheader = reader.get_tsv_header(self.decoyfn)
907299
@Override
    public VoltXMLElement voltGetIndexXML(Session session, String tableName,
            Map<String, VoltXMLElement> indexConstraintMapping)
                    throws org.hsqldb_voltpatches.HSQLInterface.HSQLParseException {
        org.hsqldb_voltpatches.VoltXMLElement index = new org.hsqldb_voltpatches.VoltXMLElement("index");

        // Add any expressions to the XML representation of the index,
        // and compute a hash that will help uniquify the generated name,
        // if a name was not provided.
        int exprHash = 0;
        if (exprs != null) {
            org.hsqldb_voltpatches.VoltXMLElement indexedExprs = new org.hsqldb_voltpatches.VoltXMLElement("exprs");
            index.children.add(indexedExprs);
            String hashExprString = new String();
            String sep = "";
            for (org.hsqldb_voltpatches.Expression expression : exprs) {
                org.hsqldb_voltpatches.VoltXMLElement xml = expression.voltGetExpressionXML(session, (Table) table);
                indexedExprs.children.add(xml);
                hashExprString += sep + expression.getSQL();
                sep = ",";
            }

            byte[] bytes = hashExprString.getBytes();
            for (int ii = 0; ii < bytes.length; ii++) {
                exprHash = 31 * exprHash + bytes[ii];
            }
        }

        String hsqlIndexName = getName().name;
        String voltdbIndexName = null;
        boolean isHashIndex = false;

        if (indexConstraintMapping.containsKey(hsqlIndexName)) {
            // This is an index backing a constraint.
            VoltXMLElement constraintXml = indexConstraintMapping.get(hsqlIndexName);
            indexConstraintMapping.remove(hsqlIndexName);

            boolean isAutoName = constraintXml.attributes.get("nameisauto").equals("true");

            // This is either a [ASSUME]UNIQUE constraint or a PK.
            String constraintType = constraintXml.attributes.get("constrainttype");
            String hsqlConstraintName = constraintXml.attributes.get("name");

            if (!isAutoName) {
                isHashIndex = isNameRequestingHashIndex(hsqlConstraintName);
                voltdbIndexName = HSQLInterface.AUTO_GEN_NAMED_CONSTRAINT_IDX + hsqlConstraintName;
            }
            else {
                String prefix = null;
                boolean isPrimaryKey = constraintType.equals("PRIMARY_KEY");
                if (isPrimaryKey) {
                    prefix = HSQLInterface.AUTO_GEN_PRIMARY_KEY_PREFIX;
                }
                else {
                    prefix = HSQLInterface.AUTO_GEN_UNIQUE_IDX_PREFIX;
                }

                String namePart = tableName + "_" + StringUtils.join(getColumnNameList().toArray(), "_");
                if (exprs != null) {
                    namePart += "_" + java.lang.Math.abs(exprHash % 100000);
                }

                voltdbIndexName = prefix + namePart;

                // Also name the constraint here based on our naming scheme.
                String voltdbConstraintName = null;
                if (isPrimaryKey) {
                    voltdbConstraintName = HSQLInterface.AUTO_GEN_CONSTRAINT_PREFIX + "_PK_" + namePart;
                }
                else {
                    voltdbConstraintName = HSQLInterface.AUTO_GEN_CONSTRAINT_PREFIX + "_CT_" + namePart;

                }

                constraintXml.attributes.put("name", voltdbConstraintName);
            }

            // Update the index name in the constraint.
            constraintXml.attributes.put("index", voltdbIndexName);
        }
        else {
            // This is an index created via CREATE INDEX
            isHashIndex = isNameRequestingHashIndex(hsqlIndexName);
            voltdbIndexName = hsqlIndexName;
        }

        index.attributes.put("name", voltdbIndexName);
        index.attributes.put("ishashindex", isHashIndex ? "true" : "false");

        index.attributes.put("assumeunique", isAssumeUnique() ? "true" : "false");
        index.attributes.put("unique", isUnique() ? "true" : "false");
        index.attributes.put("migrating", isMigrating() ? "true" : "false");
        assert ! (isMigrating() && (isUnique() || isAssumeUnique())) :
                "Cannot create a MIGRATING index that is also UNIQUE or ASSUMEUNIQUE";

        Object[] columnList = getColumnNameList().toArray();
        index.attributes.put("columns", StringUtils.join(columnList, ","));

        if (predicate != null) {
            org.hsqldb_voltpatches.VoltXMLElement partialExpr = new org.hsqldb_voltpatches.VoltXMLElement("predicate");
            index.children.add(partialExpr);
            org.hsqldb_voltpatches.VoltXMLElement xml = predicate.voltGetExpressionXML(session, (Table) table);
            partialExpr.children.add(xml);
        }

        return index;
    }
853702
private JXTable getUrlsTable() {
		if (urlsTable == null) {
			// Create the table with a default, empty TableModel and the proper settings
			urlsTable = new ZapTable(EMPTY_URLS_TABLE_MODEL);
			urlsTable.setColumnSelectionAllowed(false);
			urlsTable.setCellSelectionEnabled(false);
			urlsTable.setRowSelectionAllowed(true);
			urlsTable.setAutoCreateRowSorter(true);

			urlsTable.setAutoCreateColumnsFromModel(false);
			urlsTable.getColumnExt(0).setCellRenderer(
					new DefaultTableRenderer(new MappedValue(StringValues.EMPTY, IconValues.NONE), JLabel.CENTER));
			urlsTable.getColumnExt(0).setHighlighters(new ProcessedCellItemIconHighlighter(0));

			urlsTable.getColumnModel().getColumn(0).setMinWidth(80);
			urlsTable.getColumnModel().getColumn(0).setPreferredWidth(90); // processed

			urlsTable.getColumnModel().getColumn(1).setMinWidth(60);
			urlsTable.getColumnModel().getColumn(1).setPreferredWidth(70); // method

			urlsTable.getColumnModel().getColumn(2).setMinWidth(300); // name

			urlsTable.getColumnModel().getColumn(3).setMinWidth(50);
			urlsTable.getColumnModel().getColumn(3).setPreferredWidth(250); // flags

			urlsTable.setName(PANEL_NAME);
			urlsTable.setDoubleBuffered(true);
			urlsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
			urlsTable.setComponentPopupMenu(new JPopupMenu() {

				private static final long serialVersionUID = 6608291059686282641L;

				@Override
				public void show(Component invoker, int x, int y) {
					View.getSingleton().getPopupMenu().show(invoker, x, y);
				}
			});
		}
		return urlsTable;
	}
875231
VoltXMLElement voltGetTableXML(Session session)
            throws org.hsqldb_voltpatches.HSQLInterface.HSQLParseException
    {
        VoltXMLElement table = new VoltXMLElement("table");

        // add table metadata
        String tableName = getName().name;
        table.attributes.put("name", tableName);

        // read all the columns
        VoltXMLElement columns = new VoltXMLElement("columns");
        columns.attributes.put("name", "columns");
        table.children.add(columns);
        int[] columnIndices = getColumnMap();
        for (int i : columnIndices) {
            ColumnSchema column = getColumn(i);
            VoltXMLElement colChild = column.voltGetColumnXML(session);
            colChild.attributes.put("index", Integer.toString(i));
            columns.children.add(colChild);
            assert(colChild != null);
        }

        // read all the constraints
        VoltXMLElement constraints = new VoltXMLElement("constraints");
        constraints.attributes.put("name", "constraints");
        Map<String, VoltXMLElement> indexConstraintMap = new HashMap<>();
        for (Constraint constraint : getConstraints()) {
            VoltXMLElement constraintChild = constraint.voltGetConstraintXML();
            constraints.children.add(constraintChild);
            if (constraintChild.attributes.containsKey("index")) {
                indexConstraintMap.put(constraintChild.attributes.get("index"), constraintChild);
            }
        }

        // read all the indexes
        VoltXMLElement indexes = new VoltXMLElement("indexes");
        indexes.attributes.put("name", "indexes");
        for (Index index : indexList) {
            VoltXMLElement indexChild = index.voltGetIndexXML(session, tableName, indexConstraintMap);
            indexes.children.add(indexChild);
            assert(indexChild != null);
        }

        // Indexes must come before constraints when converting to the catalog.
        table.children.add(indexes);
        table.children.add(constraints);

        if (timeToLive != null) {
            VoltXMLElement ttl = new VoltXMLElement(TimeToLiveVoltDB.TTL_NAME);
            ttl.attributes.put("name", TimeToLiveVoltDB.TTL_NAME);
            ttl.attributes.put("value", Integer.toString(timeToLive.ttlValue));
            ttl.attributes.put("unit",  timeToLive.ttlUnit);
            ttl.attributes.put("column", timeToLive.ttlColumn.getNameString());
            ttl.attributes.put("maxFrequency", Integer.toString(timeToLive.maxFrequency));
            ttl.attributes.put("batchSize", Integer.toString(timeToLive.batchSize));
            ttl.attributes.put("migrationTarget", timeToLive.migrationTarget);
            table.children.add(ttl);
        }
        assert(indexConstraintMap.isEmpty());

        return table;
    }
905743
@Override
    public BeansXml getBeansXml() {
        if (this.beansXml == null) {
            Resource beansXmlResource = archive.getBeansXml();
            if (beansXmlResource != null) {
                URL beansXmlUrl = beansXmlResource.getURL();
                Bootstrap bootstrap = getCDIDeployment().getBootstrap();
                final ClassLoader origTCCL = getContextClassLoader();
                try {
                    // Must use this class's loader as the context classloader to ensure
                    // that we load Liberty's XML parser rather than any parser defined
                    // in the application.
                    setContextClassLoader(BeanDeploymentArchiveImpl.class.getClassLoader());
                    beansXml = bootstrap.parse(beansXmlUrl);
                } finally {
                    setContextClassLoader(origTCCL);
                }
            }
        }
        return this.beansXml;
    }
75025
@Override
    protected AstNode parseAlterTableStatement( DdlTokenStream tokens,
                                                AstNode parentNode ) throws ParsingException {
        assert tokens != null;
        assert parentNode != null;

        markStartOfStatement(tokens);

        // ALTER TABLE table-Name
        // {
        // ADD COLUMN column-definition |
        // ADD CONSTRAINT clause |
        // DROP [ COLUMN ] column-name [ CASCADE | RESTRICT ] |
        // DROP { PRIMARY KEY | FOREIGN KEY constraint-name | UNIQUE constraint-name | CHECK constraint-name | CONSTRAINT
        // constraint-name } |
        // ALTER [ COLUMN ] column-alteration |
        // LOCKSIZE { ROW | TABLE }
        // }

        tokens.consume(ALTER, TABLE); // consumes 'ALTER TABLE'
        String tableName = parseName(tokens);

        AstNode alterTableNode = nodeFactory().node(tableName, parentNode, TYPE_ALTER_TABLE_STATEMENT);

        // System.out.println("  >> PARSIN ALTER STATEMENT >>  TABLE Name = " + tableName);

        if (tokens.canConsume("ADD")) {
            if (isTableConstraint(tokens)) {
                parseTableConstraint(tokens, alterTableNode, true);
            } else {
                // This segment can also be enclosed in "()" brackets to handle multiple ColumnDefinition ADDs
                if (tokens.matches(L_PAREN)) {
                    parseColumns(tokens, alterTableNode, true);
                } else {
                    parseSingleTerminatedColumnDefinition(tokens, alterTableNode, true);
                }
            }

        } else if (tokens.canConsume("DROP")) {
            // DROP { PRIMARY KEY | FOREIGN KEY constraint-name | UNIQUE constraint-name | CHECK constraint-name | CONSTRAINT
            // constraint-name }
            if (tokens.canConsume("PRIMARY", "KEY")) {
                String name = parseName(tokens); // constraint name
                nodeFactory().node(name, alterTableNode, TYPE_DROP_TABLE_CONSTRAINT_DEFINITION);
            } else if (tokens.canConsume("FOREIGN", "KEY")) {
                String name = parseName(tokens); // constraint name
                nodeFactory().node(name, alterTableNode, TYPE_DROP_TABLE_CONSTRAINT_DEFINITION);
            } else if (tokens.canConsume("UNIQUE")) {
                String name = parseName(tokens); // constraint name
                nodeFactory().node(name, alterTableNode, TYPE_DROP_TABLE_CONSTRAINT_DEFINITION);
            } else if (tokens.canConsume("CHECK")) {
                String name = parseName(tokens); // constraint name
                nodeFactory().node(name, alterTableNode, TYPE_DROP_TABLE_CONSTRAINT_DEFINITION);
            } else if (tokens.canConsume("CONSTRAINT")) {
                String name = parseName(tokens); // constraint name
                nodeFactory().node(name, alterTableNode, TYPE_DROP_TABLE_CONSTRAINT_DEFINITION);
            } else {
                // DROP [ COLUMN ] column-name [ CASCADE | RESTRICT ]
                tokens.canConsume("COLUMN"); // "COLUMN" is optional

                String columnName = parseName(tokens);

                AstNode columnNode = nodeFactory().node(columnName, alterTableNode, TYPE_DROP_COLUMN_DEFINITION);

                if (tokens.canConsume(DropBehavior.CASCADE)) {
                    columnNode.setProperty(StandardDdlLexicon.DROP_BEHAVIOR, DropBehavior.CASCADE);
                } else if (tokens.canConsume(DropBehavior.RESTRICT)) {
                    columnNode.setProperty(StandardDdlLexicon.DROP_BEHAVIOR, DropBehavior.RESTRICT);
                }
            }
        } else if (tokens.canConsume("ALTER")) {
            // column-alteration
            //
            // ALTER [ COLUMN ] column-Name SET DATA TYPE VARCHAR(integer) |
            // ALTER [ COLUMN ] column-Name SET DATA TYPE VARCHAR FOR BIT DATA(integer) |
            // ALTER [ COLUMN ] column-name SET INCREMENT BY integer-constant |
            // ALTER [ COLUMN ] column-name RESTART WITH integer-constant |
            // ALTER [ COLUMN ] column-name [ NOT ] NULL |
            // ALTER [ COLUMN ] column-name [ WITH | SET ] DEFAULT default-value |
            // ALTER [ COLUMN ] column-name DROP DEFAULT

            tokens.canConsume("COLUMN");
            String alterColumnName = parseName(tokens);

            AstNode columnNode = nodeFactory().node(alterColumnName, alterTableNode, TYPE_ALTER_COLUMN_DEFINITION);

            if (tokens.matches("DEFAULT")) {
                parseDefaultClause(tokens, columnNode);
            } else if (tokens.canConsume("SET")) {
                if (tokens.canConsume("DATA", "TYPE")) {
                    DataType datatype = getDatatypeParser().parse(tokens);

                    columnNode.setProperty(StandardDdlLexicon.DATATYPE_NAME, datatype.getName());
                    if (datatype.getLength() >= 0) {
                        columnNode.setProperty(StandardDdlLexicon.DATATYPE_LENGTH, datatype.getLength());
                    }
                    if (datatype.getPrecision() >= 0) {
                        columnNode.setProperty(StandardDdlLexicon.DATATYPE_PRECISION, datatype.getPrecision());
                    }
                    if (datatype.getScale() >= 0) {
                        columnNode.setProperty(StandardDdlLexicon.DATATYPE_SCALE, datatype.getScale());
                    }

                } else if (tokens.canConsume("INCREMENT")) {
                    tokens.consume("BY", TokenStream.ANY_VALUE);
                }
                if (tokens.matches("DEFAULT")) {
                    parseDefaultClause(tokens, columnNode);
                }
            } else if (tokens.canConsume("WITH")) {
                parseDefaultClause(tokens, columnNode);
            } else {
                tokens.canConsume("RESTART", "WITH", TokenStream.ANY_VALUE);
                tokens.canConsume("DROP", "DEFAULT");

                if (tokens.canConsume("NOT", "NULL")) {
                    columnNode.setProperty(StandardDdlLexicon.NULLABLE, "NOT NULL");
                } else if (tokens.canConsume("NULL")) {
                    columnNode.setProperty(StandardDdlLexicon.NULLABLE, "NULL");
                }
            }

        } else if (tokens.canConsume("LOCKSIZE")) {
            tokens.canConsume("ROWS");
            tokens.canConsume("TABLE");
        }

        markEndOfStatement(tokens, alterTableNode);

        return alterTableNode;
    }
1057932
def print_table(seqs, id2name, name):
    
    itable = open('%s.itable' % (name.rsplit('.', 1)[0]), 'w')
    print('\t'.join(['#sequence', 'gene', 'model', 'insertion', 'gene position', 'model position', 'length', 'orf?', 'intron?', 'orf?intron?', 'insertion', 'orf', 'intron']), file=itable)
    for seq, info in list(seqs.items()):
        gene, model, insertions = info
        name = id2name[seq]
        for i, ins in enumerate(insertions, 1):
            gene_pos, model_pos, length, iseq, \
                    orfs, introns, orfs_b, introns_b, orf_annotations = ins
            # append annotation to orf header
            for orf in orfs:
                parts = orf[0].split()
                annotation = orf_annotations[parts[0].split('>')[1]]
                orf[0] = '%s %s %s' % (parts[0], annotation, ' '.join(parts[1:]))
            # get orf position
            gene_pos = '-'.join([str(j) for j in gene_pos])
            # check if orf, intron is present
            if orfs_b is True or introns_b is True:
                orfs_introns_b = True
            else:
                orfs_introns_b = False
            out = [name, gene, model, i, gene_pos, model_pos, length, orfs_b, introns_b, orfs_introns_b]
            out.append('|'.join(iseq))
            out.append('|'.join(['|'.join(orf) for orf in orfs]))
            out.append('|'.join(['|'.join(intron) for intron in introns]))
            print('\t'.join([str(i) for i in out]), file=itable)
    itable.close()
1163078
protected static CannotParseException missingXmlElements(ICalDataType... dataTypes) {
		String[] elements = new String[dataTypes.length];
		for (int i = 0; i < dataTypes.length; i++) {
			ICalDataType dataType = dataTypes[i];
			elements[i] = (dataType == null) ? "unknown" : dataType.getName().toLowerCase();
		}
		return missingXmlElements(elements);
	}
1183604
def to_segment_xml(self, override_file_if_exists=False):
        
        # create XML doc and add process table
        outdoc = ligolw.Document()
        outdoc.appendChild(ligolw.LIGO_LW())
        process = ligolw_process.register_to_xmldoc(outdoc, sys.argv[0], {})

        for key, seglist in self.segment_dict.items():
            ifo, name = self.parse_segdict_key(key)
            # Ensure we have LIGOTimeGPS
            fsegs = [(lal.LIGOTimeGPS(seg[0]),
                      lal.LIGOTimeGPS(seg[1])) for seg in seglist]

            if self.seg_summ_dict is None:
                vsegs = [(lal.LIGOTimeGPS(seg[0]),
                          lal.LIGOTimeGPS(seg[1])) \
                         for seg in self.valid_segments]
            else:
                vsegs = [(lal.LIGOTimeGPS(seg[0]),
                          lal.LIGOTimeGPS(seg[1])) \
                         for seg in self.seg_summ_dict[key]]

            # Add using glue library to set all segment tables
            with ligolw_segments.LigolwSegments(outdoc, process) as x:
                x.add(ligolw_segments.LigolwSegmentList(active=fsegs,
                                    instruments=set([ifo]), name=name,
                                    version=1, valid=vsegs))

        # write file
        url = urlparse.urljoin('file:', urllib.pathname2url(self.storage_path))
        if not override_file_if_exists or not self.has_pfn(url, site='local'):
            self.PFN(url, site='local')
        ligolw_utils.write_filename(outdoc, self.storage_path)
1006720
def calculate_residue_counts_perstrain(protein_pickle_path, outdir, pdbflex_keys_file, wt_pid_cutoff=None, force_rerun=False):
    """"""
    from collections import defaultdict
    from ssbio.protein.sequence.seqprop import SeqProp
    from ssbio.protein.sequence.properties.residues import _aa_property_dict_one
    log = logging.getLogger(__name__)

    protein_id = op.splitext(op.basename(protein_pickle_path))[0].split('_')[0]

    protein_df_outfile = op.join(outdir, '{}_protein_strain_properties.fthr'.format(protein_id))

    if ssbio.utils.force_rerun(flag=force_rerun, outfile=protein_df_outfile):

        protein = ssbio.io.load_pickle(protein_pickle_path)

        # First calculate disorder cuz i forgot to
        protein.get_all_disorder_predictions(representative_only=True)

        # Then get all subsequences
        all_protein_subseqs = protein.get_all_subsequences(pdbflex_keys_file=pdbflex_keys_file)
        if not all_protein_subseqs:
            log.error('{}: cannot run subsequence calculator'.format(protein.id))
            return

        # Each strain gets a dictionary
        strain_to_infodict = defaultdict(dict)

        for seqprop_to_analyze in protein.sequences:
            if seqprop_to_analyze.id == protein.representative_sequence.id:
                strain_id = 'K12'
            elif type(seqprop_to_analyze) == SeqProp and seqprop_to_analyze.id != protein.id:  # This is to filter out other KEGGProps or UniProtProps
                strain_id = seqprop_to_analyze.id.split('_', 1)[1]  # This split should work for all strains
            else:
                continue

            ## Additional filtering for genes marked as orthologous but actually have large deletions or something
            ## TODO: experiment with other cutoffs?
            if wt_pid_cutoff:
                aln = protein.sequence_alignments.get_by_id('{0}_{0}_{1}'.format(protein.id, seqprop_to_analyze.id))
                if aln.annotations['percent_identity'] < wt_pid_cutoff:
                    continue

            ###### Calculate "all" properties ######
            seqprop_to_analyze.get_biopython_pepstats()

            # [ALL] aa_count
            if 'amino_acids_percent-biop' not in seqprop_to_analyze.annotations:  # May not run if weird amino acids in the sequence
                log.warning('Protein {}, sequence {}: skipping, unable to run Biopython ProteinAnalysis'.format(protein.id,
                                                                                                            seqprop_to_analyze.id))
                continue
            strain_to_infodict[strain_id].update({'aa_count_{}'.format(k): v for k, v in seqprop_to_analyze.annotations['amino_acids_content-biop'].items()})

            # [ALL] aa_count_total
            strain_to_infodict[strain_id]['aa_count_total'] = seqprop_to_analyze.seq_len

            ###### Calculate subsequence properties ######
            for prop, propdict in all_protein_subseqs.items():
                strain_to_infodict[strain_id].update(protein.get_subseq_props(property_dict=propdict, property_name=prop,
                                                                              seqprop=seqprop_to_analyze))

        protein_df = pd.DataFrame(strain_to_infodict)
        protein_df.reset_index().to_feather(protein_df_outfile)

    return protein_pickle_path, protein_df_outfile
73938
def build_proteintable(pqdb, headerfields, mergecutoff, isobaric=False,
                       precursor=False, probability=False, fdr=False,
                       pep=False, genecentric=False):
    """"""
    pdmap = create_featuredata_map(pqdb, genecentric=genecentric,
                                   psm_fill_fun=pinfo.add_psms_to_proteindata,
                                   pgene_fill_fun=pinfo.add_protgene_to_protdata,
                                   count_fun=pinfo.count_peps_psms,
                                   get_uniques=True)
    empty_return = lambda x, y, z: {}
    iso_fun = {True: get_isobaric_quant, False: empty_return}[isobaric]
    ms1_fun = {True: get_precursor_quant, False: empty_return}[precursor]
    prob_fun = {True: get_prot_probability,
                False: empty_return}[probability]
    fdr_fun = {True: get_prot_fdr,
               False: empty_return}[fdr]
    pep_fun = {True: get_prot_pep,
               False: empty_return}[pep]
    pdata_fun = {True: get_protein_data_genecentric,
                 False: get_protein_data}[genecentric is not False]
    protein_sql, sqlfieldmap = pqdb.prepare_mergetable_sql(precursor, isobaric,
                                                           probability, fdr,
                                                           pep)
    accession_field = prottabledata.ACCESSIONS[genecentric]
    proteins = pqdb.get_merged_features(protein_sql)
    protein = next(proteins)
    outprotein = {accession_field: protein[sqlfieldmap['p_acc']]}
    check_prot = {k: v for k, v in outprotein.items()}
    if not mergecutoff or protein_pool_fdr_cutoff(protein, sqlfieldmap,
                                                  mergecutoff):
        fill_mergefeature(outprotein, iso_fun, ms1_fun, prob_fun, fdr_fun,
                          pep_fun, pdata_fun, protein, sqlfieldmap,
                          headerfields, pdmap, accession_field)
    for protein in proteins:
        if mergecutoff and not protein_pool_fdr_cutoff(protein, sqlfieldmap,
                                                       mergecutoff):
            continue
        p_acc = protein[sqlfieldmap['p_acc']]
        if p_acc != outprotein[accession_field]:
            # check if protein has been filled, otherwise do not output
            # sometimes proteins have NA in all fields
            if outprotein != check_prot:
                yield outprotein
            outprotein = {accession_field: p_acc}
            check_prot = {k: v for k, v in outprotein.items()}
        fill_mergefeature(outprotein, iso_fun, ms1_fun, prob_fun, fdr_fun,
                          pep_fun, pdata_fun, protein, sqlfieldmap,
                          headerfields, pdmap, accession_field)
    if outprotein != check_prot:
        yield outprotein
630972
def add_protein_data(proteins, pgdb, headerfields, genecentric=False,
                     pool_to_output=False):
    """"""
    proteindata = create_featuredata_map(pgdb, genecentric=genecentric,
                                         psm_fill_fun=add_psms_to_proteindata,
                                         pgene_fill_fun=add_protgene_to_protdata,
                                         count_fun=count_peps_psms,
                                         pool_to_output=pool_to_output,
                                         get_uniques=True)
    dataget_fun = {True: get_protein_data_genecentric,
                   False: get_protein_data_pgrouped}[genecentric is not False]
    firstfield = prottabledata.ACCESSIONS[genecentric]
    for protein in proteins:
        outprotein = {k: v for k, v in protein.items()}
        outprotein[firstfield] = outprotein.pop(prottabledata.HEADER_PROTEIN)
        protein_acc = protein[prottabledata.HEADER_PROTEIN]
        outprotein.update(dataget_fun(proteindata, protein_acc, headerfields))
        outprotein = {k: str(v) for k, v in outprotein.items()}
        yield outprotein
920982
def retrieve(pdb_id, cache_dir = None, acceptable_sequence_percentage_match = 70.0, require_uniprot_residue_mapping = True, bio_cache = None):
        '''
        '''

        pdb_contents = None
        xml_contents = None
        pdb_id = pdb_id.upper()

        l_pdb_id = pdb_id.lower()

        if len(pdb_id) != 4 or not pdb_id.isalnum():
            raise Exception("Bad PDB identifier '%s'." % pdb_id)

        if bio_cache:
            pdb_contents = bio_cache.get_pdb_contents(pdb_id)
            xml_contents = bio_cache.get_sifts_xml_contents(pdb_id)

        if cache_dir:
            if not pdb_contents:
                # Check to see whether we have a cached copy of the PDB file
                filename = os.path.join(cache_dir, "%s.pdb" % pdb_id)
                if os.path.exists(filename):
                    pdb_contents = read_file(filename)

            if not xml_contents:
                # Check to see whether we have a cached copy of the XML file
                filename = os.path.join(cache_dir, "%s.sifts.xml.gz" % l_pdb_id)
                if os.path.exists(filename):
                    xml_contents = read_file(filename)

        # Get any missing files from the RCSB and create cached copies if appropriate
        if not pdb_contents:
            pdb_contents = rcsb.retrieve_pdb(pdb_id)
            if cache_dir:
                write_file(os.path.join(cache_dir, "%s.pdb" % pdb_id), pdb_contents)

        if not xml_contents:
            try:
                xml_contents = retrieve_xml(pdb_id, silent = False)
                if cache_dir:
                    write_file(os.path.join(cache_dir, "%s.sifts.xml.gz" % l_pdb_id), xml_contents)
            except FTPException550:
                raise MissingSIFTSRecord('The file "%s.sifts.xml.gz" could not be found on the EBI FTP server.' % l_pdb_id)

        xml_contents = xml_contents

        # Return the object
        handler = SIFTS(xml_contents, pdb_contents, acceptable_sequence_percentage_match = acceptable_sequence_percentage_match, cache_dir = cache_dir, require_uniprot_residue_mapping = require_uniprot_residue_mapping, bio_cache = bio_cache, pdb_id = pdb_id)
        xml.sax.parseString(xml_contents, handler)
        return handler
888247
def _parseMzml(self):
        
        #TODO: this is already pretty nested, reduce that eg by using a function
        #   processRunNode
        for event, element, elementTag in self:
            if elementTag == 'mzML':
                metadataNode = ETREE.Element(self.elementTag,
                                             self.element.attrib
                                             )
                _, _, targetTag = next(self)
                break

        while targetTag != 'mzML':
            if targetTag == 'run':
                runNode = ETREE.Element('run', self.element.attrib)
                next(self)
                while self.event != 'end' or self.elementTag != 'run':
                    if self.elementTag == 'spectrumList':
                        #Add spectrumListNode
                        specListAttrib = {'defaultDataProcessingRef':
                                          self.element.attrib['defaultDataProcessingRef']
                                          }
                        specListNode = ETREE.Element('spectrumList', specListAttrib)
                        runNode.append(specListNode)
                        #Parse and yield spectrum xml elements
                        while self.event != 'end' or self.elementTag != 'spectrumList':
                            if self.event == 'end' and self.elementTag == 'spectrum':
                                yield self.element
                                clearParsedElements(self.element)
                            next(self)
                    elif self.elementTag == 'chromatogramList':
                        #Add chromatogramListNode
                        chromListAttrib = {'defaultDataProcessingRef':
                                           self.element.attrib['defaultDataProcessingRef']
                                           }
                        chromListNode = ETREE.Element('chromatogramList',
                                                      chromListAttrib
                                                      )
                        runNode.append(chromListNode)
                        #Parse and store chromatogram xml elements
                        while self.event != 'end' or self.elementTag != 'chromatogramList':
                            if self.event == 'end' and self.elementTag == 'chromatogram':
                                self.chromatogramList.append(self.element)
                                #Alternatively also the chromatogram xml
                                #elements could be yielded:
                                #   yield self.element
                                #   clearParsedElements(self.element)
                            next(self)
                    else:
                        runNode.append(self.element)
                    next(self)
                metadataNode.append(runNode)
                break
            else:
                while self.event != 'end' or self.elementTag != targetTag:
                    next(self)
                metadataNode.append(self.element)
            _, _, targetTag = next(self)
        recClearTag(metadataNode)
        recRemoveTreeFormating(metadataNode)
        self.metadataNode = recCopyElement(metadataNode)
        self.openfile.close()
71581
def get_synset_xml(self,syn_id):
        

        http, resp, content = self.connect()

        params   = ""
        fragment = ""

        path = "cdb_syn"
        if self.debug:
            printf( "cornettodb/views/query_remote_syn_id: db_opt: %s" % path )

        # output_opt: plain, html, xml
        # 'xml' is actually xhtml (with markup), but it is not valid xml!
        # 'plain' is actually valid xml (without markup)
        output_opt = "plain"
        if self.debug:
            printf( "cornettodb/views/query_remote_syn_id: output_opt: %s" % output_opt )

        action = "runQuery"
        if self.debug:
            printf( "cornettodb/views/query_remote_syn_id: action: %s" % action )
            printf( "cornettodb/views/query_remote_syn_id: query: %s" % syn_id )

        qdict = {}
        qdict[ "action" ]  = action
        qdict[ "query" ]   = syn_id
        qdict[ "outtype" ] = output_opt

        query = urllib.urlencode( qdict )

        db_url_tuple = ( self.scheme, self.host + ':' + str(self.port), path, params, query, fragment )
        db_url = urlparse.urlunparse( db_url_tuple )
        if self.debug:
            printf( "db_url: %s" % db_url )

        resp, content = http.request( db_url, "GET" )
        if self.debug:
            printf( "resp:\n%s" % resp )
        #    printf( "content:\n%s" % content )
        #    printf( "content is of type: %s" % type( content ) )        #<type 'str'>

        xml_data = eval( content )
        return etree.fromstring( xml_data )
1055643
@Override
    public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
        StringBuilder buf = new StringBuilder();

        buf.append('<').append(getElementName()).append(" xmlns=\"");
        buf.append(getNamespace()).append("\" ");

        synchronized (candidates) {
            if (getCandidatesCount() > 0) {
                buf.append('>');
                Iterator<JingleTransportCandidate> iter = getCandidates();

                while (iter.hasNext()) {
                    JingleTransportCandidate candidate = iter.next();
                    buf.append(candidate.toXML());
                }
                buf.append("</").append(getElementName()).append('>');
            } else {
                buf.append("/>");
            }
        }

        return buf.toString();
    }
486951
def ensembl_to_kegg(organism,kegg_db):
    
    print("KEGG API: http://rest.genome.jp/link/"+kegg_db+"/"+organism)
    sys.stdout.flush()
    kegg_ens=urlopen("http://rest.genome.jp/link/"+kegg_db+"/"+organism).read()
    kegg_ens=kegg_ens.split("\n")
    final=[]
    for i in kegg_ens:
        final.append(i.split("\t"))
    df=pd.DataFrame(final[0:len(final)-1])[[0,1]]
    ens_id=pd.DataFrame(df[1].str.split(":").tolist())[1]
    df=pd.concat([df,ens_id],axis=1)
    df.columns=['KEGGid','ensDB','ENSid']
    df=df[['KEGGid','ENSid']]
    return df