🔍 Code Extractor

function get_lims_samples_with_references_flocks_dbo_flocks

Maturity: 40

Queries a Neo4j graph database to retrieve dbo_Flocks nodes that are connected to a specific LIMS_Samples node through a REFERENCES_FLOCKS relationship.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1513 - 1520
Complexity:
simple

Purpose

This function is designed to traverse a graph database relationship between laboratory information management system (LIMS) samples and flock records. It retrieves flock information associated with a given sample ID, which is useful for tracking biological samples back to their source flocks in agricultural or research contexts. The function supports pagination through a configurable limit parameter.

Source Code

def get_lims_samples_with_references_flocks_dbo_flocks(source_id, limit=100):
    """Get dbo_Flocks nodes connected to a LIMS_Samples via REFERENCES_FLOCKS"""
    query = """
    MATCH (source:LIMS_Samples {id: $source_id})-[r:REFERENCES_FLOCKS]->(target:dbo_Flocks)
    RETURN target
    LIMIT $limit
    """
    return run_query(query, {"source_id": source_id, "limit": limit})

Parameters

Name Type Default Kind
source_id - - positional_or_keyword
limit - 100 positional_or_keyword

Parameter Details

source_id: The unique identifier of the LIMS_Samples node to query. This should be a string or value that matches the 'id' property of a LIMS_Samples node in the Neo4j database.

limit: Maximum number of dbo_Flocks nodes to return. Defaults to 100. This parameter controls pagination and prevents returning excessively large result sets. Must be a positive integer.

Return Value

Returns the result of the run_query function, which typically contains a list or collection of dbo_Flocks nodes (target nodes) that match the query criteria. The exact return type depends on the implementation of run_query, but it likely returns a list of dictionaries or Neo4j Record objects containing the properties of the matched dbo_Flocks nodes. Returns an empty collection if no matching relationships are found.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j is configured
# Example run_query implementation:
from neo4j import GraphDatabase

driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))

def run_query(query, params):
    with driver.session() as session:
        result = session.run(query, params)
        return [record['target'] for record in result]

# Use the function
sample_id = 'SAMPLE_12345'
flocks = get_lims_samples_with_references_flocks_dbo_flocks(sample_id, limit=50)

# Process results
for flock in flocks:
    print(f"Flock ID: {flock['id']}, Name: {flock.get('name', 'N/A')}")

Best Practices

  • Ensure the source_id parameter matches the exact format and type stored in the Neo4j database
  • Use appropriate limit values to avoid performance issues with large datasets
  • Handle cases where no relationships exist (empty result set) in calling code
  • Consider adding error handling for database connection failures
  • Validate that the run_query function properly closes database connections to prevent resource leaks
  • Consider adding indexes on the LIMS_Samples.id property in Neo4j for better query performance
  • Be aware that this function depends on the external run_query function which must be properly implemented

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_references_flocks_relationship 84.7% similar

    Creates a REFERENCES_FLOCKS relationship in a Neo4j graph database between a LIMS_Samples node and a dbo_Flocks node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletestresults_with_references_samples_lims_samples 77.9% similar

    Queries a Neo4j graph database to retrieve LIMS_Samples nodes that are connected to a specific LIMS_SampleTestResults node through a REFERENCES_SAMPLES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_flocks_with_references_flocktypes_dbo_flocktypes 77.3% similar

    Queries a Neo4j graph database to retrieve dbo_FlockTypes nodes that are connected to a specific dbo_Flocks node via a REFERENCES_FLOCKTYPES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_samples_with_references_requests_lims_requests 76.4% similar

    Queries a Neo4j graph database to retrieve LIMS_Requests nodes that are connected to a specific LIMS_Samples node via a REFERENCES_REQUESTS relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_with_references_flocks_dbo_flocks 76.2% similar

    Queries a Neo4j graph database to retrieve dbo_Flocks nodes that are connected to a specific dbo_InterventionProtocolFlocks node through a REFERENCES_FLOCKS relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse