scout/load/hpo.py
def load_hpo_terms(adapter, hpo_lines=None, hpo_gene_lines=None, alias_genes=None):
    """Load the hpo terms into the database
    
    Parse the hpo lines, build the objects and add them to the database
    
    Args:
        adapter(MongoAdapter)
        hpo_lines(iterable(str))
        hpo_gene_lines(iterable(str))
    """
    
    # Store the hpo terms
    hpo_terms = {}
    
    # Fetch the hpo terms if no file
    if not hpo_lines:
        hpo_lines = fetch_hpo_terms()
    
    # Fetch the hpo gene information if no file
    if not hpo_gene_lines:
        hpo_gene_lines = fetch_hpo_to_genes()

    # Parse the terms
    # This will yield dictionaries with information about the terms
    LOG.info("Parsing hpo terms")
    for term in parse_hpo_obo(hpo_lines):
        hpo_terms[term['hpo_id']] = term
    
    # Get a map with hgnc symbols to hgnc ids from scout
    if not alias_genes:
        alias_genes = adapter.genes_by_alias()

    LOG.info("Adding gene information to hpo terms ...")
    for hpo_to_symbol in parse_hpo_to_genes(hpo_gene_lines):
        hgnc_symbol = hpo_to_symbol['hgnc_symbol']
        hpo_id = hpo_to_symbol['hpo_id']
        
        # Fetch gene info to get correct hgnc id
        gene_info = alias_genes.get(hgnc_symbol)
        if not gene_info:
            continue

        hgnc_id = gene_info['true']

        if hpo_id not in hpo_terms:
            continue

        hpo_term = hpo_terms[hpo_id]

        if not 'genes' in hpo_term:
            hpo_term['genes'] = set()

        hpo_term['genes'].add(hgnc_id)

    start_time = datetime.now()

    LOG.info("Loading the hpo terms...")
    nr_terms = len(hpo_terms)
    hpo_bulk = []
    with progressbar(hpo_terms.values(), label="Loading hpo terms", length=nr_terms) as bar:
        
        for hpo_info in bar:
            hpo_bulk.append(build_hpo_term(hpo_info))
        
        if len(hpo_bulk) > 10000:
            adapter.load_hpo_bulk(hpo_bulk)
            hpo_bulk = []
    
    if hpo_bulk:
        adapter.load_hpo_bulk(hpo_bulk)
    
    LOG.info("Loading done. Nr of terms loaded {0}".format(nr_terms))
    LOG.info("Time to load terms: {0}".format(datetime.now() - start_time))
def load_hpo_terms(adapter, hpo_lines=None, hpo_gene_lines=None, alias_genes=None):
    """Load the hpo terms into the database
    
    Parse the hpo lines, build the objects and add them to the database
    
    Args:
        adapter(MongoAdapter)
        hpo_lines(iterable(str))
        hpo_gene_lines(iterable(str))
    """
    
    # Store the hpo terms
    hpo_terms = {}
    
    # Fetch the hpo terms if no file
    if not hpo_lines:
        hpo_lines = fetch_hpo_terms()
    
    # Fetch the hpo gene information if no file
    if not hpo_gene_lines:
        hpo_gene_lines = fetch_hpo_to_genes()

    # Parse the terms
    # This will yield dictionaries with information about the terms
    LOG.info("Parsing hpo terms")
    for term in parse_hpo_obo(hpo_lines):
        hpo_terms[term['hpo_id']] = term
    
    # Get a map with hgnc symbols to hgnc ids from scout
    if not alias_genes:
        alias_genes = adapter.genes_by_alias()

    LOG.info("Adding gene information to hpo terms ...")
    for hpo_to_symbol in parse_hpo_to_genes(hpo_gene_lines):
        hgnc_symbol = hpo_to_symbol['hgnc_symbol']
        hpo_id = hpo_to_symbol['hpo_id']
        
        # Fetch gene info to get correct hgnc id
        gene_info = alias_genes.get(hgnc_symbol)
        if not gene_info:
            continue

        hgnc_id = gene_info['true']

        if hpo_id not in hpo_terms:
            continue

        hpo_term = hpo_terms[hpo_id]

        if not 'genes' in hpo_term:
            hpo_term['genes'] = set()

        hpo_term['genes'].add(hgnc_id)

    start_time = datetime.now()

    LOG.info("Loading the hpo terms...")
    nr_terms = len(hpo_terms)
    hpo_bulk = []
    with progressbar(hpo_terms.values(), label="Loading hpo terms", length=nr_terms) as bar:
        
        for hpo_info in bar:
            hpo_bulk.append(build_hpo_term(hpo_info))
        
        if len(hpo_bulk) > 10000:
            adapter.load_hpo_bulk(hpo_bulk)
            hpo_bulk = []
    
    if hpo_bulk:
        adapter.load_hpo_bulk(hpo_bulk)
    
    LOG.info("Loading done. Nr of terms loaded {0}".format(nr_terms))
    LOG.info("Time to load terms: {0}".format(datetime.now() - start_time))
def load_hpo_terms ( adapter , hpo_lines = None , hpo_gene_lines = None , alias_genes = None ) : # Store the hpo terms hpo_terms = { } # Fetch the hpo terms if no file if not hpo_lines : hpo_lines = fetch_hpo_terms ( ) # Fetch the hpo gene information if no file if not hpo_gene_lines : hpo_gene_lines = fetch_hpo_to_genes ( ) # Parse the terms # This will yield dictionaries with information about the terms LOG . info ( "Parsing hpo terms" ) for term in parse_hpo_obo ( hpo_lines ) : hpo_terms [ term [ 'hpo_id' ] ] = term # Get a map with hgnc symbols to hgnc ids from scout if not alias_genes : alias_genes = adapter . genes_by_alias ( ) LOG . info ( "Adding gene information to hpo terms ..." ) for hpo_to_symbol in parse_hpo_to_genes ( hpo_gene_lines ) : hgnc_symbol = hpo_to_symbol [ 'hgnc_symbol' ] hpo_id = hpo_to_symbol [ 'hpo_id' ] # Fetch gene info to get correct hgnc id gene_info = alias_genes . get ( hgnc_symbol ) if not gene_info : continue hgnc_id = gene_info [ 'true' ] if hpo_id not in hpo_terms : continue hpo_term = hpo_terms [ hpo_id ] if not 'genes' in hpo_term : hpo_term [ 'genes' ] = set ( ) hpo_term [ 'genes' ] . add ( hgnc_id ) start_time = datetime . now ( ) LOG . info ( "Loading the hpo terms..." ) nr_terms = len ( hpo_terms ) hpo_bulk = [ ] with progressbar ( hpo_terms . values ( ) , label = "Loading hpo terms" , length = nr_terms ) as bar : for hpo_info in bar : hpo_bulk . append ( build_hpo_term ( hpo_info ) ) if len ( hpo_bulk ) > 10000 : adapter . load_hpo_bulk ( hpo_bulk ) hpo_bulk = [ ] if hpo_bulk : adapter . load_hpo_bulk ( hpo_bulk ) LOG . info ( "Loading done. Nr of terms loaded {0}" . format ( nr_terms ) ) LOG . info ( "Time to load terms: {0}" . format ( datetime . now ( ) - start_time ) )
Load the hpo terms into the database
    
    Parse the hpo lines, build the objects and add them to the database
    
    Args:
        adapter(MongoAdapter)
        hpo_lines(iterable(str))
        hpo_gene_lines(iterable(str))
Load the hpo terms into the database Parse the hpo lines build the objects and add them to the database Args : adapter ( MongoAdapter ) hpo_lines ( iterable ( str )) hpo_gene_lines ( iterable ( str ))