scripts/export/genomes/fetch_gen_metadata.py
def fetch_wgs_metadata(upid, assembly_acc, domain):
    """
    Parses ENA WGS accession xml, and returns the accession's data in the
    form of a dictionary

    upid: A valid Uniprot's proteome id
    assembly_acc: A valid ENA's WGS accession
    domain: A string representing the domain a species belongs to (e.g.viruses)
    """

    wgs_entry = {}
    fields = {}

    response = requests.get(gc.ENA_XML_URL % assembly_acc)

    if response.status_code == httplib.OK:
        assembly_xml = ET.fromstring(response.content)  # root

        entry = assembly_xml.find("entry")

        fields["gca_acc"] = None
        fields["gca_version"] = None

        fields["wgs_acc"] = entry.get("accession")
        fields["wgs_version"] = int(entry.get("version"))
        fields["ensembl_id"] = None  # post processing

        # fetching assembly name out of entry's comment lines
        entry_comment = None
        entry_comment = entry.find("comment")

        if entry_comment is not None:
            assembly_name = get_wgs_assembly_name(
                entry.find("comment").text)
            fields["assembly_name"] = assembly_name

        else:
            fields["assembly_name"] = None

        if entry.get("topology") == "linear":
            fields["circular"] = 0
        else:
            fields["circular"] = 1

        fields["assembly_level"] = "contig"

        fields["study_ref"] = entry.find("projectAccession").text

        description = ''
        if entry.find("reference") is not None:
            if entry.find("reference").find("title") is not None:
                description = entry.find("reference").find("title").text
        fields["description"] = description

        fields["kingdom"] = domain

        taxon = entry.find("feature").find("taxon")
        fields["scientific_name"] = taxon.get("scientificName")
        fields["common_name"] = None
        fields["ncbi_id"] = int(taxon.get("taxId"))

        fields["total_length"] = None
        fields["ungapped_length"] = None

        fields["num_gen_regions"] = None

        fields["num_rfam_regions"] = None  # post process
        fields["num_families"] = None  # post process

        # this takes the date of the entry is created
        entry_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        fields["created"] = entry_date
        fields["updated"] = entry_date

        wgs_entry["model"] = gc.GENOME_MODEL
        wgs_entry["pk"] = upid
        wgs_entry["fields"] = fields

    return wgs_entry

    Parses ENA WGS accession xml, and returns the accession's data in the
    form of a dictionary

    upid: A valid Uniprot's proteome id
    assembly_acc: A valid ENA's WGS accession
    domain: A string representing the domain a species belongs to (e.g.viruses)
    
Parses ENA WGS accession xml, and returns the accession's data in the
form of a dictionary

A valid Uniprot's proteome id
assembly_acc: A valid ENA's WGS accession
domain: A string representing the domain a species belongs to
Parses ENA WGS accession xml and returns the accession ' s data in the form of a dictionary A valid Uniprot ' s proteome id assembly_acc : A valid ENA ' s WGS accession domain : A string representing the domain a species belongs to
def fetch_wgs_metadata(upid, assembly_acc, domain):
    wgs_entry = {}
    fields = {}
    response = requests.get(gc.ENA_XML_URL % assembly_acc)
    if response.status_code == httplib.OK:
        assembly_xml = ET.fromstring(response.content)  
        entry = assembly_xml.find("entry")
        fields["gca_acc"] = None
        fields["gca_version"] = None
        fields["wgs_acc"] = entry.get("accession")
        fields["wgs_version"] = int(entry.get("version"))
        fields["ensembl_id"] = None  
        entry_comment = None
        entry_comment = entry.find("comment")
        if entry_comment is not None:
            assembly_name = get_wgs_assembly_name(
                entry.find("comment").text)
            fields["assembly_name"] = assembly_name
        else:
            fields["assembly_name"] = None
        if entry.get("topology") == "linear":
            fields["circular"] = 0
        else:
            fields["circular"] = 1
        fields["assembly_level"] = "contig"
        fields["study_ref"] = entry.find("projectAccession").text
        description = ''
        if entry.find("reference") is not None:
            if entry.find("reference").find("title") is not None:
                description = entry.find("reference").find("title").text
        fields["description"] = description
        fields["kingdom"] = domain
        taxon = entry.find("feature").find("taxon")
        fields["scientific_name"] = taxon.get("scientificName")
        fields["common_name"] = None
        fields["ncbi_id"] = int(taxon.get("taxId"))
        fields["total_length"] = None
        fields["ungapped_length"] = None
        fields["num_gen_regions"] = None
        fields["num_rfam_regions"] = None  
        fields["num_families"] = None  
        entry_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        fields["created"] = entry_date
        fields["updated"] = entry_date
        wgs_entry["model"] = gc.GENOME_MODEL
        wgs_entry["pk"] = upid
        wgs_entry["fields"] = fields
    return wgs_entry
def fetch_wgs_metadata ( upid , assembly_acc , domain ) : wgs_entry = { } fields = { } response = requests . get ( gc . ENA_XML_URL % assembly_acc ) if response . status_code == httplib . OK : assembly_xml = ET . fromstring ( response . content ) entry = assembly_xml . find ( "entry" ) fields [ "gca_acc" ] = None fields [ "gca_version" ] = None fields [ "wgs_acc" ] = entry . get ( "accession" ) fields [ "wgs_version" ] = int ( entry . get ( "version" ) ) fields [ "ensembl_id" ] = None entry_comment = None entry_comment = entry . find ( "comment" ) if entry_comment is not None : assembly_name = get_wgs_assembly_name ( entry . find ( "comment" ) . text ) fields [ "assembly_name" ] = assembly_name else : fields [ "assembly_name" ] = None if entry . get ( "topology" ) == "linear" : fields [ "circular" ] = 0 else : fields [ "circular" ] = 1 fields [ "assembly_level" ] = "contig" fields [ "study_ref" ] = entry . find ( "projectAccession" ) . text description = '' if entry . find ( "reference" ) is not None : if entry . find ( "reference" ) . find ( "title" ) is not None : description = entry . find ( "reference" ) . find ( "title" ) . text fields [ "description" ] = description fields [ "kingdom" ] = domain taxon = entry . find ( "feature" ) . find ( "taxon" ) fields [ "scientific_name" ] = taxon . get ( "scientificName" ) fields [ "common_name" ] = None fields [ "ncbi_id" ] = int ( taxon . get ( "taxId" ) ) fields [ "total_length" ] = None fields [ "ungapped_length" ] = None fields [ "num_gen_regions" ] = None fields [ "num_rfam_regions" ] = None fields [ "num_families" ] = None entry_date = datetime . datetime . now ( ) . strftime ( "%Y-%m-%d %H:%M:%S" ) fields [ "created" ] = entry_date fields [ "updated" ] = entry_date wgs_entry [ "model" ] = gc . GENOME_MODEL wgs_entry [ "pk" ] = upid wgs_entry [ "fields" ] = fields return wgs_entry
Parses ENA WGS accession xml, and returns the accession's data in the
form of a dictionary
Parses ENA WGS accession xml and returns the accession ' s data in the form of a dictionary
"""
    Parses ENA WGS accession xml, and returns the accession's data in the
    form of a dictionary

    upid: A valid Uniprot's proteome id
    assembly_acc: A valid ENA's WGS accession
    domain: A string representing the domain a species belongs to (e.g.viruses)
    """ # root # post processing # fetching assembly name out of entry's comment lines # post process # post process # this takes the date of the entry is created
upid
assembly_acc
domain