Exemplo n.º 1
0
 def test_outputdiraleady( self ):
     ''' Output directory already created '''
     outdir = self.tempdir
     results = demultiplex.demultiplex( self.fp, outdir, self.rf, self.mp, self.sffc )
     # Get region list
     expected_dirs = [str(int(os.path.splitext(n)[0][-2:])) for n in fixtures.multiplex_sffs()]
     # Ensure output directory created
     common.ere( True, os.path.isdir( outdir ) )
     # Ensure region directories
     common.ere( expected_dirs, os.listdir( outdir ) )
     # Ensure results are correct
     common.ere( self.rdl, results )
Exemplo n.º 2
0
 def test_singleinputsff( self ):
     ''' Make sure single sff works '''
     multiplex_files = fixtures.multiplex_sffs().items()
     sfffile = multiplex_files[0][0]
     expect = os.path.join( self.tempdir, 'sff', sfffile )
     os.mkdir( 'sff' )
     # symlink in a fixture sff file
     os.symlink( multiplex_files[0][1], expect )
     outdir = os.path.join( self.tempdir, 'test' )
     results = demultiplex.demultiplex( 'sff', outdir, self.rf, self.mp, self.sffc )
     expected_dirs = [str(int(os.path.splitext(expect)[0][-2:]))]
     common.ere( expected_dirs, os.listdir( outdir ) )
     common.ere( {sfffile:self.rdl[sfffile]}, results )
Exemplo n.º 3
0
 def test_singleinputsff(self):
     ''' Make sure single sff works '''
     multiplex_files = fixtures.multiplex_sffs().items()
     sfffile = multiplex_files[0][0]
     expect = os.path.join(self.tempdir, 'sff', sfffile)
     os.mkdir('sff')
     # symlink in a fixture sff file
     os.symlink(multiplex_files[0][1], expect)
     outdir = os.path.join(self.tempdir, 'test')
     results = demultiplex.demultiplex('sff', outdir, self.rf, self.mp,
                                       self.sffc)
     expected_dirs = [str(int(os.path.splitext(expect)[0][-2:]))]
     common.ere(expected_dirs, os.listdir(outdir))
     common.ere({sfffile: self.rdl[sfffile]}, results)
Exemplo n.º 4
0
 def test_outputdiraleady(self):
     ''' Output directory already created '''
     outdir = self.tempdir
     results = demultiplex.demultiplex(self.fp, outdir, self.rf, self.mp,
                                       self.sffc)
     # Get region list
     expected_dirs = [
         str(int(os.path.splitext(n)[0][-2:]))
         for n in fixtures.multiplex_sffs()
     ]
     # Ensure output directory created
     common.ere(True, os.path.isdir(outdir))
     # Ensure region directories
     common.ere(expected_dirs, os.listdir(outdir))
     # Ensure results are correct
     common.ere(self.rdl, results)
Exemplo n.º 5
0
class TestDemultiplexSff(common.BaseClass):
    sffs = fixtures.multiplex_sffs()
    rf = RunFile(fixtures.RUNFILE_PATH)
    expected_read_list = fixtures.demultiplex_reads_lst()
    sfffilecmd = which('sfffile')

    def setUp(self):
        super(TestDemultiplexSff, self).setUp()

    def test_ensureabspath(self):
        ''' sfffile, midparsefile, sfffilecmd and outputdir all need to abspaths '''
        try:
            demultiplex.demultiplex_sff('sfffile', 'MidParse.conf', ['Mid1'],
                                        'sfffilecmd', 'outputdir')
            assert False, 'Should have raised exception as there is a non abspath'
        except ValueError as e:
            assert True

    def test_outputdir_notexist(self):
        ''' Make sure outputdir gets created if it doesn't exist '''
        sffn, sffp = self.sffs.items()[0]
        try:
            demultiplex.demultiplex_sff(sffp, fixtures.MIDPARSE, ['Mid1'],
                                        self.sfffilecmd, 'outputdir')
            assert True
        except OSError as e:
            assert False, 'Output dir didn\'t exist and threw an error which is incorrect'

    def test_emptymidlist(self):
        ''' Empty midlist should raise exception '''
        try:
            demultiplex.demultiplex_sff('', '', [], '', '')
            assert False, 'Empty midlist did not raise exception'
        except ValueError as e:
            assert True

    def test_midlist_missing(self):
        sffn, sffp = self.sffs.items()[0]
        reg = int(sffn.replace('.sff', '')[-2:])
        process = demultiplex.demultiplex_sff(sffp, fixtures.MIDPARSE,
                                              self.rf[reg].keys() + ['RL99'],
                                              self.sfffilecmd, self.tempdir)
        stdout, stderr = process.communicate()
        read_lst = self.expected_read_list[sffn.replace('.sff', '.lst')]
        with open(read_lst) as fh:
            result = fh.read(
            ) + '  ' + fixtures.MIDPREFIX + 'RL99:  0 reads found\n'
            common.erdiff(result, stdout)

    def test_midlist_missingrev(self):
        ''' Make sure only midkey list barcodes are extracted '''
        sffn, sffp = self.sffs.items()[0]
        reg = int(sffn.replace('.sff', '')[-2:])
        keys = demultiplex.sort_midlist(self.rf[reg].keys())[:-2]
        process = demultiplex.demultiplex_sff(sffp, fixtures.MIDPARSE, keys,
                                              self.sfffilecmd, self.tempdir)
        stdout, stderr = process.communicate()
        read_lst = self.expected_read_list[sffn.replace('.sff', '.lst')]
        with open(read_lst) as fh:
            expect = "".join(fh.readlines()[:-2])
            common.erdiff(expect, stdout)

    def test_demultiplex_sff(self):
        ''' Should match expected output from fixtures '''
        for sffn, sffp in self.sffs.items():
            reg = int(sffn.replace('.sff', '')[-2:])
            read_lst = self.expected_read_list[sffn.replace('.sff', '.lst')]
            process = demultiplex.demultiplex_sff(sffp, fixtures.MIDPARSE,
                                                  self.rf[reg].keys(),
                                                  self.sfffilecmd,
                                                  self.tempdir)
            stdout, stderr = process.communicate()
            with open(read_lst) as fh:
                common.erdiff(fh.read(), stdout)