Mercurial > repos > iuc > repmatch_gff3
annotate repmatch_gff3_util.py @ 0:a072f0f30ea3 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
author | iuc |
---|---|
date | Wed, 23 Dec 2015 09:25:42 -0500 |
parents | |
children | e5c7fffdc078 |
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 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
7 import matplotlib |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
8 matplotlib.use('Agg') |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
9 from matplotlib import pyplot |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
10 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
11 # Graph settings |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 # 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
|
16 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
|
17 # 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
24 COLORS = 'krb' |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
25 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
26 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
27 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
|
28 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
29 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
|
30 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
|
31 self.dataset_path = dataset_path |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
32 self.parse(csv.reader(open(dataset_path, 'rt'), delimiter='\t')) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
33 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
34 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
|
35 self.chromosomes = {} |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
36 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
|
37 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
|
38 continue |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
39 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
|
40 attrs = parse_gff_attrs(attrs) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
41 distance = attrs['cw_distance'] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 distance = int(distance) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
57 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
|
58 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
|
59 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
60 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
61 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
|
62 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
63 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
|
64 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
|
65 self.peaks = [] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
66 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
67 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
|
68 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
|
69 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
74 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
|
75 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
|
76 # 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
|
77 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
|
78 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
|
79 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
|
80 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 |
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 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
|
87 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
95 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
|
96 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
|
97 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
98 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
99 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
|
100 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
101 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
|
102 self.peaks = {} |
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 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
|
105 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
|
106 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
107 @property |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
108 def chrom(self): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
109 return self.peaks.values()[0].chrom |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
110 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
111 @property |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
112 def midpoint(self): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
113 return median([peak.midpoint for peak in self.peaks.values()]) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
114 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
115 @property |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
116 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
|
117 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
|
118 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
119 @property |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
120 def median_distance(self): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
121 return median([peak.distance for peak in self.peaks.values()]) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
122 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
123 @property |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
124 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
|
125 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
|
126 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
127 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
|
128 values = [] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
133 @property |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
134 def peakpeak_distance(self): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
135 keys = self.peaks.keys() |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
136 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
|
137 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
138 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
139 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
|
140 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
141 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
|
142 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
|
143 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
144 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
|
145 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
|
146 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
147 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
|
148 x = [] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
149 y = [] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
155 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
|
156 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
|
157 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
158 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
|
159 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
|
160 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
161 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
162 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
|
163 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
|
164 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
|
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 median(data): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
168 """ |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
169 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
|
170 """ |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
171 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
|
172 return 0 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
173 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
|
174 if 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
|
175 return (sdata[len(data)//2] + sdata[len(data)//2-1]) / 2 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
176 else: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
177 return sdata[len(data)//2] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
178 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
179 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
180 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
|
181 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
|
182 |
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 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
|
185 """ |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
186 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
|
187 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
|
188 """ |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
189 lower = target_peaks[0].midpoint |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
190 upper = target_peaks[0].midpoint |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
198 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
199 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
|
200 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
|
201 return None |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
202 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
|
203 return None |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
204 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
|
205 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
206 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
207 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
|
208 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
|
209 return None |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
210 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
|
211 return None |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
212 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
|
213 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
214 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
215 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
|
216 pyplot.clf() |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 # 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
|
221 xvals.reverse() |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
222 pyplot.bar([x-0.4 + 0.8/len(freqs)*i for x in xvals], yvals, width=0.8/len(freqs), color=COLORS[i]) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
223 pyplot.xticks(range(min(xvals), max(xvals)+1), map(str, reversed(range(min(xvals), max(xvals)+1)))) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
232 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
233 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
|
234 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
235 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
236 def gff_attrs(d): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
237 if not d: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
238 return '.' |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
239 return ';'.join('%s=%s' % item for item in d.items()) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
240 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
241 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
242 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
|
243 d = {} |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
244 if s == '.': |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
245 return d |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
246 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
|
247 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
|
248 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
|
249 return d |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
250 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
251 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
252 def gff_row(cname, start, end, score, source, type='.', strand='.', phase='.', attrs={}): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
253 return (cname, source, type, start, end, score, strand, phase, gff_attrs(attrs)) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
254 |
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 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
|
257 """ |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
258 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
|
259 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
|
260 """ |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
261 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
|
262 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
|
263 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
|
264 return name |
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 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 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
|
271 return |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
272 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
|
273 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
|
274 else: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 galaxy_hids, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
279 match_method, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
280 distance, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
281 step, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
282 replicates, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
283 up_limit, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
284 low_limit, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
285 output_files, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
286 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
|
287 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
|
288 output_detail, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 METHODS.keys()) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
296 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
|
297 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
298 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 replicates = [] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
306 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
|
307 try: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
308 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
|
309 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
|
310 replicates.append(r) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
311 except Exception, e: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
321 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
|
322 # Returns a tab-delimited writer for a certain output |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
323 return csv.writer(open(file_path, 'wt'), delimiter='\t') |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
324 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
325 labels = ('chrom', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
326 'median midpoint', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
327 'median midpoint+1', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
328 '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
|
329 'replicates', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
330 '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
|
331 'reads sum') |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
332 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
|
333 labels += ('chrom', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
334 'median midpoint', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
335 'median midpoint+1', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
336 '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
|
337 '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
|
338 'replicate id') |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 # Perform filtering |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 # 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
|
354 peak_groups = [] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
355 unmatched_peaks = [] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
356 freq = FrequencyDistribution() |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
357 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
358 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
|
359 # 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
|
360 reps = reps[:] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
361 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
|
362 # 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
|
363 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
|
364 reps.remove(main) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
365 for chromosome in main.chromosomes.values(): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
366 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
|
367 # 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
|
368 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
|
369 |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
370 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
|
371 # 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
|
372 # +- 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
|
373 while True: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
374 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
|
375 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
|
376 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
|
377 # 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
|
378 continue |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
379 try: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
380 # Lines changed to remove a major bug by Rohit Reja. |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
381 window, chrum = get_window(replicate.chromosomes[chromosome.name], |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
382 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
|
383 distance) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
384 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
|
385 except KeyError: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
386 continue |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
387 if match: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 break |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
392 # 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
|
393 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
|
394 old_peaks = group.peaks.values()[:] |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 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
|
399 # 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
|
400 # 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
|
401 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
|
402 matches = PeakGroup() |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
403 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
|
404 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
|
405 # 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
|
406 if matches.num_replicates >= num_required: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
407 for peak in matches.peaks.values(): |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
408 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
|
409 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
|
410 # 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
|
411 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
|
412 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
|
413 else: |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
414 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
|
415 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
|
416 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
|
417 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
|
418 # 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 # 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 # 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
|
431 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
|
432 start=group.midpoint, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
433 end=group.midpoint+1, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
434 source='repmatch', |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
435 score=group.normalized_value(med), |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
436 attrs={'median_distance': group.median_distance, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
437 'replicates': group.num_replicates, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
438 'value_sum': group.value_sum})) |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
439 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
|
440 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
|
441 group.midpoint, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
442 group.midpoint+1, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 matched_peaks += (peak.chrom, peak.midpoint, peak.midpoint+1, peak.value, peak.distance, 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 unmatched_peak.midpoint, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
454 unmatched_peak.midpoint+1, |
a072f0f30ea3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/repmatch_gff3 commit 0e04a4c237677c1f5be1950babcf8591097996a9
iuc
parents:
diff
changeset
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 return {'distribution': freq} |