Cache projection structure unionizes for all projection datasets
from allensdk.api.queries.rma_api import RmaApi
import os
import urllib
# Use RMA API to fetch projection datasets from projection related products
products = ['ConnProj',
'ConnRetinaProjection',
'ConnAntCreEGFP',
'ConnAntCreSypEGFP',
'ConnAntTarget',
'ConnAntTargetAssocCort']
# create an API instance
ra = RmaApi()
# output directory to store results
base_output_path = "."
for p in products :
print "Fetch experiments from product %s" % p
data = ra.model_query( model='SectionDataSet',
filters={'failed':'false'},
criteria="products[abbreviation$eq'%s']" % p,
num_rows="all")
print " %d dataset retrieved" % len(data)
# create output directory
output_directory = os.path.join( base_output_path, p )
if not os.path.exists(output_directory):
os.makedirs(output_directory)
# fetch projection structure unionizes for each experiment as csv file
for ds in data :
#print " experiment: %d" % ds['id']
ms = ra.model_stage( 'ProjectionStructureUnionize',
criteria="section_data_set[id$eq%d]" % ds['id'],
num_rows="all" )
url = ra.build_query_url( ms, fmt='csv')
output_file = os.path.join( output_directory, '%d.csv' % ds['id'])
testfile = urllib.URLopener()
testfile.retrieve(url, output_file)