parameters: (request:HttpRequest, project_id=None)
return_statement: return response
docstring: Export the NeuroML Level 3 version 1.8.1 representation of one or more skeletons.
      Considers synapses among the requested skeletons only.
docstring_summary: Export the NeuroML Level 3 version 1.8.1 representation of one or more skeletons.
      Considers synapses among the requested skeletons only.
docstring_tokens: Export the NeuroML Level 3 version 1 . 8 . 1 representation of one or more skeletons . Considers synapses among the requested skeletons only .
function: def export_neuroml_level3_v181(request:HttpRequest, project_id=None) -> HttpResponse:
      """Export the NeuroML Level 3 version 1.8.1 representation of one or more skeletons.
      Considers synapses among the requested skeletons only. """
      skeleton_ids = tuple(int(v) for v in request.POST.getlist('skids[]'))
      mode = int(request.POST.get('mode'))
      skeleton_strings = ",".join(map(str, skeleton_ids))
      cursor = connection.cursor()
  
      relations = get_relation_to_id_map(project_id, ('presynaptic_to', 'postsynaptic_to'), cursor)
      presynaptic_to = relations['presynaptic_to']
      postsynaptic_to = relations['postsynaptic_to']
  
      cursor.execute('''
      SELECT cici.class_instance_a, ci.name
      FROM class_instance_class_instance cici,
           class_instance ci,
           relation r
      WHERE cici.class_instance_a IN (%s)
        AND cici.class_instance_b = ci.id
        AND cici.relation_id = r.id
        AND r.relation_name = 'model_of'
      ''' % skeleton_strings)
  
      neuron_names = dict(cursor.fetchall())
  
      skeleton_query = '''
          SELECT id, parent_id, location_x, location_y, location_z,
                 radius, skeleton_id
          FROM treenode
          WHERE skeleton_id IN (%s)
          ORDER BY skeleton_id
          ''' % skeleton_strings
  
      if 0 == mode:
          cursor.execute('''
          SELECT treenode_id, connector_id, relation_id, skeleton_id
          FROM treenode_connector
          WHERE skeleton_id IN (%s)
            AND (relation_id = %s OR relation_id = %s)
          ''' % (skeleton_strings, presynaptic_to, postsynaptic_to))
  
          # Dictionary of connector ID vs map of relation_id vs list of treenode IDs
          connectors:DefaultDict = defaultdict(partial(defaultdict, list))
  
          for row in cursor.fetchall():
              connectors[row[1]][row[2]].append((row[0], row[3]))
  
          # Dictionary of presynaptic skeleton ID vs map of postsynaptic skeleton ID vs list of tuples with presynaptic treenode ID and postsynaptic treenode ID.
          connections:DefaultDict = defaultdict(partial(defaultdict, list))
  
          for connectorID, m in connectors.items():
              for pre_treenodeID, skID1 in m[presynaptic_to]:
                  for post_treenodeID, skID2 in m[postsynaptic_to]:
                      connections[skID1][skID2].append((pre_treenodeID, post_treenodeID))
  
          cursor.execute(skeleton_query)
  
          generator = export_NeuroML_Level3.exportMutual(neuron_names, cursor.fetchall(), connections)
  
      else:
          if len(skeleton_ids) > 1:
              raise Exception("Expected a single skeleton for mode %s!" % mode)
          input_ids = tuple(int(v) for v in request.POST.getlist('inputs[]', []))
          input_strings = ",".join(map(str, input_ids))
          if 2 == mode:
              constraint = "AND tc2.skeleton_id IN (%s)" % input_strings
          elif 1 == mode:
              constraint = ""
          else:
              raise Exception("Unknown mode %s" % mode)
  
          cursor.execute('''
          SELECT tc2.skeleton_id, tc1.treenode_id
          FROM treenode_connector tc1,
               treenode_connector tc2
          WHERE tc1.skeleton_id = %s
            AND tc1.connector_id = tc2.connector_id
            AND tc1.treenode_id != tc2.treenode_id
            AND tc1.relation_id = %s
            AND tc2.relation_id = %s
            %s
          ''' % (skeleton_strings, postsynaptic_to, presynaptic_to, constraint))
  
          # Dictionary of skeleton ID vs list of treenode IDs at which the neuron receives inputs
          inputs:DefaultDict[Any, List] = defaultdict(list)
          for row in cursor.fetchall():
              inputs[row[0]].append(row[1])
  
          cursor.execute(skeleton_query)
  
          generator = export_NeuroML_Level3.exportSingle(neuron_names, cursor.fetchall(), inputs)
  
      response = HttpResponse(generator, content_type='text/plain')
      response['Content-Disposition'] = 'attachment; filename=neuronal-circuit.neuroml'
  
      return response
function_tokens: def export_neuroml_level3_v181 ( request : HttpRequest , project_id = None ) -> HttpResponse : skeleton_ids = tuple ( int ( v ) for v in request . POST . getlist ( 'skids[]' ) ) mode = int ( request . POST . get ( 'mode' ) ) skeleton_strings = "," . join ( map ( str , skeleton_ids ) ) cursor = connection . cursor ( ) relations = get_relation_to_id_map ( project_id , ( 'presynaptic_to' , 'postsynaptic_to' ) , cursor ) presynaptic_to = relations [ 'presynaptic_to' ] postsynaptic_to = relations [ 'postsynaptic_to' ] cursor . execute ( '''
      SELECT cici.class_instance_a, ci.name
      FROM class_instance_class_instance cici,
           class_instance ci,
           relation r
      WHERE cici.class_instance_a IN (%s)
        AND cici.class_instance_b = ci.id
        AND cici.relation_id = r.id
        AND r.relation_name = 'model_of'
      ''' % skeleton_strings ) neuron_names = dict ( cursor . fetchall ( ) ) skeleton_query = '''
          SELECT id, parent_id, location_x, location_y, location_z,
                 radius, skeleton_id
          FROM treenode
          WHERE skeleton_id IN (%s)
          ORDER BY skeleton_id
          ''' % skeleton_strings if 0 == mode : cursor . execute ( '''
          SELECT treenode_id, connector_id, relation_id, skeleton_id
          FROM treenode_connector
          WHERE skeleton_id IN (%s)
            AND (relation_id = %s OR relation_id = %s)
          ''' % ( skeleton_strings , presynaptic_to , postsynaptic_to ) ) # Dictionary of connector ID vs map of relation_id vs list of treenode IDs connectors : DefaultDict = defaultdict ( partial ( defaultdict , list ) ) for row in cursor . fetchall ( ) : connectors [ row [ 1 ] ] [ row [ 2 ] ] . append ( ( row [ 0 ] , row [ 3 ] ) ) # Dictionary of presynaptic skeleton ID vs map of postsynaptic skeleton ID vs list of tuples with presynaptic treenode ID and postsynaptic treenode ID. connections : DefaultDict = defaultdict ( partial ( defaultdict , list ) ) for connectorID , m in connectors . items ( ) : for pre_treenodeID , skID1 in m [ presynaptic_to ] : for post_treenodeID , skID2 in m [ postsynaptic_to ] : connections [ skID1 ] [ skID2 ] . append ( ( pre_treenodeID , post_treenodeID ) ) cursor . execute ( skeleton_query ) generator = export_NeuroML_Level3 . exportMutual ( neuron_names , cursor . fetchall ( ) , connections ) else : if len ( skeleton_ids ) > 1 : raise Exception ( "Expected a single skeleton for mode %s!" % mode ) input_ids = tuple ( int ( v ) for v in request . POST . getlist ( 'inputs[]' , [ ] ) ) input_strings = "," . join ( map ( str , input_ids ) ) if 2 == mode : constraint = "AND tc2.skeleton_id IN (%s)" % input_strings elif 1 == mode : constraint = "" else : raise Exception ( "Unknown mode %s" % mode ) cursor . execute ( '''
          SELECT tc2.skeleton_id, tc1.treenode_id
          FROM treenode_connector tc1,
               treenode_connector tc2
          WHERE tc1.skeleton_id = %s
            AND tc1.connector_id = tc2.connector_id
            AND tc1.treenode_id != tc2.treenode_id
            AND tc1.relation_id = %s
            AND tc2.relation_id = %s
            %s
          ''' % ( skeleton_strings , postsynaptic_to , presynaptic_to , constraint ) ) # Dictionary of skeleton ID vs list of treenode IDs at which the neuron receives inputs inputs : DefaultDict [ Any , List ] = defaultdict ( list ) for row in cursor . fetchall ( ) : inputs [ row [ 0 ] ] . append ( row [ 1 ] ) cursor . execute ( skeleton_query ) generator = export_NeuroML_Level3 . exportSingle ( neuron_names , cursor . fetchall ( ) , inputs ) response = HttpResponse ( generator , content_type = 'text/plain' ) response [ 'Content-Disposition' ] = 'attachment; filename=neuronal-circuit.neuroml' return response