annotate repmatch_gff3_util.py @ 2:d7f1312b3455 draft

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