示例#1
0
    def test_symlinksymlink(self):
        f = 'somefile.txt'
        s1 = join('sym1', f)
        s2 = join('sym2', f)
        os.mkdir('sym1')
        os.mkdir('sym2')
        touch(f)

        # s1 link to f
        os.symlink(join('..', f), s1)
        # s2 link to s1
        os.symlink(join('..', 'sym1', f), s2)
        ok_(exists(s1))
        ok_(exists(s2))
        ok_(exists(f))
        print compat.check_output('find ' + self.tempdir +
                                  ' -exec ls -ld {} \;',
                                  shell=True)

        # Try to rename a symlink -> symlink -> file
        self._C(s2, 'somefile', 'some1')

        print compat.check_output('find ' + self.tempdir +
                                  ' -exec ls -ld {} \;',
                                  shell=True)
        ok_(exists(join('sym2', 'some1.txt')), 'Did not rename sym2 file')
        ok_(exists(join('sym1', 'some1.txt')), 'Did not rename sym1 file')
        ok_(exists('some1.txt'), 'Did not rename actual file')
示例#2
0
def make_project_repo( projpath ):
    '''
    Turn a project into a git repository. Basically just git init a project path
    '''
    gitdir = os.path.join( projpath, '.git' )
    cmd = ['git', '--work-tree', projpath, '--git-dir', gitdir, 'init']
    output = compat.check_output( cmd, stderr=subprocess.STDOUT )
    logger.debug( output )
示例#3
0
def make_project_repo(projpath):
    '''
    Turn a project into a git repository. Basically just git init a project path
    '''
    gitdir = os.path.join(projpath, '.git')
    cmd = ['git', '--work-tree', projpath, '--git-dir', gitdir, 'init']
    output = compat.check_output(cmd, stderr=subprocess.STDOUT)
    logger.debug(output)
示例#4
0
 def check_git_repo( self, path ):
     gitdir = join( path, '.git' )
     cmd = 'git status status'.format( path, gitdir )
     try:
         output = compat.check_output( cmd, cwd=path, stderr=subprocess.STDOUT, shell=True )
         return 'Not a git repository' not in output
     except subprocess.CalledProcessError as e:
         print e.output
         return False
示例#5
0
def rsync_run( rundir, ngsdata ):
    # No trailing /
    src = normpath( rundir )
    # Dst will end in MiSeq since we removed the trailing / in src
    dst = join( ngsdata, 'RawData', 'MiSeq' )
    logger.info( 'The fastq read data is synced. Syncing the rest of the data' )
    cmd = 'rsync -av --progress --size-only {0} {1}'.format( src, dst )
    cmd = shlex.split( cmd )
    logger.debug( compat.check_output( cmd ) )
示例#6
0
 def check_git_repo( self, path ):
     gitdir = join( path, '.git' )
     cmd = 'git status status'.format( path, gitdir )
     try:
         output = compat.check_output( cmd, cwd=path, stderr=subprocess.STDOUT, shell=True )
         return 'Not a git repository' not in output
     except subprocess.CalledProcessError as e:
         print e.output
         return False
示例#7
0
    def run_vcf_diff(self, vcffile, *args, **kwargs):
        import subprocess
        script = 'vcf_diff'

        cmd = [script, vcffile]
        print "Running {0}".format(' '.join(cmd))
        try:
            return compat.check_output(cmd, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            return e.output
示例#8
0
    def run_vcf_diff( self, vcffile, *args, **kwargs ):
        import subprocess
        script = 'vcf_diff'

        cmd = [script,vcffile]
        print "Running {0}".format(' '.join(cmd))
        try:
            return compat.check_output( cmd, stderr=subprocess.STDOUT )
        except subprocess.CalledProcessError as e:
            return e.output
示例#9
0
 def get_numreads(self, bam):
     try:
         out = compat.check_output(
             'samtools flagstat {0} | head -1 | cut -d\' \' -f 1'.format(
                 bam),
             shell=True)
     except subprocess.CalledProcessError as e:
         print e.output
         print e
         raise e
     nreads = int(out)
     return nreads
示例#10
0
 def _rungraphsample( self, bamfile, **kwargs ):
     script_path = 'graphsample'
     args = ' '.join( ['-{0} {1}'.format(aname,aval) for aname, aval in kwargs.items()] )
     cmd = script_path + ' {0} '.format(bamfile) + args
     print "Running: {0}".format(cmd)
     cmd = shlex.split( cmd )
     try:
         sout = check_output( cmd, stderr=STDOUT )
     except CalledProcessError as e:
         print e.output
         assert False
     return sout
示例#11
0
 def run_script(self, script):
     print "Running {0}".format(script)
     fh = open('/tmp/test_run.txt', 'w')
     fh.write('Running {0}'.format(script))
     try:
         out = compat.check_output(script,
                                   stderr=subprocess.STDOUT,
                                   shell=True)
         fh.write(out)
         fh.close()
         return (0, out)
     except subprocess.CalledProcessError as e:
         return (e.returncode, e.output)
示例#12
0
 def _rungraphsample(self, bamfile, **kwargs):
     script_path = 'graphsample'
     args = ' '.join(
         ['-{0} {1}'.format(aname, aval) for aname, aval in kwargs.items()])
     cmd = script_path + ' {0} '.format(bamfile) + args
     print "Running: {0}".format(cmd)
     cmd = shlex.split(cmd)
     try:
         sout = check_output(cmd, stderr=STDOUT)
     except CalledProcessError as e:
         print e.output
         assert False
     return sout
示例#13
0
 def _run_cmd(self, jsons, outpath=None):
     script_path = 'graph_mapunmap'
     args = ' '.join(jsons)
     if outpath is not None:
         args += ' -o {0}'.format(outpath)
     cmd = script_path + ' {0} '.format(args)
     print "Running: {0}".format(cmd)
     cmd = shlex.split(cmd)
     try:
         sout = check_output(cmd, stderr=STDOUT)
     except CalledProcessError as e:
         print e.output
         assert False
     return sout
示例#14
0
 def _run_cmd( self, jsons, outpath=None ):
     script_path = 'graph_mapunmap'
     args = ' '.join( jsons )
     if outpath is not None:
         args += ' -o {0}'.format(outpath)
     cmd = script_path + ' {0} '.format(args)
     print "Running: {0}".format(cmd)
     cmd = shlex.split( cmd )
     try:
         sout = check_output( cmd, stderr=STDOUT )
     except CalledProcessError as e:
         print e.output
         assert False
     return sout
示例#15
0
    def test_symlinksymlink( self ):
        f = 'somefile.txt'
        s1 = join( 'sym1', f )
        s2 = join( 'sym2', f )
        os.mkdir( 'sym1' )
        os.mkdir( 'sym2' )
        touch(f)

        # s1 link to f
        os.symlink( join('..',f), s1 )
        # s2 link to s1
        os.symlink( join('..','sym1',f), s2 )
        ok_(exists(s1))
        ok_(exists(s2))
        ok_(exists(f))
        print compat.check_output('find '+self.tempdir+' -exec ls -ld {} \;',shell=True)

        # Try to rename a symlink -> symlink -> file
        self._C( s2, 'somefile', 'some1' )
    
        print compat.check_output('find '+self.tempdir+' -exec ls -ld {} \;',shell=True)
        ok_( exists( join('sym2','some1.txt') ), 'Did not rename sym2 file' )
        ok_( exists( join('sym1','some1.txt') ), 'Did not rename sym1 file' )
        ok_( exists( 'some1.txt' ), 'Did not rename actual file' )
示例#16
0
 def _run_runsample( self, readdir, reference, fileprefix, od=None, configfile=None,qsubargs=[] ):
     script_path = 'runsample'
     cmd = script_path + ' {0} {1} {2}'.format(readdir, reference, fileprefix)
     if od is not None:
         cmd += ' -od {0}'.format(od)
     if configfile:
         cmd += ' -c {0}'.format(configfile)
     if qsubargs:
         cmd += ' {0}'.format(' '.join(qsubargs))
     print "Running: {0}".format(cmd)
     cmd = shlex.split( cmd )
     try:
         sout = compat.check_output( cmd, stderr=subprocess.STDOUT )
     except subprocess.CalledProcessError as e:
         return (e.output,-1)
     return sout,0
示例#17
0
 def _run_runsample( self, readdir, reference, fileprefix, od=None, configfile=None,qsubargs=[] ):
     script_path = 'runsample'
     cmd = script_path + ' {0} {1} {2}'.format(readdir, reference, fileprefix)
     if od is not None:
         cmd += ' -od {0}'.format(od)
     if configfile:
         cmd += ' -c {0}'.format(configfile)
     if qsubargs:
         cmd += ' {0}'.format(' '.join(qsubargs))
     print "Running: {0}".format(cmd)
     cmd = shlex.split( cmd )
     try:
         sout = compat.check_output( cmd, stderr=subprocess.STDOUT )
     except subprocess.CalledProcessError as e:
         return (e.output,-1)
     return sout,0
示例#18
0
def run_trimmomatic( *args, **kwargs ):
    '''
        Runs trimmomatic
        @param arg0 - SE|PE -- Only SE supported at this time
        @param arg1-arg6 - Input/Ouput files
        @param arg7-argN - Tuples of (Trimmomatic Step,Options)
        @param kwargs are any --options

        run_trimmomatic( 'SE', 'input.fq', 'output.fq', ('LEADING','20), ('TRAILING','20'), trim_log='out.log' )
        would result in
        java -jar trimmomatic.jar input.fq output.fq LEADING:20 TRAILING:20 --trim_log out.log
    '''
    if args[0] == 'SE':
        inputs = [args[1]]
        outputs = [args[2]]
        # Trimmomatic doesn't seem to be able to detect Sanger quality encoding
        # so we will try to force it here to phred33
        if data.is_sanger_readfile(args[1]):
            kwargs['phred33'] = ''
        steps = args[3:]
    elif args[0] == 'PE':
        inputs = list(args[1:3])
        outputs = list(args[3:7])
        steps = args[7:]
    else:
        raise ValueError( 'SE or PE need to be supplied' )

    # Change all steps to strings of STEPNAME:VALUE
    steps = [':'.join([str(x) for x in s]) for s in steps]
    # Set all options
    primer_info = kwargs.pop('primer_info', None)
    options = shlex.split( ' '.join( ['-{0} {1}'.format(k,v) for k,v in kwargs.items()] ) )
    cmd = ['trimmomatic', args[0]] + options + inputs + outputs + steps

    if primer_info and primer_info[0]: # primer file was passed
        cmd += [':'.join(['ILLUMINACLIP'] + primer_info)]


    # Write stdout to output argument(should be fastq)
    # Allow us to read stderr which should be stats from cutadapt
    logger.debug( "Running {0}".format(' '.join(cmd)) )
    try:
        output = compat.check_output( cmd, stderr=subprocess.STDOUT )
        return output
    except subprocess.CalledProcessError as e:
        logger.critical( "Trimmomatic error: {0}".format(e.output) )
        raise e
示例#19
0
    def test_handles_sff( self ):
        sff = glob( join( fixtures.THIS, 'fixtures', 'reads', '*.sff' ) )[0]
        shutil.copy( sff, 'expected/reads' )
        sff = join( 'expected', 'reads', basename( sff ) )

        print "All files in expected directory:" + str( glob( 'expected/*' ) )
        ff = self.fixture_files
        argv = ['expected/reads', ff['REF']]
        self._CM( argv )
        r = 'bwa_mem.bam'
        assert os.stat(r)
        import subprocess
        out = compat.check_output( ['samtools', 'view', '{0}'.format(r)] )
        rochecount = out.count( 'IA52U1' )
        print rochecount
        eq_( 100, rochecount, 'Sff file reads did not make it into bam file' )

        os.unlink( sff )
示例#20
0
    def test_handles_sff(self):
        sff = glob(join(fixtures.THIS, 'fixtures', 'reads', '*.sff'))[0]
        shutil.copy(sff, 'expected/reads')
        sff = join('expected', 'reads', basename(sff))

        print "All files in expected directory:" + str(glob('expected/*'))
        ff = self.fixture_files
        argv = ['expected/reads', ff['REF']]
        self._CM(argv)
        r = 'bwa_mem.bam'
        assert os.stat(r)
        import subprocess
        out = compat.check_output(['samtools', 'view', '{0}'.format(r)])
        rochecount = out.count('IA52U1')
        print rochecount
        eq_(100, rochecount, 'Sff file reads did not make it into bam file')

        os.unlink(sff)
示例#21
0
 def print_ngs(self):
     print compat.check_output('find . -ls', shell=True)
示例#22
0
 def get_readgroup(self, bam, rg):
     cmd = ['samtools', 'view', '-r', rg, bam]
     return compat.check_output(cmd)
示例#23
0
 def print_tempdir(self):
     print compat.check_output('find ' + self.tempdir +
                               ' -exec ls -ld {} \;',
                               shell=True)
示例#24
0
 def print_tempdir( self ):
     print compat.check_output('find '+self.tempdir+' -exec ls -ld {} \;',shell=True)