scripts/export/genomes/fetch_gen_metadata.py
def extract_uniprot_genome_metadata(upid):
    """
    Parses a proteome's xml file from Uniprot and converts it to a json
    like object which is returned

    upid: A valid Uniprot Proteome identifier

    returns: A dictionary
    """

    proteome_dict = {}

    # namespace prefix # or register a namespace in the ET
    prefix = "{http://uniprot.org/uniprot}%s"

    response = requests.get(gc.PROTEOME_XML_URL % upid)

    # check if we got an OK http reponse
    if response.status_code == httplib.OK:
        prot_tree_root = ET.fromstring(response.content)

        proteome = prot_tree_root.find(prefix % "proteome")

        upid = proteome.find(prefix % "upid")
        proteome_dict["upid"] = upid.text
        proteome_dict["ncbi_id"] = int(proteome.find(prefix % "taxonomy").text)
        proteome_dict["description"] = ""
        proteome_dict["scientific_name"] = proteome.find(prefix % "name").text

        # initialization to the default values
        is_reference = proteome.find(prefix % "is_reference_proteome").text
        proteome_dict["is_reference"] = 1

        if is_reference == "false":
            proteome_dict["is_reference"] = 0
        else:
            proteome_dict["is_reference"] = 1

        # initialization to the default values
        is_representative = is_reference = proteome.find(prefix % "is_representative_proteome").text
        proteome_dict["is_representative"] = 0

        if is_representative == "false":
            proteome_dict["is_representative"] = 0
        else:
            proteome_dict["is_representative"] = 1

        # get sequence accessions
        acc_dict = {}
        other_accs = []
        accession_nodes = proteome.findall(prefix % "component")

        for node in accession_nodes:
            if node.get("name").find("WGS") != -1:
                # look for all WGS accessions
                gen_acc_nodes = node.findall(prefix % "genome_accession")

                # single WGS accession
                if len(gen_acc_nodes) == 1:
                    acc_dict["WGS"] = node.find(prefix % "genome_accession").text
                else:
                    for gen_acc_node in gen_acc_nodes:
                        other_accs.append(gen_acc_node.text)

            elif node.get("name").find("Chloroplast") != -1:
                acc_dict["Chloroplast"] = node.find(prefix % "genome_accession").text

            elif node.get("name").find("Mitochondrion") != -1:
                acc_dict["Mitochondrion"] = node.find(prefix % "genome_accession").text

            elif node.get("name").find("Genome") != -1:
                description =node.find(prefix % "description").text
                proteome_dict["description"] = description

            else:

                other_acc = node.find(prefix % "genome_accession")
                if other_acc is not None:
                    other_accs.append(node.find(prefix % "genome_accession").text)

        if len(other_accs) > 0:
            acc_dict["other"] = other_accs

        proteome_dict["accessions"] = acc_dict

    return proteome_dict

    Parses a proteome's xml file from Uniprot and converts it to a json
    like object which is returned

    upid: A valid Uniprot Proteome identifier

    returns: A dictionary
    
Parses a proteome's xml file from Uniprot and converts it to a json
like object which is returned

A valid Uniprot Proteome identifier

A dictionary
Parses a proteome ' s xml file from Uniprot and converts it to a json like object which is returned A valid Uniprot Proteome identifier A dictionary
def extract_uniprot_genome_metadata(upid):
    proteome_dict = {}
    prefix = "{http://uniprot.org/uniprot}%s"
    response = requests.get(gc.PROTEOME_XML_URL % upid)
    if response.status_code == httplib.OK:
        prot_tree_root = ET.fromstring(response.content)
        proteome = prot_tree_root.find(prefix % "proteome")
        upid = proteome.find(prefix % "upid")
        proteome_dict["upid"] = upid.text
        proteome_dict["ncbi_id"] = int(proteome.find(prefix % "taxonomy").text)
        proteome_dict["description"] = ""
        proteome_dict["scientific_name"] = proteome.find(prefix % "name").text
        is_reference = proteome.find(prefix % "is_reference_proteome").text
        proteome_dict["is_reference"] = 1
        if is_reference == "false":
            proteome_dict["is_reference"] = 0
        else:
            proteome_dict["is_reference"] = 1
        is_representative = is_reference = proteome.find(prefix % "is_representative_proteome").text
        proteome_dict["is_representative"] = 0
        if is_representative == "false":
            proteome_dict["is_representative"] = 0
        else:
            proteome_dict["is_representative"] = 1
        acc_dict = {}
        other_accs = []
        accession_nodes = proteome.findall(prefix % "component")
        for node in accession_nodes:
            if node.get("name").find("WGS") != -1:
                gen_acc_nodes = node.findall(prefix % "genome_accession")
                if len(gen_acc_nodes) == 1:
                    acc_dict["WGS"] = node.find(prefix % "genome_accession").text
                else:
                    for gen_acc_node in gen_acc_nodes:
                        other_accs.append(gen_acc_node.text)
            elif node.get("name").find("Chloroplast") != -1:
                acc_dict["Chloroplast"] = node.find(prefix % "genome_accession").text
            elif node.get("name").find("Mitochondrion") != -1:
                acc_dict["Mitochondrion"] = node.find(prefix % "genome_accession").text
            elif node.get("name").find("Genome") != -1:
                description =node.find(prefix % "description").text
                proteome_dict["description"] = description
            else:
                other_acc = node.find(prefix % "genome_accession")
                if other_acc is not None:
                    other_accs.append(node.find(prefix % "genome_accession").text)
        if len(other_accs) > 0:
            acc_dict["other"] = other_accs
        proteome_dict["accessions"] = acc_dict
    return proteome_dict
def extract_uniprot_genome_metadata ( upid ) : proteome_dict = { } prefix = "{http://uniprot.org/uniprot}%s" response = requests . get ( gc . PROTEOME_XML_URL % upid ) if response . status_code == httplib . OK : prot_tree_root = ET . fromstring ( response . content ) proteome = prot_tree_root . find ( prefix % "proteome" ) upid = proteome . find ( prefix % "upid" ) proteome_dict [ "upid" ] = upid . text proteome_dict [ "ncbi_id" ] = int ( proteome . find ( prefix % "taxonomy" ) . text ) proteome_dict [ "description" ] = "" proteome_dict [ "scientific_name" ] = proteome . find ( prefix % "name" ) . text is_reference = proteome . find ( prefix % "is_reference_proteome" ) . text proteome_dict [ "is_reference" ] = 1 if is_reference == "false" : proteome_dict [ "is_reference" ] = 0 else : proteome_dict [ "is_reference" ] = 1 is_representative = is_reference = proteome . find ( prefix % "is_representative_proteome" ) . text proteome_dict [ "is_representative" ] = 0 if is_representative == "false" : proteome_dict [ "is_representative" ] = 0 else : proteome_dict [ "is_representative" ] = 1 acc_dict = { } other_accs = [ ] accession_nodes = proteome . findall ( prefix % "component" ) for node in accession_nodes : if node . get ( "name" ) . find ( "WGS" ) != - 1 : gen_acc_nodes = node . findall ( prefix % "genome_accession" ) if len ( gen_acc_nodes ) == 1 : acc_dict [ "WGS" ] = node . find ( prefix % "genome_accession" ) . text else : for gen_acc_node in gen_acc_nodes : other_accs . append ( gen_acc_node . text ) elif node . get ( "name" ) . find ( "Chloroplast" ) != - 1 : acc_dict [ "Chloroplast" ] = node . find ( prefix % "genome_accession" ) . text elif node . get ( "name" ) . find ( "Mitochondrion" ) != - 1 : acc_dict [ "Mitochondrion" ] = node . find ( prefix % "genome_accession" ) . text elif node . get ( "name" ) . find ( "Genome" ) != - 1 : description = node . find ( prefix % "description" ) . text proteome_dict [ "description" ] = description else : other_acc = node . find ( prefix % "genome_accession" ) if other_acc is not None : other_accs . append ( node . find ( prefix % "genome_accession" ) . text ) if len ( other_accs ) > 0 : acc_dict [ "other" ] = other_accs proteome_dict [ "accessions" ] = acc_dict return proteome_dict
Parses a proteome's xml file from Uniprot and converts it to a json
like object which is returned
Parses a proteome ' s xml file from Uniprot and converts it to a json like object which is returned
"""
    Parses a proteome's xml file from Uniprot and converts it to a json
    like object which is returned

    upid: A valid Uniprot Proteome identifier

    returns: A dictionary
    """ # namespace prefix # or register a namespace in the ET # check if we got an OK http reponse # initialization to the default values # initialization to the default values # get sequence accessions # look for all WGS accessions # single WGS accession
upid