> For the complete documentation index, see [llms.txt](https://zpliu.gitbook.io/booknote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zpliu.gitbook.io/booknote/ke-bian-jian-qie/di-wu-ci-fen-xi/hui-zhi-ke-bian-jian-qie.md).

# rmats2sashimiplot

**rmats2sashimiplot**可以直接将`rMATS`的输出结果绘制图片，同样也可以使用基因组的注释文件个基因组坐标绘制。

### 准备使用matplotlib绘制基因结构

> 参考 ：<http://www.biotrainee.com/thread-624-1-1.html>

### 安装依赖

* Python 2.7 (Python 3 can be used after running 2to3.sh)
  * numpy
  * scipy
  * matplotlib
  * pysam
* Samtools
* bedtools

> 如果想在python3中运行软件的话，直接使用运行`2to3.sh`这个脚本转换一下

脚本不需要编译就能直接使用，当然也可以运行`python ./setup.py install`后直接`rmats2sashimiplot`即可运行脚本

### 使用BAM文件的坐标和基因注释文件绘图

> BAM文件需要安装染色体坐标排好序，不然`samtools index`的时候会报错

```bash
python3 ~/github/rmats2sashimiplot/src/rmats2sashimiplot/rmats2sashimiplot.py  -h
```

对rmats的结果进行可视化，默认是绘制所有的事件的，也可以绘制单个事件

> 绘制单个Exon Skip事件, 由于这里只有单个样品，为了画图可以指定sample1和sample2一样，最后画出两幅一样的图；
>
> 也可以使用

* `--b1` 安装染色体位置排好序的BAM
* `-t` 剪切事件类型
* `-e` 对应的剪切事件文件
* `--l1`显示第一个样品的label
* -o 输出文件夹
* `--hide-number` 不显示BAM文件中的read数目
* `--color`指定配色风格

```bash
##提取对应事件的文件，文件必须要包含表头
head -2 ../out2/SE.MATS.JCEC.txt  >test.txt
##绘制图片，指定多个replicate bam，用逗号隔开
python3 ~/github/rmats2sashimiplot/src/rmats2sashimiplot/rmats2sashimiplot.py --b1 ../tmp/bam1_1/Aligned.sortedByCoord.out.bam,../tmp/bam1_2/Aligned.sortedByCoord.out.bam --b2  ../tmp/bam1_1/Aligned.sortedByCoord.out.bam,../tmp/bam1_2/Aligned.sortedByCoord.out.bam -t SE -e test.txt   --l1 '' --l2 '' -o ./ --group-info  group.txt
```

### 合并两个重复

`--group-info grouping.gf`

文件内容如下：

> As an example: --b1 a.bam,b.bam,c.bam --b2 d.bam,e.bam,f.bam with this grouping file
>
> ```bash
> firstGroup: 1,4
> secondGroup: 1-3,5,6
> ```
>
> Defines firstGroup=a.bam,d.bam and secondGroup=a.bam,b.bam,c.bam,e.bam,f.bam

这里有两个一样的分组，并且分组的名字叫`evm.TU.Ga14G2881`，BAM文件分别是第一个、第二个。

```bash
evm.TU.Ga14G2881: 1,2
evm.TU.Ga14G2881: 3,4
```

> 当有两个sample要进行比较，而每个sample中又有多个replicate的时候，可以将每个sample中的重复进行合并，然后计算sample中的`average inclusion level`

### Y轴的意义

Y轴是`represents a modified RPKM value.`，但是从计算公式来看这三个指标没啥区别

![计算公式](https://s1.ax1x.com/2020/08/05/asoKCn.png)

图片上的数字表示支持该事件的read数目

## 参考

1. <https://github.com/Xinglab/rmats2sashimiplot#examples>
