Notes from
Torrent SDK Documentation, Release 5.12.1.
1. Plugin System
1.1 入门
插件是通用分析流程的扩展,表现为在流程不同环节执行的python模块。
1.1.1 快速开始
'''
vi Myplugin/MyPlugin.py # 1.name; 2.code below
zip -r –exclude=*.git* mp.zip MyPlugin
upload, run
'''import subprocess
from ion.plugin import*classMyPlugin(IonPlugin):# Must inherit from the base class IonPlugin;# The version attribute and launch method need to be overridden;
version ="1.0.0.0"deflaunch(self, data=None):
output = subprocess.check_output(['ls','-l'])withopen("status_block.html","w")as h:
h.write("<html><body><pre>")
h.write(output)
h.write("</pre></body></html>")if __name__ =="__main__":
PluginCLI()
1.1.2 流程概览
Run levels
stage
PRE
before any significant processing happens
BLOCK
triggered once per block on the chip
POST
after the analysis pipeline is completely executed
DEFAULT
triggered at the end of pipeline processing after the four usual steps
LAST
executed after all other plugins that are not “LAST” have been executed
1.2 参考
1.2.1 Base class
Attribute Name
Required
Type
Default
Description
name
N
str
Empty
存放插件名
version
Y
str
Empty
版本号
runtypes
N
list(str)
Empty
用于整张芯片或缩略
runlevels
Y
list(str)
Empty
运行等级
features
N
list(str)
Empty
功能特性
depends
N
list(str)
Empty
依赖的插件
major_block
N
boolean
False
插件结果是否作为运行报告的一部分
startplugin
N
dictionary
None
返回startplugin.json内存字典中的 “an”
Method Name
Required
Return Type
Description
launch
Y
boolean
插件结果是否作为运行报告的一部分
pre_launch
N
boolean
是否在launch前运行
barcodetable_columns
N
list
generate the plugin barcodes table ui
barcodetable_data
N
dictionary
populate the contents of the plugin barcodes table ui
# plugin class method to specify which columns to displaydefbarcodetable_columns(self):
cols=[{"field":"selected","editable":True},{"field":"barcode_name","editable":True},{"field":"sample","editable":False}]return cols
# plugin class method to specify default table contentsdefbarcodetable_data(self, data, planconfig={}, globalconfig={}):## data: same structure as in barcodes.json## planconfig: plugin configuration from planning (plan.html)## globalconfig:plugin global configuration (config.html)return data
The instance.html must add the contents of barcodes table to the plugin data before POSTing it to the results API. This data will be written to startplugin.json file at plugin runtime under “pluginconfig” section.
1.2.4 输入文件
barcodes.json
nonbarcoded
keys
type
describe
aligned
bool
标识bam_file中的reads是否已比对到参考基因组
bam_file
str
存储reads的文件名
bam_filepath
str
bam_file在服务器上的路径
control_sequence_type
str
(RNA测序)ERCC Mix 1 or ERCC Mix2
filtered
bool
标识barcode是否通过了TS分析流程过滤
hotspot_filepath
str
热点目标区域文件(BED格式)在服务器上的路径
genome_urlpath
str
基因组的URL地址
nucleotide_type
str
DNA或RNA
read_count
int
barcode在bam_file中的总数
reference
str
参考基因组的常用名,如hg19
reference_fullpath
str
参考序列的全路径
sample
str
和barcode关联的样本名
sample_id
str
和sample关联的样本ID
target_region_filepath
str
靶向区域文件(BED格式)的全路径
barcode_name - nonbarcoded
keys
type
describe
barcode_adapter
str
从测序read中区分barcode_sequence的接头序列
barcode_annotation
str
用户对barcode的注释
barcode_index
int
barcode在barcode集中的索引
barcode_name
str
barcode在barcode集中的名字
barcode_sequence
str
用于标识barcode的DNA序列
barcode_type
str
用户指定的类型
startplugin.json
keys
type
describe
chefSummaary
dict
chef parameters used
keys
type
describe
datamanagement
dict
data management state
__Basecalling Input
bool
__Intermediate Files
bool
__Output Files
bool
__Signal Processing Input
bool
keys
type
describe
expmeta
dict
aggregate from the expMeta.dat file and the ion_params_00.json file
__analysis_date
date
__barcodeId
str
__chipBarcode
str
__chiptype
__flowOrder
__instrument
__notes
__project
__results_name
__run_date
__run_flows
__run_name
__runid
__sample
__output_file_name_stem
keys
type
describe
globalconfig
__MEM_MAX
__debug
keys
type
describe
plan
__barcodeId
__barcodedSamples
____Sample Name
______-Sample Name-
________barcodeSampleInfo
__________-Barcode ID-
____________controlSequenceType
____________controlType
____________description
____________externalId
____________hotSpotRegionBedFile
____________nucleotideType
____________reference
____________sseBedFile
____________targetRegionBedFile
________barcodes
__bedfile
__controlSequencekitname
__librarykitname
__planName
__regionfile
__reverse_primer
__runMode
__runType
__runTypeDescription
__sampleGrouping
__samplePrepKitName
__sampleSet_name
__sampleSet_planIndex
__sampleSet_planTotal
__sampleSet_uid
__sampleTubeLabel
__sequencekitname
__templatingKitName
__threePrimeAdapter
__username
keys
type
describe
runinfo
dict
测序run的信息
__alignment_dir
str
比对数据的文件夹路径
__analysis_dir
str
__api_key
str
用于访问
__api_url
__barcodeId
__basecaller_dir
__chipDescription
__chipType
__library
__library_key
__net_location
__pk
__platform
__plugin
dict
the run parameters for this plugin in this run
____depends
list
该插件本次运行所依赖的插件
____features
list
该插件的功能
____hold_jid
list
处理所需的 job ID
____id
int
插件ID的数据库主键
____name
str
该插件的名字
____path
str
该插件可执行文件的路径
____pluginconfig
dict
插件运行的全局配置信息
____pluginresult
int
插件结果entry的数据库主键
____results_dir
str
插件分析结果的目录路径
____runlevel
list
运行层次
____runtype
list
运行类型
____userInput
dict
插件运行的配置信息
____version
str
插件版本
__plugin_dir
__plugin_name
__pluginresult
__raw_data_dir
__report_root_dir
__results_dir
__sigproc_dir
__systemType
__testfrag_key
__tmap_version
__url_root
__username
____runplugin
______blockId
______block_dirs
______numBlocks
______run_mode
______run_type
____runlevel
__sampleinfo
____SampleName
______attributes
______description
______displayedName
______externalId
______name
____pluginconfig
Seq Files (BAMs)
barcodes.json >> bam_filepath
1.2.5 输出文件
The report HTML file (*_block.(html|php))
A log file (drmaa_stdout.txt)
1.3 示例
1.3.1 basic
# LogParserimport json,os
from django.utils.functional import cached_property
from ion.plugin import*classlogParser(IonPlugin):
version ="0.1.0.0"
@cached_property
defstartplugin_json(self):return self.startplugin
defread_explog(self):
path = os.path.join(self.startplugin_json['runinfo']['raw_data_dir'],'explog_final.txt')ifnot os.path.exists(path):raise Exception("explog_final.txt not found")
md ={}for l inopen(path):
ll = l.split(":",1)iflen(ll)==2:
k,v = ll
md[k.strip()]= v.strip()return md
deflaunch(self, data=None):
na ='<strong>NA</strong>'
explog = self.read_explog()
result ={'Sample':explog.get('Sample',None)or na}withopen(self.startplugin_json['runinfo']['results_dir']+'/LogParser_block.html','w')as ha:
ha.write('<html><body>')
ha.write("Sample is %s<br >"% result['Sample'])
ha.write("</body></hmtl>")withopen(self.startplugin_json['runinfo']['results_dir']+'/results.json','w')as ha:
json.dump(result, ha, indent=4)returnTrueif __name__ =="__main__":
PluginCLI()
# subprocessfrom subprocess import check_output
import json
import os
from django.utils.functional import cached_property
from ion.plugin import*classCallSubprocessExample(IonPlugin):
version ="5.4.0.0"
runtypes =[RunType.FULLCHIP, RunType.THUMB, RunType.COMPOSITE]
runlevels =[RunLevel.DEFAULT]
@cached_property
defstartplugin_json(self):return self.startplugin
deflaunch(self, data=None):"""This is the primary launch method for the plugin."""
path_to_executable ="MyExecutable"
arg1 ='First Argument'
arg2 ='Second Argument'
results = check_output([path_to_executable, arg1, arg2],cwd=self.startplugin_json['runinfo']['plugin']['path'])returnTrueif __name__ =="__main__":
PluginCLI()
# access barcode dataimport json
import os
from django.utils.functional import cached_property
from ion.plugin import*from subprocess import check_output
classBarcodesExample(IonPlugin):
version ="5.4.0.0"
runtypes =[RunType.FULLCHIP, RunType.THUMB, RunType.COMPOSITE]
runlevels =[RunLevel.DEFAULT]
@cached_property
defstartplugin_json(self):return self.startplugin
@cached_property
def barcodes_json:withopen('barcodes.json','r')as barcodes_handle:return json.load(barcodes_handle)deflaunch(self, data=None):"""This is the primary launch method for the plugin."""for barcode_name, barcode_values in self.barcodes_json.iteritems():print("Barcode Name: "+ barcode_name)print("Bam File: "+ barcode_values['bam_file']returnTrueif __name__ =="__main__":
PluginCLI()
发表评论 取消回复