Last active
December 27, 2017 23:43
-
-
Save mpkocher/783587aa2f7bc6652100942c95169f4f to your computer and use it in GitHub Desktop.
Example for extracting SubreadSet Bam files from a SMRT Link Job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import logging | |
import sys | |
from pbcommand.services import ServiceAccessLayer as S | |
from pbcore.io.dataset import SubreadSet | |
log = logging.getLogger(__name__) | |
def get_subreadset_path(client, dataset_id): | |
sset = client.get_subreadset_by_id(dataset_id) | |
return sset['path'] | |
def extract_from_sset(sset): | |
for f in sset.externalResources: | |
if f.metaType == 'PacBio.SubreadFile.SubreadBamFile': | |
yield f.resourceId | |
def get_and_extract_from_sset(client, dataset_id): | |
path = get_subreadset_path(client, dataset_id) | |
sset = SubreadSet(path) | |
for r in extract_from_sset(sset): | |
yield r | |
def get_bam_files_from_job_id(client, job_id): | |
# will fail if can't connect to server | |
status = client.get_status() | |
epts = client.get_analysis_job_entry_points(job_id) | |
sset_uuids = [e.dataset_uuid for e in epts if e.dataset_metatype == 'PacBio.DataSet.SubreadSet'] | |
for u in sset_uuids: | |
for r in get_and_extract_from_sset(client, u): | |
yield r | |
def example(): | |
job_id = 29212 | |
host = "smrtlink-alpha" | |
port = 8081 | |
client = S(host, port) | |
resources = list(get_bam_files_from_job_id(client, job_id)) | |
print "\n".join(resources) | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(example()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment