annotate sashimi-plot.py @ 2:964b974a5348 draft default tip

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit c9cdba24b5e5f47d61814834ea5e376467fede5c"
author artbio
date Tue, 07 Jan 2020 06:30:31 -0500
parents 9304dd9a16a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1 #!/usr/bin/env python
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
2
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
3 # Import modules
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
4 import copy
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
5 import os
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
6 import re
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
7 import subprocess as sp
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
8 import sys
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
9 from argparse import ArgumentParser
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
10 from collections import OrderedDict
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
11
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
12
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
13 def define_options():
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
14 # Argument parsing
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
15 parser = ArgumentParser(description="""Create sashimi plot for a given
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
16 genomic region""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
17 parser.add_argument("-b", "--bam", type=str,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
18 help="""
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
19 Individual bam file or file with a list of bam files.
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
20 In the case of a list of files the format is tsv:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
21 1col: id for bam file,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
22 2col: path of bam file,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
23 3+col: additional columns
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
24 """)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
25 parser.add_argument("-c", "--coordinates", type=str,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
26 help="Genomic region. Format: chr:start-end (1-based)")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
27 parser.add_argument("-o", "--out-prefix", type=str, dest="out_prefix",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
28 default="sashimi",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
29 help="Prefix for plot file name [default=%(default)s]")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
30 parser.add_argument("-S", "--out-strand", type=str, dest="out_strand",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
31 default="both", help="""Only for --strand other than
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
32 'NONE'. Choose which signal strand to plot:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
33 <both> <plus> <minus> [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
34 parser.add_argument("-M", "--min-coverage", type=int, default=1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
35 dest="min_coverage", help="""Minimum number of reads
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
36 supporting a junction to be drawn [default=1]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
37 parser.add_argument("-j", "--junctions-bed", type=str, default="",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
38 dest="junctions_bed", help="""Junction BED file name
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
39 [default=no junction file]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
40 parser.add_argument("-g", "--gtf",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
41 help="Gtf file with annotation (only exons is enough)")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
42 parser.add_argument("-s", "--strand", default="NONE", type=str,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
43 help="""Strand specificity: <NONE> <SENSE> <ANTISENSE>
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
44 <MATE1_SENSE> <MATE2_SENSE> [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
45 parser.add_argument("--shrink", action="store_true",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
46 help="""Shrink the junctions by a factor for nicer
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
47 display [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
48 parser.add_argument("-O", "--overlay", type=int,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
49 help="Index of column with overlay levels (1-based)")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
50 parser.add_argument("-A", "--aggr", type=str, default="",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
51 help="""Aggregate function for overlay:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
52 <mean> <median> <mean_j> <median_j>.
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
53 Use mean_j | median_j to keep density overlay but
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
54 aggregate junction counts [default=no aggregation]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
55 parser.add_argument("-C", "--color-factor", type=int, dest="color_factor",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
56 help="Index of column with color levels (1-based)")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
57 parser.add_argument("--alpha", type=float, default=0.5,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
58 help="""Transparency level for density histogram
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
59 [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
60 parser.add_argument("-P", "--palette", type=str,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
61 help="""Color palette file. tsv file with >=1 columns,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
62 where the color is the first column""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
63 parser.add_argument("-L", "--labels", type=int, dest="labels", default=1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
64 help="""Index of column with labels (1-based)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
65 [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
66 parser.add_argument("--height", type=float, default=2,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
67 help="""Height of the individual signal plot in inches
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
68 [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
69 parser.add_argument("--ann-height", type=float, default=1.5,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
70 dest="ann_height", help="""Height of annotation plot in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
71 inches [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
72 parser.add_argument("--width", type=float, default=10,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
73 help="""Width of the plot in inches
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
74 [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
75 parser.add_argument("--base-size", type=float, default=14,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
76 dest="base_size", help="""Base font size of the plot in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
77 pch [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
78 parser.add_argument("-F", "--out-format", type=str, default="pdf",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
79 dest="out_format", help="""Output file format:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
80 <pdf> <svg> <png> <jpeg> <tiff>
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
81 [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
82 parser.add_argument("-R", "--out-resolution", type=int, default=300,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
83 dest="out_resolution", help="""Output file resolution in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
84 PPI (pixels per inch). Applies only to raster output
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
85 formats [default=%(default)s]""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
86 return parser
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
87
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
88
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
89 def parse_coordinates(c):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
90 c = c.replace(",", "")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
91 chr = c.split(":")[0]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
92 start, end = c.split(":")[1].split("-")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
93 # Convert to 0-based
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
94 start, end = int(start) - 1, int(end)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
95 return chr, start, end
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
96
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
97
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
98 def count_operator(CIGAR_op, CIGAR_len, pos, start, end, a, junctions):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
99
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
100 # Match
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
101 if CIGAR_op == "M":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
102 for i in range(pos, pos + CIGAR_len):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
103 if i < start or i >= end:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
104 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
105 ind = i - start
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
106 a[ind] += 1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
107
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
108 # Insertion or Soft-clip
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
109 if CIGAR_op == "I" or CIGAR_op == "S":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
110 return pos
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
111
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
112 # Deletion
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
113 if CIGAR_op == "D":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
114 pass
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
115
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
116 # Junction
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
117 if CIGAR_op == "N":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
118 don = pos
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
119 acc = pos + CIGAR_len
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
120 if don > start and acc < end:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
121 junctions[(don, acc)] = junctions.setdefault((don, acc), 0) + 1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
122
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
123 pos = pos + CIGAR_len
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
124
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
125 return pos
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
126
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
127
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
128 def flip_read(s, samflag):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
129 if s == "NONE" or s == "SENSE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
130 return 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
131 if s == "ANTISENSE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
132 return 1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
133 if s == "MATE1_SENSE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
134 if int(samflag) & 64:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
135 return 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
136 if int(samflag) & 128:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
137 return 1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
138 if s == "MATE2_SENSE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
139 if int(samflag) & 64:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
140 return 1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
141 if int(samflag) & 128:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
142 return 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
143
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
144
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
145 def read_bam(f, c, s):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
146
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
147 _, start, end = parse_coordinates(c)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
148
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
149 # Initialize coverage array and junction dict
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
150 a = {"+": [0] * (end - start)}
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
151 junctions = {"+": OrderedDict()}
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
152 if s != "NONE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
153 a["-"] = [0] * (end - start)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
154 junctions["-"] = OrderedDict()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
155
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
156 p = sp.Popen("samtools view %s %s " % (f, c), shell=True, stdout=sp.PIPE)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
157 for line in p.communicate()[0].decode('utf8').strip().split("\n"):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
158
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
159 if line == "":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
160 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
161
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
162 line_sp = line.strip().split("\t")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
163 samflag, read_start, CIGAR = line_sp[1], int(line_sp[3]), line_sp[5]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
164
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
165 # Ignore reads with more exotic CIGAR operators
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
166 if any(map(lambda x: x in CIGAR, ["H", "P", "X", "="])):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
167 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
168
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
169 read_strand = ["+", "-"][flip_read(s, samflag) ^ bool(int(samflag) &
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
170 16)]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
171 if s == "NONE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
172 read_strand = "+"
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
173
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
174 CIGAR_lens = re.split("[MIDNS]", CIGAR)[:-1]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
175 CIGAR_ops = re.split("[0-9]+", CIGAR)[1:]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
176
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
177 pos = read_start
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
178
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
179 for n, CIGAR_op in enumerate(CIGAR_ops):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
180 CIGAR_len = int(CIGAR_lens[n])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
181 pos = count_operator(CIGAR_op, CIGAR_len, pos, start, end,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
182 a[read_strand], junctions[read_strand])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
183
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
184 p.stdout.close()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
185 return a, junctions
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
186
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
187
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
188 def get_bam_path(index, path):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
189 if os.path.isabs(path):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
190 return path
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
191 base_dir = os.path.dirname(index)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
192 return os.path.join(base_dir, path)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
193
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
194
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
195 def read_bam_input(f, overlay, color, label):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
196 if f.endswith(".bam"):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
197 bn = f.strip().split("/")[-1].strip(".bam")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
198 yield bn, f, None, None, bn
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
199 return
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
200 with open(f) as openf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
201 for line in openf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
202 line_sp = line.strip().split("\t")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
203 bam = get_bam_path(f, line_sp[1])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
204 overlay_level = line_sp[overlay-1] if overlay else None
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
205 color_level = line_sp[color-1] if color else None
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
206 label_text = line_sp[label-1] if label else None
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
207 yield line_sp[0], bam, overlay_level, color_level, label_text
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
208
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
209
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
210 def prepare_for_R(a, junctions, c, m):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
211
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
212 _, start, _ = parse_coordinates(args.coordinates)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
213
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
214 # Convert the array index to genomic coordinates
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
215 x = list(i+start for i in range(len(a)))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
216 y = a
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
217
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
218 # Arrays for R
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
219 dons, accs, yd, ya, counts = [], [], [], [], []
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
220
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
221 # Prepare arrays for junctions (which will be the arcs)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
222 for (don, acc), n in junctions.items():
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
223
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
224 # Do not add junctions with less than defined coverage
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
225 if n < m:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
226 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
227
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
228 dons.append(don)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
229 accs.append(acc)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
230 counts.append(n)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
231
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
232 yd.append(a[don - start - 1])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
233 ya.append(a[acc - start + 1])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
234
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
235 return x, y, dons, accs, yd, ya, counts
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
236
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
237
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
238 def intersect_introns(data):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
239 data = sorted(data)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
240 it = iter(data)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
241 a, b = next(it)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
242 for c, d in it:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
243 if b > c:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
244 # Use `if b > c` if you want (1,2), (2,3) not to be
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
245 # treated as intersection.
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
246 b = min(b, d)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
247 a = max(a, c)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
248 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
249 yield a, b
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
250 a, b = c, d
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
251 yield a, b
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
252
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
253
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
254 def shrink_density(x, y, introns):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
255 new_x, new_y = [], []
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
256 shift = 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
257 start = 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
258 # introns are already sorted by coordinates
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
259 for a, b in introns:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
260 end = x.index(a)+1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
261 new_x += [int(i-shift) for i in x[start:end]]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
262 new_y += y[start:end]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
263 start = x.index(b)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
264 L = (b-a)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
265 shift += L-L**0.7
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
266 new_x += [int(i-shift) for i in x[start:]]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
267 new_y += y[start:]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
268 return new_x, new_y
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
269
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
270
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
271 def shrink_junctions(dons, accs, introns):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
272 new_dons, new_accs = [0]*len(dons), [0]*len(accs)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
273 shift_acc = 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
274 shift_don = 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
275 s = set()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
276 junctions = list(zip(dons, accs))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
277 for a, b in introns:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
278 L = b - a
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
279 shift_acc += L-int(L**0.7)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
280 for i, (don, acc) in enumerate(junctions):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
281 if a >= don and b <= acc:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
282 if (don, acc) not in s:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
283 new_dons[i] = don - shift_don
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
284 new_accs[i] = acc - shift_acc
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
285 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
286 new_accs[i] = acc - shift_acc
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
287 s.add((don, acc))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
288 shift_don = shift_acc
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
289 return new_dons, new_accs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
290
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
291
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
292 def read_palette(f):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
293 palette = "#ff0000", "#00ff00", "#0000ff", "#000000"
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
294 if f:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
295 with open(f) as openf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
296 palette = list(line.split("\t")[0].strip() for line in openf)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
297 return palette
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
298
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
299
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
300 def read_gtf(f, c):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
301 exons = OrderedDict()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
302 transcripts = OrderedDict()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
303 chr, start, end = parse_coordinates(c)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
304 end = end - 1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
305 with open(f) as openf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
306 for line in openf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
307 if line.startswith("#"):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
308 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
309 (el_chr, _, el, el_start, el_end, _,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
310 strand, _, tags) = line.strip().split("\t")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
311 if el_chr != chr:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
312 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
313 d = dict(kv.strip().split(" ") for kv in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
314 tags.strip(";").split("; "))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
315 transcript_id = d["transcript_id"]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
316 el_start, el_end = int(el_start) - 1, int(el_end)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
317 strand = '"' + strand + '"'
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
318 if el == "transcript":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
319 if (el_end > start and el_start < end):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
320 transcripts[transcript_id] = (max(start, el_start),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
321 min(end, el_end),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
322 strand)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
323 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
324 if el == "exon":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
325 if (start < el_start < end or start < el_end < end):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
326 exons.setdefault(transcript_id,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
327 []).append((max(el_start, start),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
328 min(end, el_end), strand))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
329
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
330 return transcripts, exons
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
331
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
332
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
333 def make_introns(transcripts, exons, intersected_introns=None):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
334 new_transcripts = copy.deepcopy(transcripts)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
335 new_exons = copy.deepcopy(exons)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
336 introns = OrderedDict()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
337 if intersected_introns:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
338 for tx, (tx_start, tx_end, strand) in new_transcripts.items():
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
339 total_shift = 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
340 for a, b in intersected_introns:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
341 L = b - a
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
342 shift = L - int(L**0.7)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
343 total_shift += shift
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
344 for i, (exon_start, exon_end, strand) in \
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
345 enumerate(exons.get(tx, [])):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
346 new_exon_start, new_exon_end = new_exons[tx][i][:2]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
347 if a < exon_start:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
348 if b > exon_end:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
349 if i == len(exons[tx])-1:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
350 total_shift = total_shift - shift + \
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
351 (exon_start - a)*(1-int(L**-0.3))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
352 shift = (exon_start - a)*(1-int(L**-0.3))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
353 new_exon_end = new_exons[tx][i][1] - shift
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
354 new_exon_start = new_exons[tx][i][0] - shift
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
355 if b <= exon_end:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
356 new_exon_end = new_exons[tx][i][1] - shift
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
357 new_exons[tx][i] = (new_exon_start, new_exon_end, strand)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
358 tx_start = min(tx_start,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
359 sorted(new_exons.get(tx, [[sys.maxsize]]))[0][0])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
360 new_transcripts[tx] = (tx_start, tx_end - total_shift, strand)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
361
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
362 for tx, (tx_start, tx_end, strand) in new_transcripts.items():
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
363 intron_start = tx_start
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
364 ex_end = 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
365 for ex_start, ex_end, strand in sorted(new_exons.get(tx, [])):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
366 intron_end = ex_start
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
367 if tx_start < ex_start:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
368 introns.setdefault(tx, []).append((intron_start, intron_end,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
369 strand))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
370 intron_start = ex_end
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
371 if tx_end > ex_end:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
372 introns.setdefault(tx, []).append((intron_start, tx_end, strand))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
373 d = {'transcripts': new_transcripts,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
374 'exons': new_exons,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
375 'introns': introns}
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
376 return d
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
377
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
378
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
379 def gtf_for_ggplot(annotation, start, end, arrow_bins):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
380 arrow_space = int((end - start)/arrow_bins)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
381 s = """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
382
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
383 # data table with exons
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
384 ann_list = list(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
385 "exons" = data.table(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
386 "introns" = data.table()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
387 )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
388 """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
389
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
390 if annotation["exons"]:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
391
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
392 s += """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
393 ann_list[['exons']] = data.table(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
394 tx = rep(c(%(tx_exons)s), c(%(n_exons)s)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
395 start = c(%(exon_start)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
396 end = c(%(exon_end)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
397 strand = c(%(strand)s)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
398 )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
399 """ % ({
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
400 "tx_exons": ",".join(annotation["exons"].keys()),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
401 "n_exons": ",".join(map(str, map(len,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
402 annotation["exons"].values()))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
403 "exon_start": ",".join(map(str, (v[0] for vs in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
404 annotation["exons"].values() for v in vs))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
405 "exon_end": ",".join(map(str, (v[1] for vs in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
406 annotation["exons"].values() for v in vs))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
407 "strand": ",".join(map(str, (v[2] for vs in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
408 annotation["exons"].values() for v in vs))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
409 })
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
410
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
411 if annotation["introns"]:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
412
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
413 s += """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
414 ann_list[['introns']] = data.table(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
415 tx = rep(c(%(tx_introns)s), c(%(n_introns)s)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
416 start = c(%(intron_start)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
417 end = c(%(intron_end)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
418 strand = c(%(strand)s)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
419 )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
420 # Create data table for strand arrows
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
421 txarrows = data.table()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
422 introns = ann_list[['introns']]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
423 # Add right-pointing arrows for plus strand
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
424 if ("+" %%in%% introns$strand) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
425 txarrows = rbind(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
426 txarrows,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
427 introns[strand=="+" & end-start>5, list(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
428 seq(start+4,end,by=%(arrow_space)s)-1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
429 seq(start+4,end,by=%(arrow_space)s)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
430 ), by=.(tx,start,end)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
431 ]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
432 )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
433 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
434 # Add left-pointing arrows for minus strand
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
435 if ("-" %%in%% introns$strand) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
436 txarrows = rbind(txarrows,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
437 introns[strand=="-" & end-start>5,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
438 list(seq(start,max(start+1, end-4),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
439 by=%(arrow_space)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
440 seq(start,max(start+1, end-4),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
441 by=%(arrow_space)s)-1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
442 ),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
443 by=.(tx,start,end)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
444 ]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
445 )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
446 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
447 """ % ({
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
448 "tx_introns": ",".join(annotation["introns"].keys()),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
449 "n_introns": ",".join(map(str, map(len,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
450 annotation["introns"].values()))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
451 "intron_start": ",".join(map(str, (v[0] for vs in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
452 annotation["introns"].values() for v in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
453 vs))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
454 "intron_end": ",".join(map(str, (v[1] for vs in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
455 annotation["introns"].values() for v in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
456 vs))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
457 "strand": ",".join(map(str, (v[2] for vs in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
458 annotation["introns"].values() for v in vs))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
459 "arrow_space": arrow_space,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
460 })
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
461
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
462 s += """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
463
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
464 gtfp = ggplot()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
465 if (length(ann_list[['introns']]) > 0) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
466 gtfp = gtfp + geom_segment(data = ann_list[['introns']],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
467 aes(x = start,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
468 xend = end,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
469 y = tx,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
470 yend = tx),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
471 size = 0.3)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
472 gtfp = gtfp + geom_segment(data = txarrows,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
473 aes(x = V1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
474 xend = V2,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
475 y = tx,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
476 yend = tx),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
477 arrow = arrow(length = unit(0.02, "npc")))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
478 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
479 if (length(ann_list[['exons']]) > 0) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
480 gtfp = gtfp + geom_segment(data = ann_list[['exons']],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
481 aes(x = start,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
482 xend = end,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
483 y = tx,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
484 yend = tx),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
485 size = 5,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
486 alpha = 1)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
487 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
488 gtfp = gtfp + scale_y_discrete(expand = c(0, 0.5))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
489 gtfp = gtfp + scale_x_continuous(expand = c(0, 0.25),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
490 limits = c( %s,% s))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
491 gtfp = gtfp + labs(y = NULL)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
492 gtfp = gtfp + theme(axis.line = element_blank(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
493 axis.text.x = element_blank(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
494 axis.ticks = element_blank())
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
495 """ % (start, end)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
496
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
497 return s
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
498
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
499
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
500 def setup_R_script(h, w, b, label_dict):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
501 s = """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
502 library(ggplot2)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
503 library(grid)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
504 library(gridExtra)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
505 library(data.table)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
506 library(gtable)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
507
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
508 scale_lwd = function(r) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
509 lmin = 0.1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
510 lmax = 4
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
511 return( r*(lmax-lmin)+lmin )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
512 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
513
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
514 base_size = %(b)s
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
515 height = ( %(h)s + base_size*0.352777778/67 ) * 1.02
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
516 width = %(w)s
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
517 theme_set(theme_bw(base_size=base_size))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
518 theme_update(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
519 plot.margin = unit(c(15,15,15,15), "pt"),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
520 panel.grid = element_blank(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
521 panel.border = element_blank(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
522 axis.line = element_line(size=0.5),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
523 axis.title.x = element_blank(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
524 axis.title.y = element_text(angle=0, vjust=0.5)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
525 )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
526
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
527 labels = list(%(labels)s)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
528
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
529 density_list = list()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
530 junction_list = list()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
531
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
532 """ % ({
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
533 'h': h,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
534 'w': w,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
535 'b': b,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
536 'labels': ",".join(('"%s"="%s"' % (id, lab) for id, lab in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
537 label_dict.items())),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
538 })
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
539 return s
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
540
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
541
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
542 def median(lst):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
543 quotient, remainder = divmod(len(lst), 2)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
544 if remainder:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
545 return sorted(lst)[quotient]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
546 return sum(sorted(lst)[quotient - 1:quotient + 1]) / 2.
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
547
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
548
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
549 def mean(lst):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
550 return sum(lst)/len(lst)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
551
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
552
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
553 def make_R_lists(id_list, d, overlay_dict, aggr, intersected_introns):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
554 s = ""
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
555 aggr_f = {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
556 "mean": mean,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
557 "median": median,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
558 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
559 id_list = id_list if not overlay_dict else overlay_dict.keys()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
560 # Iterate over ids to get bam signal and junctions
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
561 for k in id_list:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
562 x, y, dons, accs, yd, ya, counts = [], [], [], [], [], [], []
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
563 if not overlay_dict:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
564 x, y, dons, accs, yd, ya, counts = d[k]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
565 if intersected_introns:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
566 x, y = shrink_density(x, y, intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
567 dons, accs = shrink_junctions(dons, accs, intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
568 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
569 for id in overlay_dict[k]:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
570 xid, yid, donsid, accsid, ydid, yaid, countsid = d[id]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
571 if intersected_introns:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
572 xid, yid = shrink_density(xid, yid, intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
573 donsid, accsid = shrink_junctions(donsid, accsid,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
574 intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
575 x += xid
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
576 y += yid
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
577 dons += donsid
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
578 accs += accsid
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
579 yd += ydid
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
580 ya += yaid
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
581 counts += countsid
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
582 if aggr and "_j" not in aggr:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
583 x = d[overlay_dict[k][0]][0]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
584 y = list(map(aggr_f[aggr], zip(*(d[id][1] for id in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
585 overlay_dict[k]))))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
586 if intersected_introns:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
587 x, y = shrink_density(x, y, intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
588 # dons, accs, yd, ya, counts = [], [], [], [], []
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
589 s += """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
590 density_list[["%(id)s"]] = data.frame(x = c(%(x)s), y = c(%(y)s))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
591 junction_list[["%(id)s"]] = data.frame(x = c(%(dons)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
592 xend=c(%(accs)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
593 y=c(%(yd)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
594 yend=c(%(ya)s),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
595 count=c(%(counts)s))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
596 """ % ({
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
597 "id": k,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
598 'x': ",".join(map(str, x)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
599 'y': ",".join(map(str, y)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
600 'dons': ",".join(map(str, dons)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
601 'accs': ",".join(map(str, accs)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
602 'yd': ",".join(map(str, yd)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
603 'ya': ",".join(map(str, ya)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
604 'counts': ",".join(map(str, counts)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
605 })
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
606 return s
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
607
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
608
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
609 def plot(R_script):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
610 p = sp.Popen("R --vanilla --slave", shell=True, stdin=sp.PIPE)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
611 p.communicate(input=R_script.encode())
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
612 p.stdin.close()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
613 p.wait()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
614 return
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
615
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
616
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
617 def colorize(d, p, color_factor):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
618 levels = sorted(set(d.values()))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
619 n = len(levels)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
620 if n > len(p):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
621 p = (p*n)[:n]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
622 if color_factor:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
623 s = "color_list = list(%s)\n" % (",".join('%s="%s"' % (k,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
624 p[levels.index(v)]) for k, v in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
625 d.items()))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
626 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
627 s = "color_list = list(%s)\n" % (",".join('%s="%s"' % (k, "grey") for
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
628 k, v in d.items()))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
629 return s
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
630
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
631
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
632 if __name__ == "__main__":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
633
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
634 strand_dict = {"plus": "+", "minus": "-"}
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
635
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
636 parser = define_options()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
637 if len(sys.argv) == 1:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
638 parser.print_help()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
639 sys.exit(1)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
640 args = parser.parse_args()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
641
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
642 if args.aggr and not args.overlay:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
643 print("""ERROR: Cannot apply aggregate function
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
644 if overlay is not selected.""")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
645 exit(1)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
646
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
647 palette = read_palette(args.palette)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
648
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
649 (bam_dict, overlay_dict, color_dict,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
650 id_list, label_dict) = ({"+": OrderedDict()}, OrderedDict(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
651 OrderedDict(), [], OrderedDict())
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
652 if args.strand != "NONE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
653 bam_dict["-"] = OrderedDict()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
654 if args.junctions_bed != "":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
655 junctions_list = []
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
656
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
657 for (id, bam, overlay_level,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
658 color_level, label_text) in read_bam_input(args.bam,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
659 args.overlay,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
660 args.color_factor,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
661 args.labels):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
662 if not os.path.isfile(bam):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
663 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
664 id_list.append(id)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
665 label_dict[id] = label_text
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
666 a, junctions = read_bam(bam, args.coordinates, args.strand)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
667 if a.keys() == ["+"] and all(map(lambda x: x == 0,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
668 list(a.values()[0]))):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
669 print("ERROR: No reads in the specified area.")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
670 exit(1)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
671 for strand in a:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
672 # Store junction information
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
673 if args.junctions_bed:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
674 for k, v in zip(junctions[strand].keys(),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
675 junctions[strand].values()):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
676 if v > args.min_coverage:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
677 junctions_list.append('\t'.join([args.coordinates.split
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
678 (':')[0], str(k[0]), str(k[1]),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
679 id, str(v), strand]))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
680 bam_dict[strand][id] = prepare_for_R(a[strand],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
681 junctions[strand],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
682 args.coordinates,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
683 args.min_coverage)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
684 if color_level is None:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
685 color_dict.setdefault(id, id)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
686 if overlay_level is not None:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
687 overlay_dict.setdefault(overlay_level, []).append(id)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
688 label_dict[overlay_level] = overlay_level
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
689 color_dict.setdefault(overlay_level, overlay_level)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
690 if overlay_level is None:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
691 color_dict.setdefault(id, color_level)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
692
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
693 # No bam files
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
694 if not bam_dict["+"]:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
695 print("ERROR: No available bam files.")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
696 exit(1)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
697
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
698 # Write junctions to BED
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
699 if args.junctions_bed:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
700 if not args.junctions_bed.endswith('.bed'):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
701 args.junctions_bed = args.junctions_bed + '.bed'
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
702 jbed = open(args.junctions_bed, 'w')
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
703 jbed.write('\n'.join(sorted(junctions_list)))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
704 jbed.close()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
705
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
706 if args.gtf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
707 transcripts, exons = read_gtf(args.gtf, args.coordinates)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
708
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
709 if args.out_format not in ('pdf', 'png', 'svg', 'tiff', 'jpeg'):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
710 print("""ERROR: Provided output format '%s' is not available.
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
711 Please select among 'pdf', 'png', 'svg',
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
712 'tiff' or 'jpeg'""" % args.out_format)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
713 exit(1)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
714
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
715 # Iterate for plus and minus strand
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
716 for strand in bam_dict:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
717
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
718 # Output file name (allow tiff/tif and jpeg/jpg extensions)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
719 if args.out_prefix.endswith(('.pdf', '.png', '.svg', '.tiff',
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
720 '.tif', '.jpeg', '.jpg')):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
721 out_split = os.path.splitext(args.out_prefix)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
722 if (args.out_format == out_split[1][1:] or
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
723 args.out_format == 'tiff'
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
724 and out_split[1] in ('.tiff', '.tif') or
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
725 args.out_format == 'jpeg'
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
726 and out_split[1] in ('.jpeg', '.jpg')):
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
727 args.out_prefix = out_split[0]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
728 out_suffix = out_split[1][1:]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
729 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
730 out_suffix = args.out_format
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
731 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
732 out_suffix = args.out_format
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
733 out_prefix = args.out_prefix + "_" + strand
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
734 if args.strand == "NONE":
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
735 out_prefix = args.out_prefix
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
736 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
737 if args.out_strand != "both" \
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
738 and strand != strand_dict[args.out_strand]:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
739 continue
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
740
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
741 # Find set of junctions to perform shrink
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
742 intersected_introns = None
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
743 if args.shrink:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
744 introns = (v for vs in bam_dict[strand].values() for v in
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
745 zip(vs[2], vs[3]))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
746 intersected_introns = list(intersect_introns(introns))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
747
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
748 # *** PLOT *** Define plot height
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
749 bam_height = args.height * len(id_list)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
750 if args.overlay:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
751 bam_height = args.height * len(overlay_dict)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
752 if args.gtf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
753 bam_height += args.ann_height
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
754
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
755 # *** PLOT *** Start R script by loading libraries,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
756 # initializing variables, etc...
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
757 R_script = setup_R_script(bam_height, args.width,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
758 args.base_size, label_dict)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
759
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
760 R_script += colorize(color_dict, palette, args.color_factor)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
761
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
762 # *** PLOT *** Prepare annotation plot only for the first bam file
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
763 arrow_bins = 50
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
764 if args.gtf:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
765 # Make introns from annotation (they are shrunk if required)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
766 annotation = make_introns(transcripts, exons, intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
767 x = list(bam_dict[strand].values())[0][0]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
768 if args.shrink:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
769 x, _ = shrink_density(x, x, intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
770 R_script += gtf_for_ggplot(annotation, x[0], x[-1], arrow_bins)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
771
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
772 R_script += make_R_lists(id_list, bam_dict[strand], overlay_dict,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
773 args.aggr, intersected_introns)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
774
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
775 R_script += """
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
776
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
777 pdf(NULL) # just to remove the blank pdf produced by ggplotGrob
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
778 # fix problems with ggplot2 vs >3.0.0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
779 if(packageVersion('ggplot2') >= '3.0.0'){
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
780 vs = 1
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
781 } else {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
782 vs = 0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
783 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
784
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
785 density_grobs = list();
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
786
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
787 for (bam_index in 1:length(density_list)) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
788
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
789 id = names(density_list)[bam_index]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
790 d = data.table(density_list[[id]])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
791 junctions = data.table(junction_list[[id]])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
792
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
793 maxheight = max(d[['y']])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
794
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
795 # Density plot
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
796 gp = ggplot(d) + geom_bar(aes(x, y), width=1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
797 position='identity',
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
798 stat='identity',
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
799 fill=color_list[[id]],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
800 alpha=%(alpha)s)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
801 gp = gp + labs(y=labels[[id]])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
802 gp = gp + scale_x_continuous(expand=c(0,0.2))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
803
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
804 # fix problems with ggplot2 vs >3.0.0
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
805 if(packageVersion('ggplot2') >= '3.0.0') {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
806 gp = gp +
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
807 scale_y_continuous(breaks =
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
808 ggplot_build(gp
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
809 )$layout$panel_params[[1]]$y.major_source)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
810 } else {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
811 gp = gp +
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
812 scale_y_continuous(breaks =
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
813 ggplot_build(gp
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
814 )$layout$panel_ranges[[1]]$y.major_source)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
815 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
816
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
817 # Aggregate junction counts
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
818 row_i = c()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
819 if (nrow(junctions) >0 ) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
820
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
821 junctions$jlabel = as.character(junctions$count)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
822 junctions = setNames(junctions[,.(max(y),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
823 max(yend),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
824 round(mean(count)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
825 paste(jlabel,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
826 collapse=",")),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
827 keyby=.(x,xend)],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
828 names(junctions))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
829 if ("%(args.aggr)s" != "") {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
830 junctions = setNames(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
831 junctions[,.(max(y),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
832 max(yend),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
833 round(%(args.aggr)s(count)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
834 round(%(args.aggr)s(count))),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
835 keyby=.(x,xend)],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
836 names(junctions))
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
837 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
838 # The number of rows (unique junctions per bam) has to be
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
839 # calculated after aggregation
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
840 row_i = 1:nrow(junctions)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
841 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
842
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
843
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
844 for (i in row_i) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
845
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
846 j_tot_counts = sum(junctions[['count']])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
847
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
848 j = as.numeric(junctions[i,1:5])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
849
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
850 if ("%(args.aggr)s" != "") {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
851 j[3] = as.numeric(d[x==j[1]-1,y])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
852 j[4] = as.numeric(d[x==j[2]+1,y])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
853 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
854
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
855 # Find intron midpoint
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
856 xmid = round(mean(j[1:2]), 1)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
857 ymid = max(j[3:4]) * 1.2
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
858
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
859 # Thickness of the arch
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
860 lwd = scale_lwd(j[5]/j_tot_counts)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
861
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
862 curve_par = gpar(lwd=lwd, col=color_list[[id]])
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
863
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
864 # Arc grobs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
865
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
866 # Choose position of the arch (top or bottom)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
867 nss = i
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
868 if (nss%%%%2 == 0) { #bottom
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
869 ymid = -0.3 * maxheight
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
870 # Draw the arcs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
871 # Left
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
872 curve = xsplineGrob(x = c(0, 0, 1, 1),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
873 y = c(1, 0, 0, 0),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
874 shape = 1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
875 gp = curve_par)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
876 gp = gp + annotation_custom(grob = curve,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
877 j[1], xmid, 0, ymid)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
878 # Right
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
879 curve = xsplineGrob(x = c(1, 1, 0, 0),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
880 y = c(1, 0, 0, 0),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
881 shape = 1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
882 gp = curve_par)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
883 gp = gp + annotation_custom(grob = curve,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
884 xmid,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
885 j[2],
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
886 0, ymid)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
887 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
888
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
889 if (nss%%%%2 != 0) { #top
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
890 # Draw the arcs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
891 # Left
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
892 curve = xsplineGrob(x = c(0, 0, 1, 1),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
893 y = c(0, 1, 1, 1),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
894 shape = 1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
895 gp = curve_par)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
896 gp = gp + annotation_custom(grob = curve,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
897 j[1], xmid, j[3], ymid)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
898 # Right
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
899 curve = xsplineGrob(x = c(1, 1, 0, 0),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
900 y = c(0, 1, 1, 1),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
901 shape = 1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
902 gp = curve_par)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
903 gp = gp + annotation_custom(grob = curve,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
904 xmid, j[2], j[4], ymid)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
905 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
906
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
907 # Add junction labels
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
908 gp = gp + annotate("label", x = xmid, y = ymid,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
909 label = as.character(junctions[i,6]),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
910 vjust = 0.5, hjust = 0.5,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
911 label.padding = unit(0.01, "lines"),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
912 label.size = NA,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
913 size = (base_size*0.352777778)*0.6)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
914
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
915 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
916
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
917 gpGrob = ggplotGrob(gp);
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
918 gpGrob$layout$clip[gpGrob$layout$name=="panel"] <- "off"
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
919 if (bam_index == 1) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
920 # fix problems ggplot2 vs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
921 maxWidth = gpGrob$widths[2+vs] + gpGrob$widths[3+vs];
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
922 maxYtextWidth = gpGrob$widths[3+vs];
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
923 # Extract x axis grob (trim=F --> keep empty cells)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
924 xaxisGrob <- gtable_filter(gpGrob, "axis-b", trim=F)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
925 # fix problems ggplot2 vs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
926 xaxisGrob$heights[8+vs] = gpGrob$heights[1]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
927 x.axis.height = gpGrob$heights[7+vs] + gpGrob$heights[1]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
928 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
929
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
930
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
931 # Remove x axis from all density plots
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
932 kept_names = gpGrob$layout$name[gpGrob$layout$name != "axis-b"]
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
933 gpGrob <- gtable_filter(gpGrob,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
934 paste(kept_names, sep = "",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
935 collapse = "|"),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
936 trim=F)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
937
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
938 # Find max width of y text and y label and max width of y text
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
939 # fix problems ggplot2 vs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
940 maxWidth = grid::unit.pmax(maxWidth,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
941 gpGrob$widths[2+vs] +
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
942 gpGrob$widths[3+vs]);
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
943 maxYtextWidth = grid::unit.pmax(maxYtextWidth,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
944 gpGrob$widths[3+vs]);
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
945 density_grobs[[id]] = gpGrob;
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
946 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
947
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
948 # Add x axis grob after density grobs BEFORE annotation grob
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
949 density_grobs[["xaxis"]] = xaxisGrob
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
950
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
951 # Annotation grob
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
952 if (%(args.gtf)s == 1) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
953 gtfGrob = ggplotGrob(gtfp);
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
954 maxWidth = grid::unit.pmax(maxWidth,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
955 gtfGrob$widths[2+vs] +
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
956 gtfGrob$widths[3+vs]);
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
957 density_grobs[['gtf']] = gtfGrob;
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
958 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
959
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
960 # Reassign grob widths to align the plots
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
961 for (id in names(density_grobs)) {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
962 density_grobs[[id]]$widths[1] <-
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
963 density_grobs[[id]]$widths[1] +
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
964 maxWidth - (density_grobs[[id]]$widths[2 + vs] +
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
965 maxYtextWidth)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
966 # fix problems ggplot2 vs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
967 density_grobs[[id]]$widths[3 + vs] <-
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
968 maxYtextWidth # fix problems ggplot2 vs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
969 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
970
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
971 # Heights for density, x axis and annotation
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
972 heights = unit.c(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
973 unit(rep(%(signal_height)s,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
974 length(density_list)), "in"),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
975 x.axis.height,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
976 unit(%(ann_height)s*%(args.gtf)s, "in")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
977 )
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
978
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
979 # Arrange grobs
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
980 argrobs = arrangeGrob(
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
981 grobs=density_grobs,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
982 ncol=1,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
983 heights = heights,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
984 );
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
985
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
986 # Save plot to file in the requested format
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
987 if ("%(out_format)s" == "tiff"){
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
988 # TIFF images will be lzw-compressed
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
989 ggsave("%(out)s",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
990 plot = argrobs,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
991 device = "tiff",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
992 width = width,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
993 height = height,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
994 units = "in",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
995 dpi = %(out_resolution)s,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
996 compression = "lzw")
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
997 } else {
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
998 ggsave("%(out)s",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
999 plot = argrobs,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1000 device = "%(out_format)s",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1001 width = width,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1002 height = height,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1003 units = "in",
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1004 dpi = %(out_resolution)s)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1005 }
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1006
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1007 dev.log = dev.off()
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1008
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1009 """ % ({
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1010 "out": "%s.%s" % (out_prefix, out_suffix),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1011 "out_format": args.out_format,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1012 "out_resolution": args.out_resolution,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1013 "args.gtf": float(bool(args.gtf)),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1014 "args.aggr": args.aggr.rstrip("_j"),
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1015 "signal_height": args.height,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1016 "ann_height": args.ann_height,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1017 "alpha": args.alpha,
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1018 })
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1019 if os.getenv('GGSASHIMI_DEBUG') is not None:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1020 with open("R_script", 'w') as r:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1021 r.write(R_script)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1022 else:
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1023 plot(R_script)
9304dd9a16a2 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sashimi_plot commit 746c03a1187e1d708af8628920a0c615cddcdacc"
artbio
parents:
diff changeset
1024 exit()