Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update grep.py #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
help='If you want to know drug names target of which overlapped with your genes, set this flag.',
required=False)

# Try if TargetGene is not empty
def try_iloc(value, number):
try:
return value.TargetGene.iloc[number] + ':' + ','.join(value.Drug.unique())
except:
return np.nan

# fisher exact test function
def grep(target, key, annot, out_drug=False):
Expand All @@ -49,8 +55,8 @@ def grep(target, key, annot, out_drug=False):
if out_drug:
out_cols.append('TargetGene:DrugNames')
gene_druglist = target[target.TargetGene.isin(joined_genes)].groupby('TargetGene').apply(
lambda x: x.TargetGene.iloc[0] + ':' + ','.join(x.Drug.unique()))
drugnames = ";".join(gene_druglist)
lambda x: try_iloc(x, 0))
drugnames = ";".join(gene_druglist) if not gene_druglist.empty else np.nan
ret = [group, annot.Annot[group], oddsratio, pvalue, drugnames]
else:
ret = [group, annot.Annot[group], oddsratio, pvalue]
Expand Down