Pysam
This applet performs a SAMtools count on an input BAM using Pysam, a python wrapper for SAMtools.
Last updated
Was this helpful?
This applet performs a SAMtools count on an input BAM using Pysam, a python wrapper for SAMtools.
Last updated
Was this helpful?
Pysam is provided through a pip3 install
using the pip3 package manager in the dxapp.json
’s runSpec.execDepends
property:
The execDepends
value is a JSON array of dependencies to resolve before the applet source code is run. In this applet, we specify pip3
as our package manager and pysam version 0.15.4
as the dependency to resolve.
The fields mappings_sorted_bam
and mappings_sorted_bai
are passed to the main function as parameters for our job. These parameters are dictionary objects with key-value pair {"$dnanexus_link": "<file>-<xxxx>"}
. We handle file objects from the platform through handles. If an index file is not supplied, then a *.bai
index will be created.
Pysam provides several methods that mimic SAMtools commands. In our applet example, we want to focus only on canonical chromosomes. Pysam’s object representation of a BAM file is pysam.AlignmentFile
.
The helper function get_chr
Once we establish a list of canonical chromosomes, we can iterate over them and perform Pysam’s version of samtools view -c
, pysam.AlignmentFile.count
.
Our summarized counts are returned as the job output. We use the dx-toolkit
python SDK’s function to upload and generate a DXFile corresponding to our tabulated result file.
Python job outputs have to be a dictionary of key-value pairs, with the keys being job output names as defined in the dxapp.json
file and the values being the output values for corresponding output classes. For files, the output type is a DXLink. We use the function to generate the appropriate DXLink value.