Skip to content

Commit

Permalink
segmetrics: Add 'ttest' option for 1-sample t-test p-value
Browse files Browse the repository at this point in the history
  • Loading branch information
etal committed Mar 31, 2019
1 parent 4fc6baa commit 4cea639
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
20 changes: 13 additions & 7 deletions cnvlib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def _cmd_call(args):

cnarr = read_cna(args.filename)
if args.center_at:
logging.info("Shifting log2 values by %f", -args.center_at)
logging.info("Shifting log2 ratios by %f", -args.center_at)
cnarr['log2'] -= args.center_at
elif args.center:
cnarr.center_all(args.center, skip_low=args.drop_low_coverage,
Expand Down Expand Up @@ -761,7 +761,7 @@ def csvstring(text):
help="""Re-center the log2 ratio values using this estimator of the
center or average value. ('median' if no argument given.)""")
P_call.add_argument("--center-at", type=float,
help="""Subtract a constant number from all log2 values. For "manual"
help="""Subtract a constant number from all log2 ratios. For "manual"
re-centering, in case the --center option gives unsatisfactory
results.)""")
P_call.add_argument('--filter', action='append', default=[], dest='filters',
Expand Down Expand Up @@ -1144,13 +1144,16 @@ def _cmd_genemetrics(args):
# Location statistics
P_genemetrics_stats.add_argument('--mean',
action='append_const', dest='location_stats', const='mean',
help="Mean log2 value (unweighted).")
help="Mean log2-ratio (unweighted).")
P_genemetrics_stats.add_argument('--median',
action='append_const', dest='location_stats', const='median',
help="Median.")
P_genemetrics_stats.add_argument('--mode',
action='append_const', dest='location_stats', const='mode',
help="Mode (i.e. peak density of log2 values).")
help="Mode (i.e. peak density of log2 ratios).")
P_genemetrics_stats.add_argument('--ttest',
action='append_const', dest='location_stats', const='ttest',
help="One-sample t-test of bin log2 ratios versus 0.0.")
# Dispersion statistics
P_genemetrics_stats.add_argument('--stdev',
action='append_const', dest='spread_stats', const='stdev',
Expand Down Expand Up @@ -1316,13 +1319,16 @@ def _cmd_segmetrics(args):
# Location statistics
P_segmetrics_stats.add_argument('--mean',
action='append_const', dest='location_stats', const='mean',
help="Mean log2 value (unweighted).")
help="Mean log2 ratio (unweighted).")
P_segmetrics_stats.add_argument('--median',
action='append_const', dest='location_stats', const='median',
help="Median.")
P_segmetrics_stats.add_argument('--mode',
action='append_const', dest='location_stats', const='mode',
help="Mode (i.e. peak density of log2 values).")
help="Mode (i.e. peak density of bin log2 ratios).")
P_segmetrics_stats.add_argument('--ttest',
action='append_const', dest='location_stats', const='ttest',
help="One-sample t-test of bin log2 ratios versus 0.0.")
# Dispersion statistics
P_segmetrics_stats.add_argument('--stdev',
action='append_const', dest='spread_stats', const='stdev',
Expand Down Expand Up @@ -1537,7 +1543,7 @@ def _cmd_import_rna(args):
expression. Output of cnv_expression_correlate.py.""")
P_import_rna.add_argument('--max-log2',
metavar="FLOAT", default=3.0, type=float,
help="""Maximum log2 value in output. Observed values above this limit
help="""Maximum log2 ratio in output. Observed values above this limit
will be replaced with this value. [Default: %(default)s]""")
P_import_rna.add_argument('-n', '--normal', nargs='+', default=[],
help="""Normal samples (same format as `gene_counts`) to be used as a
Expand Down
1 change: 1 addition & 0 deletions cnvlib/segmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def do_segmetrics(cnarr, segarr, location_stats=(), spread_stats=(),
'mean': np.mean,
'median': np.median,
'mode': descriptives.modal_location,
'ttest': lambda a: stats.ttest_1samp(a, 0.0, nan_policy='omit')[1],

'stdev': np.std,
'mad': descriptives.median_absolute_deviation,
Expand Down
4 changes: 2 additions & 2 deletions test/test_cnvlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ def test_segmetrics(self):
cnarr = cnvlib.read("formats/amplicon.cnr")
segarr = cnvlib.read("formats/amplicon.cns")
sm = segmetrics.do_segmetrics(cnarr, segarr,
location_stats=['mean', 'median'],
spread_stats=['stdev'],
location_stats=['mean', 'median', 'mode', 'ttest'],
spread_stats=['stdev', 'sem', 'iqr'],
interval_stats=['pi', 'ci'])
# Restrict to segments with enough supporting probes for sane stats
sm = sm[sm['probes'] > 3]
Expand Down

0 comments on commit 4cea639

Please sign in to comment.