original_docstring:  Compute the mapeval r plots (ROC and QQ) 
docstring: Compute the mapeval r plots (ROC and QQ)
docstring_tokens: Compute the mapeval r plots ( ROC and QQ )
code: def _mapeval_r_plots(self, tag, positive_control=None, negative_control=None,
                           control_include=['snp1kg', 'primary', 'common1kg'], min_reads_for_filter_plots=100):
          """ Compute the mapeval r plots (ROC and QQ) """
          out_store = self._outstore(tag)
          out_store_name = self._outstore_name(tag)
          job_store = self._jobstore(tag)        
  
          # What do we want to override from the default toil-vg config?
          overrides = argparse.Namespace(
              container = self.container,
              # Toil options
              realTimeLogging = True,
              realTimeStderr = True,
              logLevel = "INFO",
              maxCores = self.cores
          )
  
          # Lookup names list with -pe and -se attached
          def pe_se(names):
              names_e = [[x, '{}-se'.format(x), '{}-pe'.format(x)] for x in names if x]
              return [y for x in names_e for y in x]
          
          # Make the context
          context = Context(out_store, overrides)
          with context.get_toil(job_store) as toil:
              try:
                  for rscript in ['pr', 'qq', 'roc']:
                      # pull the scripts from where we expect them relative to being in vg/
                      # and put them in the work directory.  This is ugly but keeps the
                      # docker interfacing simple.
                      shutil.copy2('scripts/plot-{}.R'.format(rscript), os.path.abspath(self.workdir))
  
                      # if controls specified, filter into their own plot so things don't get too busy
                      if positive_control or negative_control:
                          nc_name = 'position.results.no.control.tsv'
                          co_name = 'position.results.control.tsv'
                          with io.open(os.path.join(out_store, 'position.results.tsv'), 'r', encoding='utf8') as pr_file,\
                               io.open(os.path.join(out_store, nc_name), 'w', encoding='utf8') as nc_file,\
                               io.open(os.path.join(out_store, co_name), 'w', encoding='utf8') as co_file:
                              aidx = None
                              for i, line in enumerate(pr_file):
                                  toks = line.rstrip().split()
                                  if i == 0:
                                      aidx = toks.index('aligner')
                                  if i == 0 or toks[aidx].strip('"') in pe_se(control_include + 
                                          [positive_control, negative_control]):
                                      co_file.write(line)
                                  if i == 0 or toks[aidx].strip('"') not in  pe_se(
                                          [positive_control, negative_control]):
                                      nc_file.write(line)
                      else:
                          nc_name = 'position.results.tsv'
                          co_name = None
  
                      plot_names = [(nc_name, '')]
                      if co_name:
                          plot_names.append((co_name, '.control'))
  
                      # make a plot where we ignore reads that fail score
                      cur_plot_names = [pn for pn in plot_names]
                      for name,tag in plot_names:
                          pf_name = name.replace('.tsv', '.primary.filter.tsv')
                          if self._filter_position_file(
                                  os.path.join(out_store, name),
                                  os.path.join(out_store, pf_name)) > min_reads_for_filter_plots:
                              plot_names.append((pf_name, tag + '.primary.filter'))
                          else:
                              if os.path.isfile(os.path.join(out_store, pf_name)):
                                  os.remove(os.path.join(out_store, pf_name))
                          
                      for tsv_file, out_name in plot_names:
                          cmd = ['Rscript', 'plot-{}.R'.format(rscript),
                                 os.path.join(out_store_name, tsv_file),
                                 os.path.join(out_store_name, '{}{}.svg'.format(rscript, out_name))]
                          toil.start(Job.wrapJobFn(toil_call, context, cmd,
                                                   work_dir = os.path.abspath(self.workdir)))
  
                      os.remove(os.path.join(self.workdir, 'plot-{}.R'.format(rscript)))
                      
                  if os.path.isfile(os.path.join(self.workdir, 'Rplots.pdf')):
                      os.remove(os.path.join(self.workdir, 'Rplots.pdf'))
  
              except Exception as e:
                  log.warning("Failed to generate ROC and QQ plots with Exception: {}".format(e))
code_tokens: def _mapeval_r_plots ( self , tag , positive_control = None , negative_control = None , control_include = [ 'snp1kg' , 'primary' , 'common1kg' ] , min_reads_for_filter_plots = 100 ) : out_store = self . _outstore ( tag ) out_store_name = self . _outstore_name ( tag ) job_store = self . _jobstore ( tag ) overrides = argparse . Namespace ( container = self . container , realTimeLogging = True , realTimeStderr = True , logLevel = "INFO" , maxCores = self . cores ) def pe_se ( names ) : names_e = [ [ x , '{}-se' . format ( x ) , '{}-pe' . format ( x ) ] for x in names if x ] return [ y for x in names_e for y in x ] context = Context ( out_store , overrides ) with context . get_toil ( job_store ) as toil : try : for rscript in [ 'pr' , 'qq' , 'roc' ] : shutil . copy2 ( 'scripts/plot-{}.R' . format ( rscript ) , os . path . abspath ( self . workdir ) ) if positive_control or negative_control : nc_name = 'position.results.no.control.tsv' co_name = 'position.results.control.tsv' with io . open ( os . path . join ( out_store , 'position.results.tsv' ) , 'r' , encoding = 'utf8' ) as pr_file , io . open ( os . path . join ( out_store , nc_name ) , 'w' , encoding = 'utf8' ) as nc_file , io . open ( os . path . join ( out_store , co_name ) , 'w' , encoding = 'utf8' ) as co_file : aidx = None for i , line in enumerate ( pr_file ) : toks = line . rstrip ( ) . split ( ) if i == 0 : aidx = toks . index ( 'aligner' ) if i == 0 or toks [ aidx ] . strip ( '"' ) in pe_se ( control_include + [ positive_control , negative_control ] ) : co_file . write ( line ) if i == 0 or toks [ aidx ] . strip ( '"' ) not in pe_se ( [ positive_control , negative_control ] ) : nc_file . write ( line ) else : nc_name = 'position.results.tsv' co_name = None plot_names = [ ( nc_name , '' ) ] if co_name : plot_names . append ( ( co_name , '.control' ) ) cur_plot_names = [ pn for pn in plot_names ] for name , tag in plot_names : pf_name = name . replace ( '.tsv' , '.primary.filter.tsv' ) if self . _filter_position_file ( os . path . join ( out_store , name ) , os . path . join ( out_store , pf_name ) ) > min_reads_for_filter_plots : plot_names . append ( ( pf_name , tag + '.primary.filter' ) ) else : if os . path . isfile ( os . path . join ( out_store , pf_name ) ) : os . remove ( os . path . join ( out_store , pf_name ) ) for tsv_file , out_name in plot_names : cmd = [ 'Rscript' , 'plot-{}.R' . format ( rscript ) , os . path . join ( out_store_name , tsv_file ) , os . path . join ( out_store_name , '{}{}.svg' . format ( rscript , out_name ) ) ] toil . start ( Job . wrapJobFn ( toil_call , context , cmd , work_dir = os . path . abspath ( self . workdir ) ) ) os . remove ( os . path . join ( self . workdir , 'plot-{}.R' . format ( rscript ) ) ) if os . path . isfile ( os . path . join ( self . workdir , 'Rplots.pdf' ) ) : os . remove ( os . path . join ( self . workdir , 'Rplots.pdf' ) ) except Exception as e : log . warning ( "Failed to generate ROC and QQ plots with Exception: {}" . format ( e ) )
short_docstring: Compute the mapeval r plots (ROC and QQ)
short_docstring_tokens: Compute the mapeval r plots ( ROC and QQ )
comment: """ Compute the mapeval r plots (ROC and QQ) """$SEP$# What do we want to override from the default toil-vg config?$SEP$# Toil options$SEP$# Lookup names list with -pe and -se attached$SEP$# Make the context$SEP$# pull the scripts from where we expect them relative to being in vg/$SEP$# and put them in the work directory.  This is ugly but keeps the$SEP$# docker interfacing simple.$SEP$# if controls specified, filter into their own plot so things don't get too busy$SEP$# make a plot where we ignore reads that fail score