module

biopipen.utils.reference

Utilities for indexing reference files

Functions
  • bam_index(bam, bamdir, tool, samtools, sambamba, ncores, ext, force) Index a bam file</>
  • tabix_index(infile, preset, tmpdir, tabix) (str | os.pathlike) Index input file using tabix</>
function

biopipen.utils.reference.tabix_index(infile, preset, tmpdir=None, tabix='tabix')

Index input file using tabix

  1. Try to check if there is an index file in the same directory where infile is.
  2. If so, return the infile
  3. Otherwise, check if infile is bgzipped, if not bgzip it and save it in tmpdir
  4. Index the bgzipped file and return the bgzipped file
Parameters
  • infile (str | os.pathlike) The input file to be indexed
  • preset (Literal) The preset used to index the file
  • tmpdir (bool | str | os.pathlike | none, optional) The directory to link the infile there and index itIf False, try to index the infile directly. The directory where the infile is should be writable.
  • tabix (str, optional) The path to tabix
Returns (str | os.pathlike)

The infile itself or re-bgzipped infile. This file comes with theindex file in the same directory

function

biopipen.utils.reference.bam_index(bam, bamdir='/tmp', tool='samtools', samtools='samtools', sambamba='sambamba', ncores=1, ext='.bam.bai', force=False)

Index a bam file

First look for the index file in the same directory as the bam file, if found, return the bam file. Otherwise, generate a symbolic link of the bam file in bamdir, and generate a index there, return the path to the symbolic link

Parameters
  • bam The path to the bam file
  • bamdir (optional) If index file can't be found in the directory as the bam file,create a symbolic link to the bam file, and generate the index here
  • tool (optional) The tool used to generate the index file, either samtools orsambamba
  • samtools (optional) The path to samtools
  • sambamba (optional) The path to sambamba
  • ncores (optional) Number of cores (threads) used to generate the index file
  • ext (optional) The ext of the index file, default .bam.bai, in case, .bai isalso treated as index file
  • force (optional) Force to generate the index file, with given bamfile.Don't check if the index file exists.
Returns

The bam file if index exists in the directory as the bam file.Otherwise symbolic link to the bam file in bamdir.