annotate repmatch_gff3_util.py @ 7:79f505a25bb8 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit b50166c05f3484b0d0171cd668653efb54cf0545"
author iuc
date Mon, 16 Dec 2019 15:45:16 -0500
parents 2365720de36d
children
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')
5
2365720de36d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit cb490a0eee9efc2cd6c98d5bb714b75b5894c56c
iuc
parents: 4
diff changeset
10 from matplotlib import pyplot # noqa: I202,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'
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
26 ISPY2 = sys.version_info[0] == 2
0
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
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
29 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
30
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
31 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
32 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
33 self.dataset_path = dataset_path
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
34 if ISPY2:
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
35 fh = open(dataset_path, 'rb')
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
36 else:
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
37 fh = open(dataset_path, 'r', newline='')
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
38 self.parse(csv.reader(fh, delimiter='\t'))
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
39
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
40 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
41 self.chromosomes = {}
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
42 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
43 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
44 continue
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
45 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
46 attrs = parse_gff_attrs(attrs)
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
47 distance = int(attrs['cw_distance'])
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
48 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
49 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
50 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
51 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
52 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
53 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
54 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
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.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
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 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
59 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
60 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
61
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
62 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
63 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
64
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
65
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
66 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
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 __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
69 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
70 self.peaks = []
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
71
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
72 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
73 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
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 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
76 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
77 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
78
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
79 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
80 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
81 # 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
82 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
83 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
84 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
85
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
86 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
87 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
88 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
89
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
90
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
91 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
92
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
93 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
94 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
95 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
96 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
97 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
98 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
99
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
100 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
101 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
102
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
103
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
104 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
105
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
106 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
107 self.peaks = {}
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
108
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
109 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
110 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
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 chrom(self):
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
114 return list(self.peaks.values())[0].chrom
0
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 midpoint(self):
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
118 return int(median([peak.midpoint for peak in self.peaks.values()]))
0
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 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
122 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
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 median_distance(self):
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
126 return int(median([peak.distance for peak in self.peaks.values()]))
0
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 @property
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
129 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
130 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
131
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
132 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
133 values = []
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
134 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
135 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
136 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
137
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
138 @property
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
139 def peakpeak_distance(self):
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
140 keys = list(self.peaks.keys())
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
141 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
142
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
143
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
144 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
145
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
146 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
147 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
148
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
149 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
150 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
151
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
152 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
153 x = []
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
154 y = []
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
155 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
156 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
157 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
158 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
159
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
160 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
161 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
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 size(self):
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
164 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
165
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 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
168 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
169 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
170
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 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
173 """
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
174 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
175 """
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
176 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
177 return 0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
178 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
179 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
180 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
181 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
182 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
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 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
186 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
187
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
188
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
189 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
190 """
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
191 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
192 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
193 """
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
194 lower = list(target_peaks)[0].midpoint
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
195 upper = list(target_peaks)[0].midpoint
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
196 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
197 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
198 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
199 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
200 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
201 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
202
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
203
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
204 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
205 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
206 return None
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
207 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
208 return None
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
209 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
210
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
211
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
212 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
213 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
214 return None
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
215 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
216 return None
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
217 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
218
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
219
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
220 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
221 pyplot.clf()
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
222 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
223 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
224 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
225 # 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
236
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
237
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
238 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
239
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
240
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
241 def gff_attrs(l):
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
242 if len(l) == 0:
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
243 return '.'
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
244 return ';'.join('%s=%s' % (tup[0], tup[1]) for tup in l)
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
245
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
246
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
247 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
248 d = {}
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
249 if s == '.':
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 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
252 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
253 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
254 return d
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
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
257 def gff_row(cname, start, end, score, source, stype='.', strand='.', phase='.', attrs=None):
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
258 return (cname, source, stype, start, end, score, strand, phase, gff_attrs(attrs or []))
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
259
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
260
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
261 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
262 """
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
263 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
264 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
265 """
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
266 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
267 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
268 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
269 return name
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
270
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
271
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
272 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
273 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
274 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
275 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
276 return
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
277 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
278 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
279 else:
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
280 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
281 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
282 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
283 galaxy_hids,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
284 match_method,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
285 distance,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
286 step,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
287 replicates,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
288 up_limit,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
289 low_limit,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
290 output_files,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
291 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
292 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
293 output_detail,
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
294 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
295 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
296 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
297 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
298 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
299 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
300 METHODS.keys())
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
301 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
302
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
303
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
304 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
305 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
306 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
307 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
308 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
309 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
310 replicates = []
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
311 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
312 try:
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
313 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
314 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
326 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
327 # Returns a tab-delimited writer for a certain output
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
328 if ISPY2:
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
329 fh = open(file_path, 'wb')
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
330 return csv.writer(fh, delimiter='\t')
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
331 else:
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
332 fh = open(file_path, 'w', newline='')
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
333 return csv.writer(fh, delimiter='\t', quoting=csv.QUOTE_NONE)
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
334
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
335 labels = ('chrom',
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',
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
337 '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
338 '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
339 'replicates',
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
340 '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
341 'reads sum')
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
342 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
343 labels += ('chrom',
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
344 'median midpoint',
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
345 '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
346 '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
347 '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
348 'replicate id')
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358 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
359 # Perform filtering
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
360 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
361 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
362 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
363 # 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
364 peak_groups = []
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
365 unmatched_peaks = []
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
366 freq = FrequencyDistribution()
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
367
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
368 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
369 # 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
370 reps = reps[:]
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
371 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
372 # 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
373 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
374 reps.remove(main)
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
375 for chromosome in list(main.chromosomes.values()):
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
376 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
377 # 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
378 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
379
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
380 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
381 # 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
382 # +- 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
383 while True:
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
384 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
385 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
386 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
387 # 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
388 continue
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
389 try:
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
390 # Lines changed to remove a major bug by Rohit Reja.
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
391 window, chrum = get_window(replicate.chromosomes[chromosome.name], list(group.peaks.values()), distance)
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
392 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
393 except KeyError:
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
394 continue
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
395 if match:
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
396 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
397 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
398 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
399 break
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 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
401 for group in peak_groups:
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
402 old_peaks = list(group.peaks.values())
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
403 search_for_matches(group)
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
404 for peak in list(group.peaks.values()):
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
405 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
406 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
407 # 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
408 # 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
409 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
410 matches = PeakGroup()
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
411 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
412 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
413 # 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
414 if matches.num_replicates >= num_required:
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
415 for peak in list(matches.peaks.values()):
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
416 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
417 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
418 # 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
419 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
420 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
421 else:
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
422 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
423 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
424 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
425 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
426 # 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
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 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
429 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
430 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
431 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
432 # 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
433 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
434 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
435 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
436 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
437 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
438 # 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
439 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
440 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
441 end=group.midpoint + 1,
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
442 score=group.normalized_value(med),
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
443 source='repmatch',
4
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
444 stype='.',
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
445 strand='.',
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
446 phase='.',
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
447 attrs=[('median_distance', group.median_distance),
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
448 ('value_sum', group.value_sum),
6acaa2c93f47 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 315c3ddcdbf38a27d43753aae3b6d379306be5a9
iuc
parents: 1
diff changeset
449 ('replicates', group.num_replicates)]))
0
a072f0f30ea3 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff changeset
450 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
451 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
452 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
453 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
454 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
455 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
456 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
457 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
458 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
459 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
460 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
461 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
462 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
463 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
464 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
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472 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
473 return {'distribution': freq}