Mercurial > repos > artbio > small_rna_map
annotate small_rna_map.py @ 6:f924a33e1eef draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 19a447cd21c746c852cf7434b5df423504baf383
author | artbio |
---|---|
date | Sun, 23 Jul 2017 03:43:40 -0400 |
parents | d65045e976e6 |
children | 35d3f8ac99cf |
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 |
d65045e976e6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents:
3
diff
changeset
|
25 def __init__(self, bam_file, 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
|
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) |
d65045e976e6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit b673d39fbe79f5164ba6489b33cfa78ac238ee09
artbio
parents:
3
diff
changeset
|
35 self.size = self.compute_size(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
|
36 |
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 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
|
38 ''' |
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 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
|
40 [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
|
41 ''' |
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 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 '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
|
53 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
|
54 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
|
55 '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
|
56 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
|
57 |
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 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
|
59 ''' |
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 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
|
61 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
|
62 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
|
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 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 |
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 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
|
72 ''' |
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 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
|
74 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
|
75 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
|
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 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 |
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 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
|
87 ''' |
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 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
|
89 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
|
90 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
|
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 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 |
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 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
|
101 ''' |
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 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
|
103 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
|
104 ''' |
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 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 """ 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 |
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 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
|
120 ''' |
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 Takes a map_dictionary and returns a dictionary of sizes: |
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 {chrom: {size: {polarity: nbre 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
|
123 ''' |
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
|
124 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
|
125 lambda: defaultdict( int ))) |
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
|
126 for key in map_dictionary: |
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
|
127 if len(map_dictionary) == 0: |
f924a33e1eef
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 19a447cd21c746c852cf7434b5df423504baf383
artbio
parents:
5
diff
changeset
|
128 # to track empty chromosomes |
f924a33e1eef
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 19a447cd21c746c852cf7434b5df423504baf383
artbio
parents:
5
diff
changeset
|
129 size_dictionary[key[0]][key[2]][size] = 0 |
f924a33e1eef
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 19a447cd21c746c852cf7434b5df423504baf383
artbio
parents:
5
diff
changeset
|
130 continue |
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 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
|
132 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
|
133 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
|
134 |
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 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
|
136 ''' |
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 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
|
138 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
|
139 ''' |
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 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 |
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 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
|
154 ''' |
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 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
|
156 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
|
157 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
|
158 ''' |
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 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 |
1ad5d040f85f
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff
changeset
|
166 |
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
|
167 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
|
168 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
|
169 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
|
170 "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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 Fs.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
|
176 for file, sample in zip(inputs, samples): |
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 mapobj = Map(file, 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
|
178 mapobj.write_table(F) |
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 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
|
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 F.close() |
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.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
|
184 |
1ad5d040f85f
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff
changeset
|
185 |
1ad5d040f85f
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit fa452d860cf550c7524df59e77b36fd39e3e2a45
artbio
parents:
diff
changeset
|
186 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
|
187 args = Parser() |
2e0dc6032a98
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents:
0
diff
changeset
|
188 # if identical sample names # to be tested |
2e0dc6032a98
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_map commit 93f212712d9846c7aaa389de60babb332d38363e
artbio
parents:
0
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 main(args.input, args.sample_name, args.output, args.sizes) |