Cache projection structure unionizes for all projection datasets

In [9]:
from allensdk.api.queries.rma_api import RmaApi
import os
import urllib
In [52]:
# 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)
        
Fetch experiments from product ConnProj
  2126 dataset retrieved
Fetch experiments from product ConnRetinaProjection
  77 dataset retrieved
Fetch experiments from product ConnAntCreEGFP
  29 dataset retrieved
Fetch experiments from product ConnAntCreSypEGFP
  47 dataset retrieved