Mercurial > repos > artbio > small_rna_signatures
annotate overlapping_reads.py @ 4:20d28cfdeefe draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
author | artbio |
---|---|
date | Fri, 08 Sep 2017 04:44:22 -0400 |
parents | 4d9682bd3a6b |
children | a7fd04208764 |
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 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
35 def __init__(self, bam_file): |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
36 self.bam_object = pysam.AlignmentFile(bam_file, 'rb') |
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.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
|
38 self.bam_object.lengths)) |
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
|
39 self.all_query_positions = self.query_positions(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
|
40 self.readdic = self.make_readdic(self.bam_object) |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
41 |
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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
48 def query_positions(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
|
49 all_query_positions = 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
|
50 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
|
51 for read in bam_object.fetch(chrom): |
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
|
52 if not read.is_reverse: |
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 all_query_positions[chrom].append( |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
54 read.reference_start) |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
55 else: |
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
|
56 all_query_positions[chrom].append( |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
57 read.reference_end) |
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
|
58 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
|
59 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
|
60 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
|
61 |
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
|
62 def direct_pairing(self, minquery, maxquery, mintarget, maxtarget, |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
63 file, overlap=10): |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
64 F = open(file, 'w') |
1
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
65 query_range = range(minquery, maxquery + 1) |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
66 target_range = range(mintarget, maxtarget + 1) |
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
|
67 stringresult = [] |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
68 for chrom in sorted(self.chromosomes): |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
69 for pos in (self.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
|
70 iterreads_1 = self.bam_object.fetch(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
|
71 start=pos, end=pos+overlap-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
|
72 iterreads_2 = self.bam_object.fetch(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
|
73 start=pos, end=pos+overlap-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
|
74 iterreads_3 = self.bam_object.fetch(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
|
75 start=pos, end=pos+overlap-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
|
76 iterreads_4 = self.bam_object.fetch(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
|
77 start=pos, end=pos+overlap-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
|
78 # 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
|
79 for queryread in iterreads_1: |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
80 if queryread.reference_start == pos and \ |
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
|
81 queryread.query_alignment_length in query_range \ |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
82 and not queryread.is_reverse: |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
83 for targetread in iterreads_2: |
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 if (targetread. |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
85 get_reference_positions()[-1] |
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
|
86 == queryread.get_reference_positions( |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
87 )[overlap-1] and |
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
|
88 targetread.query_alignment_length in |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
89 target_range and targetread.is_reverse): |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
90 targetreadseq = self.revcomp( |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
91 targetread.query_sequence) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
92 stringresult.append( |
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 '>%s|%s|%s|%s|n=%s\n%s\n' % |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
94 (chrom, queryread.reference_start+1, |
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 'F', queryread.query_alignment_length, |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
96 self.readdic[queryread.query_sequence], |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
97 queryread.query_sequence)) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
98 stringresult.append( |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
99 '>%s|%s|%s|%s|n=%s\n%s\n' % |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
100 (chrom, targetread.reference_start+1, |
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
|
101 'R', targetread.query_alignment_length, |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
102 self.readdic[targetread.query_sequence], |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
103 targetreadseq)) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
104 # 2 |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
105 for queryread in iterreads_3: |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
106 if queryread.reference_end-1 == pos+overlap-1 and \ |
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
|
107 queryread.query_alignment_length in query_range \ |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
108 and queryread.is_reverse: |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
109 for targetread in iterreads_4: |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
110 if (targetread. |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
111 reference_start |
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
|
112 == pos and targetread.query_alignment_length |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
113 in target_range and not |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
114 targetread.is_reverse): |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
115 queryreadseq = self.revcomp( |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
116 queryread.query_sequence) |
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 targetreadseq = targetread.query_sequence |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
118 stringresult.append( |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
119 '>%s|%s|%s|%s|n=%s\n%s\n' % |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
120 (chrom, queryread.reference_start+1, 'R', |
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
|
121 queryread.query_alignment_length, |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
122 self.readdic[queryread.query_sequence], |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
123 queryreadseq)) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
124 stringresult.append( |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
125 '>%s|%s|%s|%s|n=%s\n%s\n' % |
4
20d28cfdeefe
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit cfdc08418887bfe4a35588cd78d0a2b6ffa6e19e
artbio
parents:
3
diff
changeset
|
126 (chrom, targetread.reference_start+1, |
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
|
127 'F', targetread.query_alignment_length, |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
128 self.readdic[targetread.query_sequence], |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
129 targetreadseq)) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
130 stringresult = sorted(set(stringresult), |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
131 key=lambda x: stringresult.index(x)) |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
132 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
|
133 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
139 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
140 def main(input, minquery, maxquery, mintarget, maxtarget, output, overlap=10): |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
141 mapobj = Map(input) |
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
|
142 mapobj.direct_pairing(minquery, maxquery, mintarget, maxtarget, |
4d9682bd3a6b
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 96ed5824190aff281cc3aa47dc60fc66aac41db3
artbio
parents:
1
diff
changeset
|
143 output, 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
|
144 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
145 |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
146 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
|
147 args = Parser() |
6f1378738798
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 6133bb114c76a795fa12a4a11edb1a8b80fd104d
artbio
parents:
diff
changeset
|
148 main(args.input, args.minquery, args.maxquery, args.mintarget, |
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
|
149 args.maxtarget, args.output, args.overlap) |