annotate repmatch_gff3_util.py @ 0:b26d50dd3226 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
author bgruening
date Wed, 23 Dec 2015 09:24:35 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
1 import bisect
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
2 import csv
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
3 import os
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
4 import shutil
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
5 import sys
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
6 import tempfile
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
7 import matplotlib
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
8 matplotlib.use('Agg')
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
9 from matplotlib import pyplot
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
10
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
11 # Graph settings
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
12 Y_LABEL = 'Counts'
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
13 X_LABEL = 'Number of matched replicates'
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
14 TICK_WIDTH = 3
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
15 # Amount to shift the graph to make labels fit, [left, right, top, bottom]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
16 ADJUST = [0.180, 0.9, 0.9, 0.1]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
17 # Length of tick marks, use TICK_WIDTH for width
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
18 pyplot.rc('xtick.major', size=10.00)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
19 pyplot.rc('ytick.major', size=10.00)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
20 pyplot.rc('lines', linewidth=4.00)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
21 pyplot.rc('axes', linewidth=3.00)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
22 pyplot.rc('font', family='Bitstream Vera Sans', size=32.0)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
23
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
24 COLORS = 'krb'
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
25
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
26
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
27 class Replicate(object):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
28
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
29 def __init__(self, id, dataset_path):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
30 self.id = id
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
31 self.dataset_path = dataset_path
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
32 self.parse(csv.reader(open(dataset_path, 'rt'), delimiter='\t'))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
33
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
34 def parse(self, reader):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
35 self.chromosomes = {}
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
36 for line in reader:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
37 if line[0].startswith("#") or line[0].startswith('"'):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
38 continue
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
39 cname, junk, junk, mid, midplus, value, strand, junk, attrs = line
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
40 attrs = parse_gff_attrs(attrs)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
41 distance = attrs['cw_distance']
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
42 mid = int(mid)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
43 midplus = int(midplus)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
44 value = float(value)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
45 distance = int(distance)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
46 if cname not in self.chromosomes:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
47 self.chromosomes[cname] = Chromosome(cname)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
48 chrom = self.chromosomes[cname]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
49 chrom.add_peak(Peak(cname, mid, value, distance, self))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
50 for chrom in self.chromosomes.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
51 chrom.sort_by_index()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
52
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
53 def filter(self, up_limit, low_limit):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
54 for chrom in self.chromosomes.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
55 chrom.filter(up_limit, low_limit)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
56
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
57 def size(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
58 return sum([len(c.peaks) for c in self.chromosomes.values()])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
59
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
60
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
61 class Chromosome(object):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
62
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
63 def __init__(self, name):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
64 self.name = name
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
65 self.peaks = []
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
66
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
67 def add_peak(self, peak):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
68 self.peaks.append(peak)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
69
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
70 def sort_by_index(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
71 self.peaks.sort(key=lambda peak: peak.midpoint)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
72 self.keys = make_keys(self.peaks)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
73
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
74 def remove_peak(self, peak):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
75 i = bisect.bisect_left(self.keys, peak.midpoint)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
76 # If the peak was actually found
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
77 if i < len(self.peaks) and self.peaks[i].midpoint == peak.midpoint:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
78 del self.keys[i]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
79 del self.peaks[i]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
80
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
81 def filter(self, up_limit, low_limit):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
82 self.peaks = [p for p in self.peaks if low_limit <= p.distance <= up_limit]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
83 self.keys = make_keys(self.peaks)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
84
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
85
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
86 class Peak(object):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
87
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
88 def __init__(self, chrom, midpoint, value, distance, replicate):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
89 self.chrom = chrom
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
90 self.value = value
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
91 self.midpoint = midpoint
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
92 self.distance = distance
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
93 self.replicate = replicate
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
94
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
95 def normalized_value(self, med):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
96 return self.value * med / self.replicate.median
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
97
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
98
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
99 class PeakGroup(object):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
100
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
101 def __init__(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
102 self.peaks = {}
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
103
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
104 def add_peak(self, repid, peak):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
105 self.peaks[repid] = peak
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
106
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
107 @property
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
108 def chrom(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
109 return self.peaks.values()[0].chrom
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
110
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
111 @property
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
112 def midpoint(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
113 return median([peak.midpoint for peak in self.peaks.values()])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
114
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
115 @property
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
116 def num_replicates(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
117 return len(self.peaks)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
118
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
119 @property
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
120 def median_distance(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
121 return median([peak.distance for peak in self.peaks.values()])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
122
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
123 @property
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
124 def value_sum(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
125 return sum([peak.value for peak in self.peaks.values()])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
126
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
127 def normalized_value(self, med):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
128 values = []
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
129 for peak in self.peaks.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
130 values.append(peak.normalized_value(med))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
131 return median(values)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
132
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
133 @property
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
134 def peakpeak_distance(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
135 keys = self.peaks.keys()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
136 return abs(self.peaks[keys[0]].midpoint - self.peaks[keys[1]].midpoint)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
137
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
138
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
139 class FrequencyDistribution(object):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
140
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
141 def __init__(self, d=None):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
142 self.dist = d or {}
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
143
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
144 def add(self, x):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
145 self.dist[x] = self.dist.get(x, 0) + 1
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
146
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
147 def graph_series(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
148 x = []
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
149 y = []
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
150 for key, val in self.dist.items():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
151 x.append(key)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
152 y.append(val)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
153 return x, y
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
154
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
155 def mode(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
156 return max(self.dist.items(), key=lambda data: data[1])[0]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
157
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
158 def size(self):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
159 return sum(self.dist.values())
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
160
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
161
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
162 def stop_err(msg):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
163 sys.stderr.write(msg)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
164 sys.exit(1)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
165
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
166
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
167 def median(data):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
168 """
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
169 Find the integer median of the data set.
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
170 """
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
171 if not data:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
172 return 0
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
173 sdata = sorted(data)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
174 if len(data) % 2 == 0:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
175 return (sdata[len(data)//2] + sdata[len(data)//2-1]) / 2
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
176 else:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
177 return sdata[len(data)//2]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
178
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
179
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
180 def make_keys(peaks):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
181 return [data.midpoint for data in peaks]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
182
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
183
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
184 def get_window(chromosome, target_peaks, distance):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
185 """
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
186 Returns a window of all peaks from a replicate within a certain distance of
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
187 a peak from another replicate.
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
188 """
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
189 lower = target_peaks[0].midpoint
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
190 upper = target_peaks[0].midpoint
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
191 for peak in target_peaks:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
192 lower = min(lower, peak.midpoint - distance)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
193 upper = max(upper, peak.midpoint + distance)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
194 start_index = bisect.bisect_left(chromosome.keys, lower)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
195 end_index = bisect.bisect_right(chromosome.keys, upper)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
196 return (chromosome.peaks[start_index: end_index], chromosome.name)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
197
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
198
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
199 def match_largest(window, peak, chrum):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
200 if not window:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
201 return None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
202 if peak.chrom != chrum:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
203 return None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
204 return max(window, key=lambda cpeak: cpeak.value)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
205
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
206
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
207 def match_closest(window, peak, chrum):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
208 if not window:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
209 return None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
210 if peak.chrom != chrum:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
211 return None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
212 return min(window, key=lambda match: abs(match.midpoint - peak.midpoint))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
213
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
214
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
215 def frequency_histogram(freqs, dataset_path, labels=[], title=''):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
216 pyplot.clf()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
217 pyplot.figure(figsize=(10, 10))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
218 for i, freq in enumerate(freqs):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
219 xvals, yvals = freq.graph_series()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
220 # Go from high to low
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
221 xvals.reverse()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
222 pyplot.bar([x-0.4 + 0.8/len(freqs)*i for x in xvals], yvals, width=0.8/len(freqs), color=COLORS[i])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
223 pyplot.xticks(range(min(xvals), max(xvals)+1), map(str, reversed(range(min(xvals), max(xvals)+1))))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
224 pyplot.xlabel(X_LABEL)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
225 pyplot.ylabel(Y_LABEL)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
226 pyplot.subplots_adjust(left=ADJUST[0], right=ADJUST[1], top=ADJUST[2], bottom=ADJUST[3])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
227 ax = pyplot.gca()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
228 for l in ax.get_xticklines() + ax.get_yticklines():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
229 l.set_markeredgewidth(TICK_WIDTH)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
230 pyplot.savefig(dataset_path)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
231
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
232
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
233 METHODS = {'closest': match_closest, 'largest': match_largest}
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
234
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
235
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
236 def gff_attrs(d):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
237 if not d:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
238 return '.'
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
239 return ';'.join('%s=%s' % item for item in d.items())
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
240
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
241
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
242 def parse_gff_attrs(s):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
243 d = {}
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
244 if s == '.':
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
245 return d
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
246 for item in s.split(';'):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
247 key, val = item.split('=')
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
248 d[key] = val
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
249 return d
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
250
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
251
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
252 def gff_row(cname, start, end, score, source, type='.', strand='.', phase='.', attrs={}):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
253 return (cname, source, type, start, end, score, strand, phase, gff_attrs(attrs))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
254
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
255
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
256 def get_temporary_plot_path():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
257 """
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
258 Return the path to a temporary file with a valid image format
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
259 file extension that can be used with bioformats.
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
260 """
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
261 tmp_dir = tempfile.mkdtemp(prefix='tmp-repmatch-')
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
262 fd, name = tempfile.mkstemp(suffix='.pdf', dir=tmp_dir)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
263 os.close(fd)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
264 return name
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
265
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
266
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
267 def process_files(dataset_paths, galaxy_hids, method, distance, step, replicates, up_limit, low_limit, output_files,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
268 output_matched_peaks, output_unmatched_peaks, output_detail, output_statistics_table, output_statistics_histogram):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
269 output_statistics_histogram_file = output_files in ["all"] and method in ["all"]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
270 if len(dataset_paths) < 2:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
271 return
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
272 if method == 'all':
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
273 match_methods = METHODS.keys()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
274 else:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
275 match_methods = [method]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
276 for match_method in match_methods:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
277 statistics = perform_process(dataset_paths,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
278 galaxy_hids,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
279 match_method,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
280 distance,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
281 step,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
282 replicates,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
283 up_limit,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
284 low_limit,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
285 output_files,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
286 output_matched_peaks,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
287 output_unmatched_peaks,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
288 output_detail,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
289 output_statistics_table,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
290 output_statistics_histogram)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
291 if output_statistics_histogram_file:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
292 tmp_statistics_histogram_path = get_temporary_plot_path()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
293 frequency_histogram([stat['distribution'] for stat in [statistics]],
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
294 tmp_statistics_histogram_path,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
295 METHODS.keys())
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
296 shutil.move(tmp_statistics_histogram_path, output_statistics_histogram)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
297
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
298
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
299 def perform_process(dataset_paths, galaxy_hids, method, distance, step, num_required, up_limit, low_limit, output_files,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
300 output_matched_peaks, output_unmatched_peaks, output_detail, output_statistics_table, output_statistics_histogram):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
301 output_detail_file = output_files in ["all"] and output_detail is not None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
302 output_statistics_table_file = output_files in ["all"] and output_statistics_table is not None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
303 output_unmatched_peaks_file = output_files in ["all", "matched_peaks_unmatched_peaks"] and output_unmatched_peaks is not None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
304 output_statistics_histogram_file = output_files in ["all"] and output_statistics_histogram is not None
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
305 replicates = []
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
306 for i, dataset_path in enumerate(dataset_paths):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
307 try:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
308 galaxy_hid = galaxy_hids[i]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
309 r = Replicate(galaxy_hid, dataset_path)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
310 replicates.append(r)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
311 except Exception, e:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
312 stop_err('Unable to parse file "%s", exception: %s' % (dataset_path, str(e)))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
313 attrs = 'd%sr%s' % (distance, num_required)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
314 if up_limit != 1000:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
315 attrs += 'u%d' % up_limit
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
316 if low_limit != -1000:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
317 attrs += 'l%d' % low_limit
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
318 if step != 0:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
319 attrs += 's%d' % step
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
320
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
321 def td_writer(file_path):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
322 # Returns a tab-delimited writer for a certain output
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
323 return csv.writer(open(file_path, 'wt'), delimiter='\t')
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
324
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
325 labels = ('chrom',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
326 'median midpoint',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
327 'median midpoint+1',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
328 'median normalized reads',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
329 'replicates',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
330 'median c-w distance',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
331 'reads sum')
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
332 for replicate in replicates:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
333 labels += ('chrom',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
334 'median midpoint',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
335 'median midpoint+1',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
336 'c-w sum',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
337 'c-w distance',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
338 'replicate id')
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
339 matched_peaks_output = td_writer(output_matched_peaks)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
340 if output_statistics_table_file:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
341 statistics_table_output = td_writer(output_statistics_table)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
342 statistics_table_output.writerow(('data', 'median read count'))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
343 if output_detail_file:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
344 detail_output = td_writer(output_detail)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
345 detail_output.writerow(labels)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
346 if output_unmatched_peaks_file:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
347 unmatched_peaks_output = td_writer(output_unmatched_peaks)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
348 unmatched_peaks_output.writerow(('chrom', 'midpoint', 'midpoint+1', 'c-w sum', 'c-w distance', 'replicate id'))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
349 # Perform filtering
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
350 if up_limit < 1000 or low_limit > -1000:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
351 for replicate in replicates:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
352 replicate.filter(up_limit, low_limit)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
353 # Actually merge the peaks
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
354 peak_groups = []
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
355 unmatched_peaks = []
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
356 freq = FrequencyDistribution()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
357
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
358 def do_match(reps, distance):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
359 # Copy list because we will mutate it, but keep replicate references.
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
360 reps = reps[:]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
361 while len(reps) > 1:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
362 # Iterate over each replicate as "main"
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
363 main = reps[0]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
364 reps.remove(main)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
365 for chromosome in main.chromosomes.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
366 peaks_by_value = chromosome.peaks[:]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
367 # Sort main replicate by value
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
368 peaks_by_value.sort(key=lambda peak: -peak.value)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
369
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
370 def search_for_matches(group):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
371 # Here we use multiple passes, expanding the window to be
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
372 # +- distance from any previously matched peak.
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
373 while True:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
374 new_match = False
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
375 for replicate in reps:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
376 if replicate.id in group.peaks:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
377 # Stop if match already found for this replicate
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
378 continue
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
379 try:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
380 # Lines changed to remove a major bug by Rohit Reja.
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
381 window, chrum = get_window(replicate.chromosomes[chromosome.name],
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
382 group.peaks.values(),
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
383 distance)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
384 match = METHODS[method](window, peak, chrum)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
385 except KeyError:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
386 continue
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
387 if match:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
388 group.add_peak(replicate.id, match)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
389 new_match = True
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
390 if not new_match:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
391 break
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
392 # Attempt to enlarge existing peak groups
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
393 for group in peak_groups:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
394 old_peaks = group.peaks.values()[:]
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
395 search_for_matches(group)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
396 for peak in group.peaks.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
397 if peak not in old_peaks:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
398 peak.replicate.chromosomes[chromosome.name].remove_peak(peak)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
399 # Attempt to find new peaks groups. For each peak in the
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
400 # main replicate, search for matches in the other replicates
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
401 for peak in peaks_by_value:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
402 matches = PeakGroup()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
403 matches.add_peak(main.id, peak)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
404 search_for_matches(matches)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
405 # Were enough replicates matched?
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
406 if matches.num_replicates >= num_required:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
407 for peak in matches.peaks.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
408 peak.replicate.chromosomes[chromosome.name].remove_peak(peak)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
409 peak_groups.append(matches)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
410 # Zero or less = no stepping
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
411 if step <= 0:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
412 do_match(replicates, distance)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
413 else:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
414 for d in range(0, distance, step):
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
415 do_match(replicates, d)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
416 for group in peak_groups:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
417 freq.add(group.num_replicates)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
418 # Collect together the remaining unmatched_peaks
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
419 for replicate in replicates:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
420 for chromosome in replicate.chromosomes.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
421 for peak in chromosome.peaks:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
422 freq.add(1)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
423 unmatched_peaks.append(peak)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
424 # Average the unmatched_peaks count in the graph by # replicates
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
425 med = median([peak.value for group in peak_groups for peak in group.peaks.values()])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
426 for replicate in replicates:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
427 replicate.median = median([peak.value for group in peak_groups for peak in group.peaks.values() if peak.replicate == replicate])
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
428 statistics_table_output.writerow((replicate.id, replicate.median))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
429 for group in peak_groups:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
430 # Output matched_peaks (matched pairs).
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
431 matched_peaks_output.writerow(gff_row(cname=group.chrom,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
432 start=group.midpoint,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
433 end=group.midpoint+1,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
434 source='repmatch',
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
435 score=group.normalized_value(med),
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
436 attrs={'median_distance': group.median_distance,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
437 'replicates': group.num_replicates,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
438 'value_sum': group.value_sum}))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
439 if output_detail_file:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
440 matched_peaks = (group.chrom,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
441 group.midpoint,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
442 group.midpoint+1,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
443 group.normalized_value(med),
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
444 group.num_replicates,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
445 group.median_distance,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
446 group.value_sum)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
447 for peak in group.peaks.values():
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
448 matched_peaks += (peak.chrom, peak.midpoint, peak.midpoint+1, peak.value, peak.distance, peak.replicate.id)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
449 detail_output.writerow(matched_peaks)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
450 if output_unmatched_peaks_file:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
451 for unmatched_peak in unmatched_peaks:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
452 unmatched_peaks_output.writerow((unmatched_peak.chrom,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
453 unmatched_peak.midpoint,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
454 unmatched_peak.midpoint+1,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
455 unmatched_peak.value,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
456 unmatched_peak.distance,
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
457 unmatched_peak.replicate.id))
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
458 if output_statistics_histogram_file:
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
459 tmp_statistics_histogram_path = get_temporary_plot_path()
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
460 frequency_histogram([freq], tmp_statistics_histogram_path)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
461 shutil.move(tmp_statistics_histogram_path, output_statistics_histogram)
b26d50dd3226 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
bgruening
parents:
diff changeset
462 return {'distribution': freq}