Example #1
0
def test_query_term(database):
    """docstring for query_term"""
    term = 'HP:0003295'
    result = query_hpo([term], connection=database)
    hpo_dict = result[0]
    assert hpo_dict['hpo_term'] == term
    assert hpo_dict['description'] == 'Impaired FSH and LH secretion'
Example #2
0
def test_query_term(database):
    """docstring for query_term"""
    term = 'HP:0003295'
    result = query_hpo([term], connection=database)
    hpo_dict = result[0]
    assert hpo_dict['hpo_term'] == term
    assert hpo_dict['description'] == 'Impaired FSH and LH secretion'
Example #3
0
File: cli.py Project: dowing/phizz
def query(ctx, config, hpo_term, mim_term, outfile, to_json, chrom, start,
          stop):
    """Query the hpo database.\n
    
        Print the result in csv format as default.
    """
    if not (hpo_term or mim_term or chrom):
        logger.error("Please provide at least one hpo- or mim term")
        logger.info("Exiting")
        sys.exit(1)

    database = phizz_db
    if config:
        config = ConfigObj(config)
        database = config['database']

    logger.info("Using database {0}".format(database))

    header = "#{0}\t{1}".format('hpo_id', 'description')
    results = []

    if chrom and start and stop:
        for hgnc_symbol in query_gene_symbol(chrom, start, stop):
            results.append(hgnc_symbol)
        header = "#hgnc_symbol"

    if hpo_term:
        try:
            for result in query_hpo(hpo_terms=hpo_term, database=database):
                results.append(result)
        except ValueError:
            logger.info("Exiting")
            sys.exit(1)

    if mim_term:
        try:
            for result in query_disease(disease_terms=mim_term,
                                        database=database):
                results.append(result)
        except ValueError:
            logger.info("Exiting")
            sys.exit(1)

    if to_json:
        if outfile:
            json.dump(results, outfile)
        else:
            print(json.dumps(results))

    else:
        if outfile:
            outfile.write(header + '\n')
        else:
            print(header)

        for result in results:
            if chrom:
                print_line = result
            else:
                print_line = "{0}\t{1}".format(result['hpo_term'],
                                               result['description'])
            if outfile:
                outfile.write(print_line + '\n')
            else:
                print(print_line)
Example #4
0
File: cli.py Project: moonso/phizz
def query(ctx, config, hpo_term, mim_term, outfile, to_json, chrom, start, stop):
    """Query the hpo database.\n
    
        Print the result in csv format as default.
    """
    if not (hpo_term or mim_term or chrom):
        logger.error("Please provide at least one hpo- or mim term")
        logger.info("Exiting")
        sys.exit(1)

    database = phizz_db
    if config:
        config = ConfigObj(config)
        database = config["database"]

    logger.info("Using database {0}".format(database))

    header = "#{0}\t{1}".format("hpo_id", "description")
    results = []

    if chrom and start and stop:
        for hgnc_symbol in query_gene_symbol(chrom, start, stop):
            results.append(hgnc_symbol)
        header = "#hgnc_symbol"

    if hpo_term:
        try:
            for result in query_hpo(hpo_terms=hpo_term, database=database):
                results.append(result)
        except ValueError:
            logger.info("Exiting")
            sys.exit(1)

    if mim_term:
        try:
            for result in query_disease(disease_terms=mim_term, database=database):
                results.append(result)
        except ValueError:
            logger.info("Exiting")
            sys.exit(1)

    if to_json:
        if outfile:
            json.dump(results, outfile)
        else:
            print(json.dumps(results))

    else:
        if outfile:
            outfile.write(header + "\n")
        else:
            print(header)

        for result in results:
            if chrom:
                print_line = result
            else:
                print_line = "{0}\t{1}".format(result["hpo_term"], result["description"])
            if outfile:
                outfile.write(print_line + "\n")
            else:
                print(print_line)
Example #5
0
def test_query_non_existing_term(database):
    """docstring for query_term"""
    term = 'HP:0000001'
    result = query_hpo([term], connection=database)
    assert result == []
Example #6
0
def test_query_wrong_term(database):
    """docstring for query_term"""
    term = 'HPO'
    with pytest.raises(ValueError):
        result = query_hpo([term], connection=database)
Example #7
0
def test_query_non_existing_term(database):
    """docstring for query_term"""
    term = 'HP:0000001'
    result = query_hpo([term], connection=database)
    assert result == []
Example #8
0
def test_query_wrong_term(database):
    """docstring for query_term"""
    term = 'HPO'
    with pytest.raises(ValueError):
        result = query_hpo([term], connection=database)