# Open the wanted_accessions file and read in each accession, stripping newline # characters, and adding each accesion into the list accession_ids accession_IDs = [] with open(wanted_accessions, "r") as accessions: accessions_list = accessions.readlines() for line in accessions_list: line = line.rstrip() accession_IDs.append(line) # Join each accession id into a string seperated by '+' characters for URL # construction below gene_IDs = "+".join(accession_IDs) # Construct the URL with wanted accessions, Example URL: # http://iptol-api.iplantcollaborative.org/onekp/v1/orthogroups? # accession=AT4G04640+AT1G15700+AT4G09650+AT2G07707+AT4G32260 # &token=1463695387322_wsMwZ5o5EmmC1Oan # &format=zip wanted_url = base_url + "orthogroups?" + "accession=" + gene_IDs + "&token=" + auth_token + "&format=" + file_format # Retrieve the wanted orthogroups and if an ok status code is given by the # server, extract the zipped archive. If a bad status code is given by the # server, print the attempted URL and the bad status code. orthogroup_file = requests.get(wanted_url, auth=HTTPDigestAuth("1kp-data", "1kp-rna1")) if orthogroup_file.status_code == requests.codes.ok: # print 'Success using this URL:', orthogroup_file.url orthogroup_file = ZipFile(StringIO(orthogroup_file.content)) orthogroup_file.extractall() else: orthogroup_file.raise_for_status() print "Error using this URL:", orthogroup_file.url