Mercurial > repos > artbio > small_rna_signatures
annotate overlapping_reads.py @ 5:a7fd04208764 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
author | artbio |
---|---|
date | Sat, 09 Sep 2017 11:57:39 -0400 |
parents | 20d28cfdeefe |
children | 4da23f009c9e |
rev | line source |
---|---|
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
1 import argparse |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
2 from collections import defaultdict |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
3 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
4 import pysam |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
5 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
6 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
7 def Parser(): |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
8 the_parser = argparse.ArgumentParser() |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
9 the_parser.add_argument( |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
10 '--input', action="store", type=str, help="bam alignment file") |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
11 the_parser.add_argument( |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
12 '--minquery', type=int, |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
13 help="Minimum readsize of query reads (nt) - must be an integer") |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
14 the_parser.add_argument( |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
15 '--maxquery', type=int, |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
16 help="Maximum readsize of query reads (nt) - must be an integer") |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
17 the_parser.add_argument( |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
18 '--mintarget', type=int, |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
19 help="Minimum readsize of target reads (nt) - must be an integer") |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
20 the_parser.add_argument( |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
21 '--maxtarget', type=int, |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
22 help="Maximum readsize of target reads (nt) - must be an integer") |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
23 the_parser.add_argument( |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
24 '--overlap', type=int, |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
25 help="Overlap analyzed (nt) - must be an integer") |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
26 the_parser.add_argument( |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
27 '--output', action="store", type=str, |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
28 help="Pairable sequences") |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
29 args = the_parser.parse_args() |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
30 return args |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
31 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
32 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
33 class Map: |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
34 |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
35 def __init__(self, bam_file, output, minquery=23, maxquery=29, |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
36 mintarget=23, maxtarget=29, overlap=10): |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
37 self.bam_object = pysam.AlignmentFile(bam_file, 'rb') |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
38 self.output = output |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
39 self.query_range = range(minquery, maxquery + 1) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
40 self.target_range = range(mintarget, maxtarget + 1) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
41 self.overlap = overlap |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
42 self.chromosomes = dict(zip(self.bam_object.references, |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
43 self.bam_object.lengths)) |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
44 self.alignement_dic = self.index_alignments(self.bam_object) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
45 self.all_query_positions = self.query_positions(self.bam_object, |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
46 overlap=self.overlap) |
3
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
47 self.readdic = self.make_readdic(self.bam_object) |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
48 self.pairing() |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
49 |
3
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
50 def make_readdic(self, bam_object): |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
51 readdic = defaultdict(int) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
52 for read in bam_object.fetch(): |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
53 readdic[read.query_sequence] += 1 |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
54 return readdic |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
55 |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
56 def index_alignments(self, bam_object): |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
57 ''' |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
58 dic[(chrom, pos, polarity)]: [readseq1, readseq2, ...] |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
59 the list value is further converted in set |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
60 ''' |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
61 dic = defaultdict(list) |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
62 for chrom in self.chromosomes: |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
63 for read in bam_object.fetch(chrom): |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
64 if read.is_reverse: |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
65 coord = read.reference_end-1 |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
66 pol = 'R' |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
67 else: |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
68 coord = read.reference_start |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
69 pol = 'F' |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
70 dic[(chrom, coord, pol)].append(read.query_sequence) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
71 for key in dic: |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
72 dic[key] = set(dic[key]) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
73 return dic |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
74 |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
75 def query_positions(self, bam_object, overlap): |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
76 all_query_positions = defaultdict(list) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
77 for genomicKey in self.alignement_dic.keys(): |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
78 chrom, coord, pol = genomicKey |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
79 if pol == 'F' and len(self.alignement_dic[(chrom, |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
80 coord+overlap-1, |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
81 'R')]) > 0: |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
82 all_query_positions[chrom].append(coord) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
83 for chrom in all_query_positions: |
3
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
84 all_query_positions[chrom] = sorted( |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
85 list(set(all_query_positions[chrom]))) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
86 return all_query_positions |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
87 |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
88 def pairing(self): |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
89 F = open(self.output, 'w') |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
90 query_range = self.query_range |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
91 target_range = self.target_range |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
92 overlap = self.overlap |
3
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
93 stringresult = [] |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
94 header_template = '>%s|coord=%s|strand %s|size=%s|nreads=%s\n%s\n' |
3
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
95 for chrom in sorted(self.chromosomes): |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
96 for pos in self.all_query_positions[chrom]: |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
97 stringbuffer = [] |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
98 uppers = self.alignement_dic[chrom, pos, 'F'] |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
99 lowers = self.alignement_dic[chrom, pos+overlap-1, 'R'] |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
100 if uppers and lowers: |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
101 for upread in uppers: |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
102 for downread in lowers: |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
103 if (len(upread) in query_range and len(downread) in |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
104 target_range) or (len(upread) in target_range |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
105 and len(downread) in |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
106 query_range): |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
107 stringbuffer.append( |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
108 header_template % |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
109 (chrom, pos+1, '+', len(upread), |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
110 self.readdic[upread], upread)) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
111 stringbuffer.append( |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
112 header_template % |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
113 (chrom, pos+overlap-len(downread)+1, '-', |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
114 len(downread), self.readdic[downread], |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
115 self.revcomp(downread))) |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
116 stringresult.extend(sorted(set(stringbuffer))) |
3
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
117 F.write(''.join(stringresult)) |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
118 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
119 def revcomp(self, sequence): |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
120 antidict = {"A": "T", "T": "A", "G": "C", "C": "G", "N": "N"} |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
121 revseq = sequence[::-1] |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
122 return "".join([antidict[i] for i in revseq]) |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
123 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
124 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
125 if __name__ == "__main__": |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
126 args = Parser() |
5
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
127 mapobj = Map(args.input, args.output, args.minquery, args.maxquery, |
a7fd04208764
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 24d44a9b7ec9db4dce3d839b597eea2b1be34adb
artbio
parents:
4
diff
changeset
|
128 args.mintarget, args.maxtarget, args.overlap) |