annotate small_rna_map.py @ 7:35d3f8ac99cf draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 975e2303944d19a4124210741e5a0d1feb546e45
author artbio
date Sun, 23 Jul 2017 05:21:58 -0400
parents f924a33e1eef
children 2cc2948cfa34
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 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
43 map_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
44 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
45 for pos in range(self.chromosomes[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
46 map_dictionary[(chrom, pos+1, 'F')] = [] # get all 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
47 map_dictionary[(chrom, pos+1, 'R')] = [] # get all 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
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):
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
50 read_positions = read.positions # a list of covered positions
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
51 if read.is_reverse:
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
52 map_dictionary[(chrom, read_positions[-1]+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
53 '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
54 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
55 map_dictionary[(chrom, read_positions[0]+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
56 '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
57 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
58
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 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
60 '''
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 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
62 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
63 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
64 '''
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 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
66 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
67 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
68 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
69 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
70 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
71
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 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
73 '''
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 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
75 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
76 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
77 '''
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 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
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86
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 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
88 '''
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 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
90 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
91 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
92 '''
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 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
94 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
95 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
96 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
97 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
98 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
99 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
100
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 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
102 '''
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 Takes a map_dictionary and returns a dictionary of lists
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 of coverage along the coordinates of pre_mirs (as 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
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 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
107 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
108 coverage = self.bam_object.count_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
109 reference=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
110 start=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
111 end=self.chromosomes[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
112 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
113 """ 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
114 coverage = [sum(x) for x in zip(*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
115 for pos, cov in enumerate(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
116 coverage_dictionary[(chrom, pos+1, "F")] = cov
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
117 coverage_dictionary[(chrom, pos+1, "R")] = cov
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 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
119
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
120 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
121 '''
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 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
123 {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
124 '''
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
125 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
126 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
127 # 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
136 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
137 '''
d65045e976e6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents: 3
diff changeset
138 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
139 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
140 '''
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 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153
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 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
155 '''
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 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
157 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
158 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
159 '''
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 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
161 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
162 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
163 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
164 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
165 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
166
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
167
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
168 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
169 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
170 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
171 "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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
188
1ad5d040f85f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff changeset
189 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
190 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
191 # 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
192 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
193 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
194 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
195 main(args.input, args.sample_name, args.output, args.sizes)