Esempio n. 1
0
def test_query_disease(database):
    """docstring for query_term"""
    term = 'OMIM:600920'
    result = query_disease([term], connection=database)

    cursor = database.cursor()

    hpo_terms = set()
    for res in result:
        hpo_terms.add(res['hpo_term'])

    assert "HP:0000767" in hpo_terms
    assert "HP:0003042" in hpo_terms
Esempio n. 2
0
def test_query_disease(database):
    """docstring for query_term"""
    term = 'OMIM:600920'
    result = query_disease([term], connection=database)
    
    cursor = database.cursor()
    
    hpo_terms = set()
    for res in result:
        hpo_terms.add(res['hpo_term'])
    
    assert "HP:0000767" in hpo_terms
    assert "HP:0003042" in hpo_terms
Esempio n. 3
0
File: cli.py Progetto: 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)
Esempio n. 4
0
def test_query_non_existing_term(database):
    """docstring for query_term"""
    term = 'OMIM:1'
    result = query_disease([term], connection=database)
    assert result == []
Esempio n. 5
0
def test_query_wrong_term(database):
    """docstring for query_term"""
    term = 'MIM'
    with pytest.raises(ValueError):
        result = query_disease([term], connection=database)
Esempio n. 6
0
def test_query_non_existing_term(database):
    """docstring for query_term"""
    term = 'OMIM:1'
    result = query_disease([term], connection=database)
    assert result == []
Esempio n. 7
0
def test_query_wrong_term(database):
    """docstring for query_term"""
    term = 'MIM'
    with pytest.raises(ValueError):
        result = query_disease([term], connection=database)
Esempio n. 8
0
File: cli.py Progetto: 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)