SAMsift - 筛选你的对齐方式
项目描述
SAMsift 是一个使用 Python 表达式对 SAM/BAM 对齐进行高级过滤和标记的程序。
入门
# clone this repo and add it to PATH
git clone http://github.com/karel-brinda/samsift
cd samsift
export PATH=$(pwd)/samsift:$PATH
# filtering: keep only alignments with score >94, save them as filtered.bam
samsift -i tests/test.bam -o filtered.bam -f 'AS>94'
# filtering: keep only unaligned reads
samsift -i tests/test.bam -f 'FLAG & 0x04'
# filtering: keep only aligned reads
samsift -i tests/test.bam -f 'not(FLAG & 0x04)'
# filtering: keep only sequences containing ACCAGAGGAT
samsift -i tests/test.bam -f 'SEQ.find("ACCAGAGGAT")!=-1'
# filtering: keep only sequences containing A and T only (defined using regular expressions)
samsift -i tests/test.bam -f 're.match(r"^[AT]*$", SEQ)'
# filtering: sample alignments with 25% rate
samsift -i tests/test.bam -f 'random.random()<0.25'
# filtering: sample alignments with 25% rate with a fixed RNG seed
samsift -i tests/test.bam -f 'random.random()<0.25' -0 'random.seed(42)'
# filtering: keep only alignments of reads specified in tests/qnames.txt
samsift -i tests/test.bam -0 'q=open("tests/qnames.txt").read().splitlines()' -f 'QNAME in q'
# filtering: keep only first 5000 reads from chr1 and 5000 reads from chr2
samsift -i tests/test.bam -0 'c={"chr1":5000,"chr2":5000}' -f 'c[RNAME]>0' -c 'c[RNAME]-=1' -m nonstop-remove
# tagging: add tags 'ln' with sequence length and 'ab' with average base quality
samsift -i tests/test.bam -c 'ln=len(SEQ);ab=1.0*sum(QUALa)/ln'
# tagging: add a tag 'ii' with the number of the current alignment
samsift -i tests/test.bam -0 'i=0' -c 'i+=1;ii=i'
# updating: removing sequences and base qualities
samsift -i tests/test.bam -c 'a.query_sequence=""'
# updating: switching all reads to unaligned
samsift -i tests/test.bam -c 'a.flag|=0x4;a.reference_start=-1;a.cigarstring="";a.reference_id=-1;a.mapping_quality=0'
安装
使用 Bioconda:
# add all necessary Bioconda channels
conda config --add channels defaults
conda config --add channels conda-forge
conda config --add channels bioconda
# install samsift
conda install samsift
使用 PyPI 中的 PIP:
pip install --upgrade samsift
使用来自 Github 的 PIP:
pip install --upgrade git+https://github.com/karel-brinda/samsift
命令行参数
Program: samsift (advanced filtering and tagging of SAM/BAM alignments using Python expressions)
Version: 0.2.5
Author: Karel Brinda <kbrinda@hsph.harvard.edu>
Usage: samsift.py [-i FILE] [-o FILE] [-f PY_EXPR] [-c PY_CODE] [-m STR]
[-0 PY_CODE] [-d PY_EXPR] [-t PY_EXPR]
Basic options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-i FILE input SAM/BAM file [-]
-o FILE output SAM/BAM file [-]
-f PY_EXPR filtering expression [True]
-c PY_CODE code to be executed (e.g., assigning new tags) [None]
-m STR mode: strict (stop on first error)
nonstop-keep (keep alignments causing errors)
nonstop-remove (remove alignments causing errors) [strict]
Advanced options:
-0 PY_CODE initialization [None]
-d PY_EXPR debugging expression to print [None]
-t PY_EXPR debugging trigger [True]
算法
exec(INITIALIZATION)
for ALIGNMENT in ALIGNMENTS:
if eval(DEBUG_TRIGER):
print(eval(DEBUG_EXPR))
if eval(FILTER):
exec(CODE)
print(ALIGNMENT)
Python 表达式和代码。所有表达式和代码都应该对Python 3有效。表达式使用eval 函数求值,代码使用exec函数执行。初始化可用于导入 Python 模块、设置全局变量(例如计数器)或从磁盘加载数据。一些模块(即 random和re)在没有明确请求的情况下加载。
示例(打印所有对齐):
samsift -i tests/test.bam -f 'True'
SAM 字段。表达式和代码可以访问从SAM 规范的对齐部分镜像字段的变量,即QNAME、FLAG、 RNAME、POS(基于 1)、MAPQ、CIGAR、RNEXT、PNEXT、 TLEN、SEQ和QUAL。定义了几个附加变量来简单地访问一些有用的信息:QUALa将基本质量存储为整数数组; SEQs , QUALs , QUALsa跳过软剪辑碱基;和RNAMEi和RNEXTi将参考 ID 存储为整数。
示例(仅保留最左边位置 <= 10000 的对齐方式):
samsift -i tests/test.bam -f 'POS<=10000'
SAMsift 在内部使用PySam库,当前对齐的表示(类 pysam.AlignedSegment的实例)可作为变量a 使用。因此,前面的例子等价于
samsift -i tests/test.bam -f 'a.reference_start+1<=10000'
a变量也可用于修改当前对齐记录。
示例(从每条记录中删除序列和碱基):
samsift -i tests/test.bam -c 'a.query_sequence=""'
SAM 标签。每个 SAM 标记都被转换为具有相同名称的变量。
示例(删除分数小于或等于序列长度的比对):
samsift -i tests/test.bam -f 'AS>len(SEQ)'
如果提供了CODE ,则除re (Python 正则表达式模块)之外的所有两个字母变量都将在代码执行后反向转换为标签。
示例(添加带有平均基础质量的标签ab ):
samsift -i tests/test.bam -c 'ab=1.0*sum(QUALa)/len(QUALa)'
错误。如果在计算表达式或执行代码期间发生错误(例如,由于访问未定义的标签),则 SAMsift 行为取决于指定的模式 ( -m )。使用严格模式(-m strict,默认值),SAMsift 将立即中断计算并报告错误。使用-m nonstop -keep选项,SAMsift 将继续处理对齐,同时将导致错误的对齐保留在输出中。使用-m nonstop-remove选项,从输出中跳过并省略所有导致错误的对齐。
类似的节目
samtools 视图可以根据 FLAGS、读取组标签和 CIGAR 字符串过滤对齐。
除了 SAMtools 之外, sambaMBA 视图还支持使用简单的类似 Perl 的表达式进行过滤。但是,不能使用浮点数或比较不同的标签。
BamQL提供了一种用于过滤 SAM/BAM 文件的简单查询语言。
bamPals添加标签 XB、XE、XP 和 XL。
SamJavascript可以使用 JavaScript 表达式过滤对齐。
Picard FilterSamReads还可以使用 JavaScript 表达式过滤对齐。
问题
请使用Github 问题。
变更日志
请参阅发布。
执照
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。