def mapping(self, analysistype, metadata):
        """

        :param analysistype:
        :param metadata:
        """
        printtime('Performing reference mapping', self.start)
        for i in range(len(metadata)):
            # Send the threads to
            threads = Thread(target=self.map, args=())
            # Set the daemon to True - something to do with thread management
            threads.setDaemon(True)
            # Start the threading
            threads.start()
        for sample in metadata:
            if sample.general.bestassemblyfile != 'NA':
                # Set the path/name for the sorted bam file to be created
                sample[analysistype].sortedbam = '{}/{}_sorted.bam'.format(sample[analysistype].outputdir,
                                                                           analysistype)
                # Remove the file extension of the bait file for use in the indexing command
                sample[analysistype].baitfilenoext = sample[analysistype].baitfile.split('.')[0]
                # Use bowtie2 wrapper to create index the target file
                bowtie2build = Bowtie2BuildCommandLine(reference=sample[analysistype].baitfile,
                                                       bt2=sample[analysistype].baitfilenoext,
                                                       **self.builddict)
                # Use samtools wrapper to set up the bam sorting command
                ''''''
                samsort = SamtoolsSortCommandline(input=sample[analysistype].sortedbam,
                                                  o=True,
                                                  out_prefix="-")
                samtools = [
                    # When bowtie2 maps reads to all possible locations rather than choosing a 'best' placement, the
                    # SAM header for that read is set to 'secondary alignment', or 256. Please see:
                    # http://davetang.org/muse/2014/03/06/understanding-bam-flags/ The script below reads in the stdin
                    # and subtracts 256 from headers which include 256
                    'python {}/sipprcommon/editsamheaders.py'.format(self.homepath),
                    # Use samtools wrapper to set up the samtools view
                    SamtoolsViewCommandline(b=True,
                                            S=True,
                                            h=True,
                                            input_file="-"),
                    samsort]
                # Add custom parameters to a dictionary to be used in the bowtie2 alignment wrapper
                indict = {'--very-sensitive-local': True,
                          # For short targets, the match bonus can be increased
                          '--ma': self.matchbonus,
                          '-U': sample[analysistype].baitedfastq,
                          '-a': True,
                          '--threads': self.cpus,
                          '--local': True}
                # Create the bowtie2 reference mapping command
                bowtie2align = Bowtie2CommandLine(bt2=sample[analysistype].baitfilenoext,
                                                  threads=self.cpus,
                                                  samtools=samtools,
                                                  **indict)
                # Create the command to faidx index the bait file
                sample[analysistype].faifile = sample[analysistype].baitfile + '.fai'
                samindex = SamtoolsFaidxCommandline(reference=sample[analysistype].baitfile)
                # Add the commands (as strings) to the metadata
                sample[analysistype].samindex = str(samindex)
                # Add the commands to the queue. Note that the commands would usually be set as attributes of the sample
                # but there was an issue with their serialization when printing out the metadata
                if not os.path.isfile(sample[analysistype].baitfilenoext + '.1' + self.bowtiebuildextension):
                    stdoutbowtieindex, stderrbowtieindex = map(StringIO,
                                                               bowtie2build(cwd=sample[analysistype].targetpath))
                    # Write any error to a log file
                    if stderrbowtieindex:
                        # Write the standard error to log, bowtie2 puts alignment summary here
                        with open(os.path.join(sample[analysistype].targetpath,
                                               '{}_bowtie_index.log'.format(analysistype)), 'a+') as log:
                            log.writelines(logstr(bowtie2build, stderrbowtieindex.getvalue(),
                                                  stdoutbowtieindex.getvalue()))
                    # Close the stdout and stderr streams
                    stdoutbowtieindex.close()
                    stderrbowtieindex.close()
                self.mapqueue.put((sample, bowtie2build, bowtie2align, samindex, analysistype))
        self.mapqueue.join()
def mapping ( self , analysistype , metadata ) : printtime ( 'Performing reference mapping' , self . start ) for i in range ( len ( metadata ) ) : threads = Thread ( target = self . map , args = ( ) ) threads . setDaemon ( True ) threads . start ( ) for sample in metadata : if sample . general . bestassemblyfile != 'NA' : sample [ analysistype ] . sortedbam = '{}/{}_sorted.bam' . format ( sample [ analysistype ] . outputdir , analysistype ) sample [ analysistype ] . baitfilenoext = sample [ analysistype ] . baitfile . split ( '.' ) [ 0 ] bowtie2build = Bowtie2BuildCommandLine ( reference = sample [ analysistype ] . baitfile , bt2 = sample [ analysistype ] . baitfilenoext , ** self . builddict ) '''''' samsort = SamtoolsSortCommandline ( input = sample [ analysistype ] . sortedbam , o = True , out_prefix = "-" ) samtools = [ 'python {}/sipprcommon/editsamheaders.py' . format ( self . homepath ) , SamtoolsViewCommandline ( b = True , S = True , h = True , input_file = "-" ) , samsort ] indict = { '--very-sensitive-local' : True , '--ma' : self . matchbonus , '-U' : sample [ analysistype ] . baitedfastq , '-a' : True , '--threads' : self . cpus , '--local' : True } bowtie2align = Bowtie2CommandLine ( bt2 = sample [ analysistype ] . baitfilenoext , threads = self . cpus , samtools = samtools , ** indict ) sample [ analysistype ] . faifile = sample [ analysistype ] . baitfile + '.fai' samindex = SamtoolsFaidxCommandline ( reference = sample [ analysistype ] . baitfile ) sample [ analysistype ] . samindex = str ( samindex ) if not os . path . isfile ( sample [ analysistype ] . baitfilenoext + '.1' + self . bowtiebuildextension ) : stdoutbowtieindex , stderrbowtieindex = map ( StringIO , bowtie2build ( cwd = sample [ analysistype ] . targetpath ) ) if stderrbowtieindex : with open ( os . path . join ( sample [ analysistype ] . targetpath , '{}_bowtie_index.log' . format ( analysistype ) ) , 'a+' ) as log : log . writelines ( logstr ( bowtie2build , stderrbowtieindex . getvalue ( ) , stdoutbowtieindex . getvalue ( ) ) ) stdoutbowtieindex . close ( ) stderrbowtieindex . close ( ) self . mapqueue . put ( ( sample , bowtie2build , bowtie2align , samindex , analysistype ) ) self . mapqueue . join ( )
:param analysistype:
        :param metadata: