Skip to content

Repository files navigation

Build StatusCoverage Status

Useful Online Annotation Scripts for Variants, Genes and HPO

CommonFuncs.py has some common functions Variants.py has some variant classes (automatically clean variant formats using CommonFuncs.py, help find online ExAC and kaviar [using http://exac.hms.harvard.edu/rest/] and sometimes cadd if given a cadd tsv file) Genes.py has some gene classes (help find online ExAC pLI, mis-z, symbol, alias using mygene.org)

CommonFuncs examples

clean_variant() is very useful in that it can trim redundant bases, and that it also can fill missing bases.

v='2-27665608-TC--'
print clean_variant(v)

Variant classes examples

importsqlite3importVariantsimportjsondb_conn=sqlite3.connect('irdc.db')
V=Variants.Variants(db_conn,['20-61523355-T-C','X-153694021-C-T'])
printjson.dumps(V.exac, indent=4)

Compare dataframes

In the field of genetic diagosis, end results are refreshed when new evidence is introduced. Manual inspection necessitates highlight of changes to avoid wasting time on unchanged data.

importCompareimportpandasaspdfields_to_check= {
'field1_to_check':None,
'field2_to_check':None,
}
Compare.compare_dfs('original_df', 'new_df', 'index', fields_to_check)
{
'+':['index1','index3'],
'-':['index2','index6'],
'<>':{
'index4':{
'change':{
'field1_to_check':{
'from':'foo',
'to':'bar'
}
}
}
}
}

You can also pass your customised compare functions as values of fields for alternative comparisons

importCompareimportpandasaspddeffilter_cb(a,b):
dc= {
'PASS':3,
'VQSR':2,
'FAIL':1,
}
ifdc[b] >dc[a]: returnTrueelse: returnFalsefields_to_check= {
'FILTER':filter_cb,
'field2_to_check':None,
}
Compare.compare_dfs('original_df', 'new_df', 'index', fields_to_check)

Or you can use closures to create some even more customised comparison methods (useful when you want to variate some cutoffs.

importCompareimportpandasaspddefexac_cb_factory(thrd):
defexac_cb_inner(a,b):
# convert np.nan to None# since np.nan != np.nana=Noneifpd.isnull(a) elseab=Noneifpd.isnull(b) elseb# equal?ifa==b: returnFalse# one > thrd, one < thrd?ifsorted([a,b,thrd])[1] ==thrd: returnTrue# both > thrd?ifmin(a,b,thrd) ==thrd: returnFalseelse: returnTruereturnexac_cb_innerexac_cutoff=0.01exac_compare=exac_cb_factory(exac_cutoff)
fields_to_check= {
'EXAC_AF':exac_compare,
'field2_to_check':None,
}
Compare.compare_dfs('original_df', 'new_df', 'index', fields_to_check)

When None is given as field value, it uses good old == for comparison. It takes care of the case where np.nan != np.nan

About

Genes variants annotation tools using online services. Also does basic manipulations of HPO.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages