🔍 Code Extractor

function get_lims_samples_with_references_sampletypes_lims_sampletypes

Maturity: 40

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1449 - 1456
Complexity:
simple

Purpose

This function is designed to fetch sample type information from a Laboratory Information Management System (LIMS) graph database. It retrieves all sample type nodes associated with a given sample ID, which is useful for understanding what types of samples are referenced by a particular LIMS sample record. The function supports pagination through a limit parameter to control the number of results returned.

Source Code

def get_lims_samples_with_references_sampletypes_lims_sampletypes(source_id, limit=100):
    """Get LIMS_SampleTypes nodes connected to a LIMS_Samples via REFERENCES_SAMPLETYPES"""
    query = """
    MATCH (source:LIMS_Samples {id: $source_id})-[r:REFERENCES_SAMPLETYPES]->(target:LIMS_SampleTypes)
    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 from which to start the traversal. 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 LIMS_SampleTypes nodes to return. Defaults to 100. This parameter helps control query performance and result set size. Must be a positive integer.

Return Value

Returns the result of executing a Neo4j Cypher query via the run_query function. The exact return type depends on the run_query implementation, but typically returns a list of records containing LIMS_SampleTypes nodes with their properties. Each record represents a target node that has a REFERENCES_SAMPLETYPES relationship from the source LIMS_Samples node. Returns an empty result set if no matching relationships are found.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j connection is configured
# Example 1: Get sample types for a specific sample with default limit
result = get_lims_samples_with_references_sampletypes_lims_sampletypes('SAMPLE_12345')

# Example 2: Get sample types with custom limit
result = get_lims_samples_with_references_sampletypes_lims_sampletypes('SAMPLE_12345', limit=50)

# Example 3: Process the results
for record in result:
    sample_type = record['target']
    print(f"Sample Type ID: {sample_type['id']}")
    print(f"Sample Type Properties: {sample_type}")

Best Practices

  • Ensure the source_id parameter matches an existing LIMS_Samples node ID in the database to avoid empty results
  • Use appropriate limit values to balance between completeness and performance - very large limits may impact query performance
  • Handle cases where no relationships exist (empty result set) in calling code
  • The run_query function should implement proper error handling and connection management for Neo4j
  • Consider implementing connection pooling and proper session management in the run_query function for production use
  • Validate that the Neo4j database schema includes the expected node labels (LIMS_Samples, LIMS_SampleTypes) and relationship type (REFERENCES_SAMPLETYPES)
  • Consider adding error handling for invalid source_id values or database connection failures

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_sampletypetests_with_references_sampletypes_lims_sampletypes 94.4% similar

    Queries a Neo4j graph database to retrieve LIMS_SampleTypes nodes that are connected to a specific LIMS_SampleTypeTests node through a REFERENCES_SAMPLETYPES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletestresults_with_references_samples_lims_samples 89.4% 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_all_lims_sampletypes 89.1% similar

    Queries a Neo4j graph database to retrieve LIMS_SampleTypes nodes with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletypes_by_id 88.6% similar

    Retrieves a single LIMS_SampleTypes node from a Neo4j graph database by matching its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletypetests_with_references_tests_lims_tests 88.1% similar

    Queries a Neo4j graph database to retrieve LIMS_Tests nodes that are connected to a specific LIMS_SampleTypeTests node through a REFERENCES_TESTS relationship.

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