annotate cwpair2.py @ 7:076fae29bb39 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit ca66053a0d915edba3d7f1d4ce014718e7f4f0f2
author iuc
date Thu, 02 May 2019 08:29:54 -0400
parents 37ea888d7765
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
1 """
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
2 cwpair2.py
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
3
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
4 Takes a list of called peaks on both strands and produces a list of matched pairs and a list
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
5 of unmatched orphans using a specified method for finding matched pairs. Methods for finding
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
6 matched pairs are mode, closest, largest or all, where the analysis is run for each method
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
7
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
8 Input: list of one or more gff format files
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
9
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
10 Output: files produced for each input/mode combination:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
11 MP (matched_pair), D (details), O (orphans), P (frequency preview plot), F (frequency final plot),
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
12 C (statistics graph), statistics.tabular
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
13 """
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
14
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
15 import argparse
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
16 import csv
5
37ea888d7765 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents: 0
diff changeset
17
0
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
18 import cwpair2_util
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
19
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
20 if __name__ == '__main__':
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
21 parser = argparse.ArgumentParser()
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
22 parser.add_argument('--input', dest='inputs', action='append', nargs=2, help="Input datasets")
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
23 parser.add_argument('--method', dest='method', default='mode', help='Method of finding match.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
24 parser.add_argument('--up_distance', dest='up_distance', type=int, default=50, help='Distance upstream from a pair.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
25 parser.add_argument('--down_distance', dest='down_distance', type=int, default=100, help='Distance downstream of a pair.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
26 parser.add_argument('--binsize', dest='binsize', type=int, default=1, help='Width of bins for plots and mode.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
27 parser.add_argument('--threshold_format', dest='threshold_format', help='Percentage to filter the 95th percentile.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
28 parser.add_argument('--relative_threshold', dest='relative_threshold', type=float, default=0.0, help='Percentage to filter the 95th percentile.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
29 parser.add_argument('--absolute_threshold', dest='absolute_threshold', type=float, default=0.0, help='Absolute value to filter.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
30 parser.add_argument('--output_files', dest='output_files', default='matched_pair', help='Restrict output dataset collections.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
31 parser.add_argument('--statistics_output', dest='statistics_output', help='Statistics output file.')
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
32 args = parser.parse_args()
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
33
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
34 cwpair2_util.create_directories()
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
35
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
36 statistics = []
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
37 if args.absolute_threshold > 0:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
38 threshold = args.absolute_threshold
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
39 elif args.relative_threshold > 0:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
40 threshold = args.relative_threshold / 100.0
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
41 else:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
42 threshold = 0
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
43 for (dataset_path, hid) in args.inputs:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
44 stats = cwpair2_util.process_file(dataset_path,
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
45 hid,
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
46 args.method,
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
47 threshold,
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
48 args.up_distance,
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
49 args.down_distance,
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
50 args.binsize,
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
51 args.output_files)
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
52 statistics.extend(stats)
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
53 # Accumulate statistics.
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
54 by_file = {}
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
55 for stats in statistics:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
56 # Skip "None" statistics from failed files
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
57 if not stats:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
58 continue
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
59 path = stats['stats_path']
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
60 if path not in by_file:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
61 by_file[path] = []
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
62 by_file[path].append(stats)
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
63 # Write tabular statistics file.
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
64 keys = ['fname', 'final_mode', 'preview_mode', 'perc95', 'paired', 'orphans']
7
076fae29bb39 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit ca66053a0d915edba3d7f1d4ce014718e7f4f0f2
iuc
parents: 5
diff changeset
65 statistics_out = csv.writer(open(args.statistics_output, 'wt'), delimiter='\t', lineterminator="\n")
0
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
66 statistics_out.writerow(keys)
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
67 for file_path, statistics in by_file.items():
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
68 for stats in statistics:
afa47be0dc76 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cwpair2 commit e96df94dba60050fa28aaf55b5bb095717a5f260
iuc
parents:
diff changeset
69 statistics_out.writerow([stats[key] for key in keys])