Skip to content

Commit

Permalink
Proof of concept for getting the header of a given SAM, BAM, CRAM. Al…
Browse files Browse the repository at this point in the history
…lowing us to more dynamically populate a template without explicity asking for metadata.
  • Loading branch information
bryce-turner committed Nov 8, 2023
1 parent e9dd199 commit bad7787
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions jetstream/templates.py
Expand Up @@ -146,15 +146,26 @@ def fromjson(value):

def env(value):
return os.environ[value]


def getenv(value, default=None):
return os.environ.get(value, default)


def setenv(key, value):
os.environ[key] = value
return ''
return ''


def get_sam_header(path):
"""This is an advanced function that is optionally available if pysam is
installed. This returns the header of a sam, bam, or cram as a dictionary."""
try:
import pysam
except (ImportError, ModuleNotFoundError):
print('This template is attempting to use pysam, but pysam is not installed')
with pysam.AlignmentFile(path, 'rb', check_sq=False) as f:
return f.header.to_dict()


def environment(*searchpath, strict=True, trim_blocks=True, lstrip_blocks=True):
Expand Down

0 comments on commit bad7787

Please sign in to comment.