<jupyter_start><jupyter_text>How to get the URL:- Perform a search on uniptot- Click on the "Download" button, select "XML" as format, and select "Preview first 10"- Copy that url and delete the part that reads "&limit=10"<jupyter_code># Change the URL to fit your request
url = "https://www.uniprot.org/uniprot/?query=*&format=xml&fil=organism:%22Homo%20sapiens%20(Human)%20[9606]%22%20AND%20reviewed:yes"

# Don't change the following if you don't know exactly what you are doing!
namespaces = {
    'd':'http://uniprot.org/uniprot',
}
# This might take a while... sit back and relax
tree = ET.parse(urlopen(url))
root = tree.getroot()
locations_list = list()

for protein in root.findall('d:entry', namespaces=namespaces):
    accession = protein.find('d:accession', namespaces=namespaces).text
    comments = protein.findall('d:comment[@type="subcellular location"]', namespaces=namespaces)
    
    for sub_cell_loc_comment in comments:
        subcellularLocations = sub_cell_loc_comment.findall('d:subcellularLocation', namespaces=namespaces)

        for subcellularLocation in subcellularLocations:
            location = subcellularLocation.find('d:location', namespaces=namespaces)
            location_text = location.text
            evidences = location.get('evidence')
            
            if evidences:
                for evidence in evidences.split(' '):
                    current_evidence = protein.find('d:evidence[@key="{}"]'.format(evidence), namespaces=namespaces)
                    locations_list.append([accession, current_evidence.get('type'), location_text])
            else:
                locations_list.append([accession, None, location_text])
    
locations_dataframe = pd.DataFrame(locations_list, columns=['accession', 'evidence', 'location']).drop_duplicates()
locations_dataframe.to_csv("locations.tsv", sep='\t', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12256706996317727, 'fraction_numerical': 0.011572856391372961, 'mean_word_length': 4.112903225806452, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '394382', 'license': 'MIT', 'n_tokens_mistral': 600, 'n_tokens_neox': 550, 'n_words': 127, 'path': 'extract_subcellular_locations.ipynb', 'repo_name': 'sacdallago/uniprot_subcellular_location_extraction', 'size': '1901'}