Mercurial > repos > artbio > small_rna_maps
annotate small_rna_maps.py @ 15:82fedc576024 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
author | artbio |
---|---|
date | Sat, 06 Oct 2018 05:24:15 -0400 |
parents | 3ea75c573429 |
children | 600e2498bd21 |
rev | line source |
---|---|
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
1 import argparse |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
2 from collections import defaultdict |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
3 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
4 import numpy |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
5 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
6 import pysam |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
7 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
8 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
9 def Parser(): |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
10 the_parser = argparse.ArgumentParser() |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
11 the_parser.add_argument('--inputs', dest='inputs', required=True, |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
12 nargs='+', help='list of input BAM files') |
8
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
13 the_parser.add_argument('--minsize', dest='minsize', type=int, |
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
14 default=0, help='minimal size of reads') |
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
15 the_parser.add_argument('--maxsize', dest='maxsize', type=int, |
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
16 default=10000, help='maximal size of reads') |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
17 the_parser.add_argument('--cluster', dest='cluster', type=int, |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
18 default=0, help='clustering distance') |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
19 the_parser.add_argument('--sample_names', dest='sample_names', |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
20 required=True, nargs='+', |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
21 help='list of sample names') |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
22 the_parser.add_argument('--outputs', nargs='+', action='store', |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
23 help='list of two output paths (only two)') |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
24 the_parser.add_argument('-M', '--plot_methods', nargs='+', action='store', |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
25 help='list of 2 plot methods (only two) among:\ |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
26 Counts, Max, Mean, Median, Coverage and Size') |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
27 args = the_parser.parse_args() |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
28 return args |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
29 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
30 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
31 class Map: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
32 |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
33 def __init__(self, bam_file, sample, minsize, maxsize, cluster): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
34 self.sample_name = sample |
8
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
35 self.minsize = minsize |
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
36 self.maxsize = maxsize |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
37 self.cluster = cluster |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
38 self.bam_object = pysam.AlignmentFile(bam_file, 'rb') |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
39 self.chromosomes = dict(zip(self.bam_object.references, |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
40 self.bam_object.lengths)) |
8
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
41 self.map_dict = self.create_map(self.bam_object, self.minsize, |
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
42 self.maxsize) |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
43 if self.cluster: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
44 self.map_dict = self.tile_map(self.map_dict, self.cluster) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
45 |
8
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
46 def create_map(self, bam_object, minsize, maxsize): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
47 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
48 Returns a map_dictionary {(chromosome,read_position,polarity): |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
49 [read_length, ...]} |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
50 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
51 map_dictionary = defaultdict(list) |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
52 for chrom in self.chromosomes: |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
53 # get empty value for start and end of each chromosome |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
54 map_dictionary[(chrom, 1, 'F')] = [] |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
55 map_dictionary[(chrom, self.chromosomes[chrom], 'F')] = [] |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
56 for read in bam_object.fetch(chrom): |
15
82fedc576024
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
artbio
parents:
9
diff
changeset
|
57 positions = read.positions # a list of covered positions |
82fedc576024
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
artbio
parents:
9
diff
changeset
|
58 if read.is_reverse: |
82fedc576024
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
artbio
parents:
9
diff
changeset
|
59 map_dictionary[(chrom, positions[-1]+1, 'R')].append( |
82fedc576024
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
artbio
parents:
9
diff
changeset
|
60 read.query_alignment_length) |
82fedc576024
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
artbio
parents:
9
diff
changeset
|
61 else: |
82fedc576024
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
artbio
parents:
9
diff
changeset
|
62 map_dictionary[(chrom, positions[0]+1, 'F')].append( |
82fedc576024
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c1d96f7f028512aa4d8fcae3dd5f967cd445708e
artbio
parents:
9
diff
changeset
|
63 read.query_alignment_length) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
64 return map_dictionary |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
65 |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
66 def grouper(self, iterable, clust_distance): |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
67 prev = None |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
68 group = [] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
69 for item in iterable: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
70 if not prev or item - prev <= clust_distance: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
71 group.append(item) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
72 else: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
73 yield group |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
74 group = [item] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
75 prev = item |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
76 if group: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
77 yield group |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
78 |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
79 def tile_map(self, map_dic, clust_distance): |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
80 ''' |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
81 takes a map_dictionary {(chromosome,read_position,polarity): |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
82 [read_length, ...]} |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
83 and retur a map_dictionary with same structure but with |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
84 read positions aggregated by size |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
85 ''' |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
86 clustered_dic = defaultdict(list) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
87 for chrom in self.chromosomes: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
88 clustered_dic[(chrom, 1, 'F')] = [] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
89 clustered_dic[(chrom, self.chromosomes[chrom], 'F')] = [] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
90 F_chrom_coord = [] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
91 R_chrom_coord = [] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
92 for key in map_dic: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
93 if key[0] == chrom and key[2] == 'F': |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
94 F_chrom_coord.append(key[1]) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
95 elif key[0] == chrom and key[2] == 'R': |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
96 R_chrom_coord.append(key[1]) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
97 F_chrom_coord = list(set(F_chrom_coord)) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
98 R_chrom_coord = list(set(R_chrom_coord)) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
99 F_chrom_coord.sort() |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
100 R_chrom_coord.sort() |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
101 F_clust_values = [i for i in self.grouper(F_chrom_coord, |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
102 clust_distance)] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
103 F_clust_keys = [(i[-1]+i[0])/2 for i in F_clust_values] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
104 R_clust_values = [i for i in self.grouper(R_chrom_coord, |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
105 clust_distance)] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
106 R_clust_keys = [(i[-1]+i[0])/2 for i in R_clust_values] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
107 F_clust_dic = dict(zip(F_clust_keys, F_clust_values)) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
108 R_clust_dic = dict(zip(R_clust_keys, R_clust_values)) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
109 # {centered_coordinate: [coord1, coord2, coord3, ..]} |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
110 for centcoor in F_clust_dic: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
111 accumulator = [] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
112 for coor in F_clust_dic[centcoor]: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
113 accumulator.extend(map_dic[(chrom, coor, 'F')]) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
114 clustered_dic[(chrom, centcoor, 'F')] = accumulator |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
115 for centcoor in R_clust_dic: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
116 accumulator = [] |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
117 for coor in R_clust_dic[centcoor]: |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
118 accumulator.extend(map_dic[(chrom, coor, 'R')]) |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
119 clustered_dic[(chrom, centcoor, 'R')] = accumulator |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
120 return clustered_dic |
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
121 |
3
ed8b0142538d
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 7b2ceb05489c27ddb769c38fdec56274108a6fa1
artbio
parents:
2
diff
changeset
|
122 def compute_readcount(self, map_dictionary, out): |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
123 ''' |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
124 takes a map_dictionary as input and writes |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
125 a readmap_dictionary {(chromosome,read_position,polarity): |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
126 number_of_reads} |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
127 in an open file handler out |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
128 ''' |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
129 readmap_dictionary = dict() |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
130 for key in map_dictionary: |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
131 readmap_dictionary[key] = len(map_dictionary[key]) |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
132 self.write_table(readmap_dictionary, out) |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
133 |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
134 def compute_max(self, map_dictionary, out): |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
135 ''' |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
136 takes a map_dictionary as input and writes |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
137 a max_dictionary {(chromosome,read_position,polarity): |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
138 max_of_number_of_read_at_any_position} |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
139 Not clear this function is still required |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
140 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
141 merge_keylist = [(i[0], 0) for i in map_dictionary.keys()] |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
142 max_dictionary = dict(merge_keylist) |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
143 for key in map_dictionary: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
144 if len(map_dictionary[key]) > max_dictionary[key[0]]: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
145 max_dictionary[key[0]] = len(map_dictionary[key]) |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
146 self.write_table(max_dictionary, out) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
147 |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
148 def compute_mean(self, map_dictionary, out): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
149 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
150 takes a map_dictionary as input and returns |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
151 a mean_dictionary {(chromosome,read_position,polarity): |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
152 mean_value_of_reads} |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
153 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
154 mean_dictionary = dict() |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
155 for key in map_dictionary: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
156 if len(map_dictionary[key]) == 0: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
157 mean_dictionary[key] = 0 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
158 else: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
159 mean_dictionary[key] = round(numpy.mean(map_dictionary[key]), |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
160 1) |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
161 self.write_table(mean_dictionary, out) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
162 |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
163 def compute_median(self, map_dictionary, out): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
164 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
165 takes a map_dictionary as input and returns |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
166 a mean_dictionary {(chromosome,read_position,polarity): |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
167 mean_value_of_reads} |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
168 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
169 median_dictionary = dict() |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
170 for key in map_dictionary: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
171 if len(map_dictionary[key]) == 0: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
172 median_dictionary[key] = 0 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
173 else: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
174 median_dictionary[key] = numpy.median(map_dictionary[key]) |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
175 self.write_table(median_dictionary, out) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
176 |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
177 def compute_coverage(self, map_dictionary, out, quality=10): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
178 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
179 takes a map_dictionary as input and returns |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
180 a coverage_dictionary {(chromosome,read_position,polarity): |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
181 coverage} |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
182 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
183 coverage_dictionary = dict() |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
184 for chrom in self.chromosomes: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
185 coverage_dictionary[(chrom, 1, 'F')] = 0 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
186 coverage_dictionary[(chrom, self.chromosomes[chrom], 'F')] = 0 |
4
a6b9a081064b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b58cb36616bf351278e57ec1949e9ebf3c3cdff1
artbio
parents:
3
diff
changeset
|
187 for read in self.bam_object.fetch(chrom): |
a6b9a081064b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b58cb36616bf351278e57ec1949e9ebf3c3cdff1
artbio
parents:
3
diff
changeset
|
188 positions = read.positions # a list of covered positions |
a6b9a081064b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b58cb36616bf351278e57ec1949e9ebf3c3cdff1
artbio
parents:
3
diff
changeset
|
189 for pos in positions: |
a6b9a081064b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b58cb36616bf351278e57ec1949e9ebf3c3cdff1
artbio
parents:
3
diff
changeset
|
190 if not map_dictionary[(chrom, pos+1, 'F')]: |
a6b9a081064b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b58cb36616bf351278e57ec1949e9ebf3c3cdff1
artbio
parents:
3
diff
changeset
|
191 map_dictionary[(chrom, pos+1, 'F')] = [] |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
192 for key in map_dictionary: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
193 coverage = self.bam_object.count_coverage( |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
194 reference=key[0], |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
195 start=key[1]-1, |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
196 end=key[1], |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
197 quality_threshold=quality) |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
198 """ Add the 4 coverage values """ |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
199 coverage = [sum(x) for x in zip(*coverage)] |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
200 coverage_dictionary[key] = coverage[0] |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
201 self.write_table(coverage_dictionary, out) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
202 |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
203 def compute_size(self, map_dictionary, out): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
204 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
205 Takes a map_dictionary and returns a dictionary of sizes: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
206 {chrom: {polarity: {size: nbre of reads}}} |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
207 ''' |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
208 size_dictionary = defaultdict(lambda: defaultdict( |
1
40972a8dfab9
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit ad60e6655aabe30246043d95f14646b2527c9255
artbio
parents:
0
diff
changeset
|
209 lambda: defaultdict(int))) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
210 # to track empty chromosomes |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
211 for chrom in self.chromosomes: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
212 if self.bam_object.count(chrom) == 0: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
213 size_dictionary[chrom]['F'][10] = 0 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
214 for key in map_dictionary: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
215 for size in map_dictionary[key]: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
216 size_dictionary[key[0]][key[2]][size] += 1 |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
217 self.write_size_table(size_dictionary, out) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
218 |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
219 def write_table(self, mapdict, out): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
220 ''' |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
221 Generic writer |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
222 Dataset, Chromosome, Chrom_length, Coordinate, Polarity, |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
223 <some mapped value> |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
224 out is an *open* file handler |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
225 ''' |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
226 for key in sorted(mapdict): |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
227 line = [self.sample_name, key[0], self.chromosomes[key[0]], |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
228 key[1], key[2], mapdict[key]] |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
229 line = [str(i) for i in line] |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
230 out.write('\t'.join(line) + '\n') |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
231 |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
232 def write_size_table(self, sizedic, out): |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
233 ''' |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
234 Generic writer of summary values |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
235 Dataset, Chromosome, Chrom_length, <some category>, <some value> |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
236 out is an *open* file handler |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
237 ''' |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
238 for chrom in sorted(sizedic): |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
239 sizes = sizedic[chrom]['F'].keys() |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
240 sizes.extend(sizedic[chrom]['R'].keys()) |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
241 for polarity in sorted(sizedic[chrom]): |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
242 for size in range(min(sizes), max(sizes)+1): |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
243 try: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
244 line = [self.sample_name, chrom, polarity, size, |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
245 sizedic[chrom][polarity][size]] |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
246 except KeyError: |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
247 line = [self.sample_name, chrom, polarity, size, 0] |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
248 line = [str(i) for i in line] |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
249 out.write('\t'.join(line) + '\n') |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
250 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
251 |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
252 def main(inputs, samples, methods, outputs, minsize, maxsize, cluster): |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
253 for method, output in zip(methods, outputs): |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
254 F = open(output, 'w') |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
255 if method == 'Size': |
5
12c14642e6ac
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents:
4
diff
changeset
|
256 header = ["Dataset", "Chromosome", "Polarity", method, "Counts"] |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
257 else: |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
258 header = ["Dataset", "Chromosome", "Chrom_length", "Coordinate", |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
259 "Polarity", method] |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
260 F.write('\t'.join(header) + '\n') |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
261 for input, sample in zip(inputs, samples): |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
262 mapobj = Map(input, sample, minsize, maxsize, cluster) |
3
ed8b0142538d
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 7b2ceb05489c27ddb769c38fdec56274108a6fa1
artbio
parents:
2
diff
changeset
|
263 token = {"Counts": mapobj.compute_readcount, |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
264 "Max": mapobj.compute_max, |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
265 "Mean": mapobj.compute_mean, |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
266 "Median": mapobj.compute_median, |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
267 "Coverage": mapobj.compute_coverage, |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
268 "Size": mapobj.compute_size} |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
269 token[method](mapobj.map_dict, F) |
0
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
270 F.close() |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
271 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
272 |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
273 if __name__ == "__main__": |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
274 args = Parser() |
6d48150495e3
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
275 # if identical sample names |
2
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
276 if len(set(args.sample_names)) != len(args.sample_names): |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
277 args.sample_names = [name + '_' + str(i) for |
507383cce5a8
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents:
1
diff
changeset
|
278 i, name in enumerate(args.sample_names)] |
8
1827b74f872b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit e4588eb6c329e4516e9bcfa084a383be81b55c60
artbio
parents:
5
diff
changeset
|
279 main(args.inputs, args.sample_names, args.plot_methods, args.outputs, |
9
3ea75c573429
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 6199193c7fe2cb56403eea8af0b40d44f7311fd5
artbio
parents:
8
diff
changeset
|
280 args.minsize, args.maxsize, args.cluster) |