annotate small_rna_map.py @ 8:2cc2948cfa34 draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
author artbio
date Sun, 23 Jul 2017 13:54:29 -0400
parents 35d3f8ac99cf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
1 import argparse
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
2 from collections import defaultdict
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
3
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
4 import numpy
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
5
0
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
6 import pysam
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
7
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
8
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
9 def Parser():
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
10 the_parser = argparse.ArgumentParser()
3
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
11 the_parser.add_argument('--input', dest='input', required=True,
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
12 nargs='+', help='input BAM files')
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
13 the_parser.add_argument('--sample_name', dest='sample_name',
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
14 required=True, nargs='+', help='sample name')
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
15 the_parser.add_argument('--output', action='store',
3
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
16 type=str, help='output tabular file')
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
17 the_parser.add_argument('-S', '--sizes', action='store',
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
18 help='use to output read sizes dataframe')
0
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
19 args = the_parser.parse_args()
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
20 return args
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
21
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
22
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
23 class Map:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
24
7
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
25 def __init__(self, bam_file, sample, computeSize=False):
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
26 self.sample_name = sample
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
27 self.bam_object = pysam.AlignmentFile(bam_file, 'rb')
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
28 self.chromosomes = dict(zip(self.bam_object.references,
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
29 self.bam_object.lengths))
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
30 self.map_dict = self.create_map(self.bam_object)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
31 self.max = self.compute_max(self.map_dict)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
32 self.mean = self.compute_mean(self.map_dict)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
33 self.median = self.compute_median(self.map_dict)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
34 self.coverage = self.compute_coverage(self.map_dict)
7
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
35 if computeSize:
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
36 self.size = self.compute_size(self.map_dict)
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
37
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
38 def create_map(self, bam_object):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
39 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
40 Returns a map_dictionary {(chromosome,read_position,polarity):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
41 [read_length, ...]}
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
42 '''
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
43 map_dictionary = defaultdict(list)
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
44 # get empty value for start and end of each chromosome
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
45 for chrom in self.chromosomes:
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
46 map_dictionary[(chrom, 1, 'F')] = []
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
47 map_dictionary[(chrom, self.chromosomes[chrom], 'F')] = []
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
48 for chrom in self.chromosomes:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
49 for read in bam_object.fetch(chrom):
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
50 positions = read.positions # a list of covered positions
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
51 for pos in positions:
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
52 if not map_dictionary[(chrom, pos+1, 'F')]:
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
53 map_dictionary[(chrom, pos+1, 'F')] = []
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
54 if not map_dictionary[(chrom, pos+1, 'R')]:
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
55 map_dictionary[(chrom, pos+1, 'R')] = []
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
56 if read.is_reverse:
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
57 map_dictionary[(chrom, positions[-1]+1,
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
58 'R')].append(read.query_alignment_length)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
59 else:
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
60 map_dictionary[(chrom, positions[0]+1,
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
61 'F')].append(read.query_alignment_length)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
62 return map_dictionary
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
63
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
64 def compute_max(self, map_dictionary):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
65 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
66 takes a map_dictionary as input and returns
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
67 a max_dictionary {(chromosome,read_position,polarity):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
68 max_of_number_of_read_at_any_position}
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
69 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
70 merge_keylist = [(i[0], 0) for i in map_dictionary.keys()]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
71 max_dictionary = dict(merge_keylist)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
72 for key in map_dictionary:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
73 if len(map_dictionary[key]) > max_dictionary[key[0]]:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
74 max_dictionary[key[0]] = len(map_dictionary[key])
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
75 return max_dictionary
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
76
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
77 def compute_mean(self, map_dictionary):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
78 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
79 takes a map_dictionary as input and returns
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
80 a mean_dictionary {(chromosome,read_position,polarity):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
81 mean_value_of_reads}
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
82 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
83 mean_dictionary = dict()
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
84 for key in map_dictionary:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
85 if len(map_dictionary[key]) == 0:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
86 mean_dictionary[key] = 0
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
87 else:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
88 mean_dictionary[key] = round(numpy.mean(map_dictionary[key]),
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
89 1)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
90 return mean_dictionary
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
91
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
92 def compute_median(self, map_dictionary):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
93 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
94 takes a map_dictionary as input and returns
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
95 a mean_dictionary {(chromosome,read_position,polarity):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
96 mean_value_of_reads}
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
97 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
98 median_dictionary = dict()
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
99 for key in map_dictionary:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
100 if len(map_dictionary[key]) == 0:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
101 median_dictionary[key] = 0
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
102 else:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
103 median_dictionary[key] = numpy.median(map_dictionary[key])
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
104 return median_dictionary
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
105
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
106 def compute_coverage(self, map_dictionary, quality=10):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
107 '''
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
108 takes a map_dictionary as input and returns
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
109 a coverage_dictionary {(chromosome,read_position,polarity):
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
110 coverage}
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
111 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
112 coverage_dictionary = dict()
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
113 for chrom in self.chromosomes:
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
114 coverage_dictionary[(chrom, 1, 'F')] = 0
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
115 coverage_dictionary[(chrom, self.chromosomes[chrom], 'F')] = 0
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
116
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
117 for key in map_dictionary:
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
118 coverage = self.bam_object.count_coverage(
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
119 reference=key[0],
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
120 start=key[1]-1,
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
121 end=key[1],
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
122 quality_threshold=quality)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
123 """ Add the 4 coverage values """
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
124 coverage = [sum(x) for x in zip(*coverage)]
8
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
125 coverage_dictionary[key] = coverage[0]
2cc2948cfa34 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b6c6b4d92a8d839e59f7ac28cb169d25ca68ef0d
artbio
parents: 7
diff changeset
126 # coverage_dictionary[(key[0], key[1], 'R')] = coverage
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
127 return coverage_dictionary
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
128
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
129 def compute_size(self, map_dictionary):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
130 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
131 Takes a map_dictionary and returns a dictionary of sizes:
7
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
132 {chrom: {polarity: {size: nbre of reads}}}
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
133 '''
6
f924a33e1eef planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 19a447cd21c746c852cf7434b5df423504baf383
artbio
parents: 5
diff changeset
134 size_dictionary = defaultdict(lambda: defaultdict(
f924a33e1eef planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 19a447cd21c746c852cf7434b5df423504baf383
artbio
parents: 5
diff changeset
135 lambda: defaultdict( int )))
7
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
136 # to track empty chromosomes
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
137 for chrom in self.chromosomes:
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
138 if self.bam_object.count(chrom) == 0:
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
139 size_dictionary[chrom]['F'][10] = 0
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
140 for key in map_dictionary:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
141 for size in map_dictionary[key]:
6
f924a33e1eef planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 19a447cd21c746c852cf7434b5df423504baf383
artbio
parents: 5
diff changeset
142 size_dictionary[key[0]][key[2]][size] += 1
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
143 return size_dictionary
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
144
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
145 def write_size_table(self, out):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
146 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
147 Dataset, Chromosome, Polarity, Size, Nbr_reads
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
148 out is an *open* file handler
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
149 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
150 for chrom in sorted(self.size):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
151 sizes = self.size[chrom]['F'].keys()
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
152 sizes.extend(self.size[chrom]['R'].keys())
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
153 for polarity in sorted(self.size[chrom]):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
154 for size in range(min(sizes), max(sizes)+1):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
155 try:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
156 line = [self.sample_name, chrom, polarity, size,
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
157 self.size[chrom][polarity][size]]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
158 except KeyError:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
159 line = [self.sample_name, chrom, polarity, size, 0]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
160 line = [str(i) for i in line]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
161 out.write('\t'.join(line) + '\n')
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
162
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
163 def write_table(self, out):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
164 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
165 Dataset, Chromosome, Chrom_length, Coordinate, Nbr_reads
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
166 Polarity, Max, Mean, Median, Coverage
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
167 out is an *open* file handler
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
168 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
169 for key in sorted(self.map_dict):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
170 line = [self.sample_name, key[0], self.chromosomes[key[0]],
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
171 key[1], len(self.map_dict[key]), key[2], self.max[key[0]],
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
172 self.mean[key], self.median[key], self.coverage[key]]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
173 line = [str(i) for i in line]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
174 out.write('\t'.join(line) + '\n')
0
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
175
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
176
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
177 def main(inputs, samples, file_out, size_file_out=''):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
178 F = open(file_out, 'w')
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
179 header = ["Dataset", "Chromosome", "Chrom_length", "Coordinate",
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
180 "Nbr_reads", "Polarity", "Max", "Mean", "Median", "Coverage"]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
181 F.write('\t'.join(header) + '\n')
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
182 if size_file_out:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
183 Fs = open(size_file_out, 'w')
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
184 header = ["Dataset", "Chromosome", "Polarity", "Size", "Nbr_reads"]
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
185 Fs.write('\t'.join(header) + '\n')
7
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
186 for file, sample in zip(inputs, samples):
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
187 mapobj = Map(file, sample, computeSize=True)
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
188 mapobj.write_table(F)
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
189 mapobj.write_size_table(Fs)
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
190 Fs.close()
7
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
191 else:
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
192 for file, sample in zip(inputs, samples):
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
193 mapobj = Map(file, sample, computeSize=False)
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
194 mapobj.write_table(F)
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
195 F.close()
0
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
196
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
197
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
198 if __name__ == "__main__":
3
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
199 args = Parser()
7
35d3f8ac99cf planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
artbio
parents: 6
diff changeset
200 # if identical sample names
3
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
201 if len(set(args.sample_name)) != len(args.sample_name):
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
202 args.sample_name = [name + '_' + str(i) for
2e0dc6032a98 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents: 0
diff changeset
203 i, name in enumerate(args.sample_name)]
5
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
204 main(args.input, args.sample_name, args.output, args.sizes)