view novo_sort.py @ 4:146641fe5ff6 draft

planemo upload for repository https://github.com/zipho/novo_sort commit 0bb684bfc6b3f1f07105117dfd71285ce4ff7f4e
author sanbi-uwc
date Fri, 01 Apr 2016 10:15:24 -0400
parents 9c51aca51902
children 6e11ef75c56c
line wrap: on
line source

#!/usr/bin/env python
from __future__ import print_function
import argparse
from subprocess import check_call, CalledProcessError
import shlex
import sys
import logging
log = logging.getLogger( __name__ )

def novo_sort( bam_filename, output_filename ):
    cmdline_str = "novosort -c 8 -m 8G -s -f {} > {}".format( bam_filename, output_filename )
    cmdline = newSplit(cmdline_str)
    try:
        check_call(cmdline)
    except CalledProcessError:
        print("Error running the nova-sort", file=sys.stderr)

def newSplit(value):
    lex = shlex.shlex(value)
    lex.quotes = '"'
    lex.whitespace_split = True
    lex.commenters = ''
    return list(lex)

def main():
    parser = argparse.ArgumentParser(description="Re-sorting aligned files by read position")
    parser.add_argument('output_filename')
    parser.add_argument('--bam_filename')
    args = parser.parse_args()
   
    novo_sort(args.bam_filename, output_filename)

if __name__ == "__main__": main()