Beispiel #1
0
 def test_optionalthird(self):
     ''' Test that given a correct third argument it still runs '''
     infa = ungzip(INPUT_PATH)
     bwa.index_ref(REF_PATH)
     # I don't have a mates file so just use infa again
     mem = BWAMem(REF_PATH, infa, infa, bwa_path=BWA_PATH)
     eq_(0, mem.run())
Beispiel #2
0
def bwa_mem( read1, mate=None, ref=None, output='bwa.sai', **kwargs ):
    '''
        Runs the bwa mem algorithm on read1 against ref. If mate is given then run that file with the read1 file
        so paired alignment is done.

        TODO:
            bwa_path should be an option to specify where the executable is

        @param read1 - File path to read
        @param mate - Mate file path
        @param ref - Reference file path or directory of references
        @param output - The output destination

        @returns the output path if sucessful or -1 if something went wrong
    '''
    if os.path.isdir( ref ):
        # Compile ref directory
        logger.debug( "Compiling references inside of {0}".format(ref) )
        ref = compile_refs( ref )
        logger.info( "Refs are all compiled into {0}".format(ref) )

    # First, make sure the reference is indexed
    logger.debug( "Ensuring {0} is indexed".format(ref) )
    if not index_ref(ref):
        raise InvalidReference("{0} cannot be indexed by bwa")

    # Setup BWA Mem
    mem = None
    if mate:
        mem = BWAMem( ref, read1, mate, bwa_path=which_bwa(), **kwargs )
    else:
        mem = BWAMem( ref, read1, bwa_path=which_bwa(), **kwargs )

    ret = mem.run( output )
    print "Ret: " + str(ret)
    if ret != 0:
        return ret
    else:
        return output
Beispiel #3
0
def bwa_mem(read1, mate=None, ref=None, output='bwa.sai', **kwargs):
    '''
        Runs the bwa mem algorithm on read1 against ref. If mate is given then run that file with the read1 file
        so paired alignment is done.

        TODO:
            bwa_path should be an option to specify where the executable is

        @param read1 - File path to read
        @param mate - Mate file path
        @param ref - Reference file path or directory of references
        @param output - The output destination

        @returns the output path if sucessful or -1 if something went wrong
    '''
    if os.path.isdir(ref):
        # Compile ref directory
        logger.debug("Compiling references inside of {0}".format(ref))
        ref = compile_refs(ref)
        logger.info("Refs are all compiled into {0}".format(ref))

    # First, make sure the reference is indexed
    logger.debug("Ensuring {0} is indexed".format(ref))
    if not index_ref(ref):
        raise InvalidReference("{0} cannot be indexed by bwa")

    # Setup BWA Mem
    mem = None
    if mate:
        mem = BWAMem(ref, read1, mate, bwa_path=which_bwa(), **kwargs)
    else:
        mem = BWAMem(ref, read1, bwa_path=which_bwa(), **kwargs)

    ret = mem.run(output)
    print "Ret: " + str(ret)
    if ret != 0:
        return ret
    else:
        return output
Beispiel #4
0
 def test_ref_is_missing(self):
     r = bwa.index_ref('/path/to/missing.fa')
     eq_(r, False)
Beispiel #5
0
 def test_bwamem_run(self):
     ''' Make sure it actually runs bwa with correct input '''
     #infa = ungzip( INPUT_PATH )
     bwa.index_ref(self.fa2)
     mem = BWAMem(self.fa2, self.fa, bwa_path=BWA_PATH)
     eq_(0, mem.run())