def test_mantel(self): """mantel should be significant for same matrix, not for random""" a = reshape(arange(25), (5,5)) b = a.copy() b[-1,-1] = 26 #slight change m = mantel(a, b, 1000) #closely related -- should be significant assert m < 0.05 c = reshape(ones(25), (5,5)) c[-1,-1] = 3 #not related -- should not be significant m = mantel(a,c,1000) assert m > 0.3, m
def test_mantel(self): """mantel should be significant for same matrix, not for random""" a = reshape(arange(25), (5, 5)) b = a.copy() b[-1, -1] = 26 #slight change m = mantel(a, b, 1000) #closely related -- should be significant assert m < 0.05 c = reshape(ones(25), (5, 5)) c[-1, -1] = 3 #not related -- should not be significant m = mantel(a, c, 1000) assert m > 0.3, m
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) sample_id_map_fp = opts.sample_id_map_fp if sample_id_map_fp: sample_id_map = dict([(k,v[0]) \ for k,v in fields_to_dict(open(sample_id_map_fp, "U")).items()]) else: sample_id_map = None input_dm_fps = opts.input_dms.split(',') output_f = open(opts.output_fp,'w') output_f.write(comment) output_f.write('DM1\tDM2\tNumber of entries\tMantel p-value\n') num_iterations = opts.num_iterations for i,fp1 in enumerate(input_dm_fps): for fp2 in input_dm_fps[i+1:]: (dm1_labels, dm1), (dm2_labels, dm2) =\ make_compatible_distance_matrices(parse_distmat(open(fp1,'U')), parse_distmat(open(fp2,'U')), lookup=sample_id_map) if len(dm1_labels) < 2: output_f.write('%s\t%s\t%d\tToo few samples\n' % (fp1,fp2,len(dm1_labels))) continue p = mantel(dm1,dm2,n=num_iterations) p_str = format_p_value_for_num_iters(p,num_iterations) output_f.write('%s\t%s\t%d\t%s\n' % (fp1,fp2,len(dm1_labels),p_str)) output_f.close()