parameters: (self, bamfile)
docstring: Extract aligner information from a BAM file
          :param bamfile: name of BAM file
docstring_summary: Extract aligner information from a BAM file
          :param bamfile: name of BAM file
docstring_tokens: Extract aligner information from a BAM file : param bamfile : name of BAM file
function: def addBAM(self, bamfile):
          """ Extract aligner information from a BAM file
          :param bamfile: name of BAM file
          """
          sp = subprocess.Popen("samtools view -H '%s'" % bamfile,
                                shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
          o, e = sp.communicate()
  
          if sp.returncode != 0:
              raise Exception("Samtools call failed: %s / %s" % (o, e))
  
          for line in o.split("\n"):
              if not line.startswith("@PG"):
                  continue
              try:
                  # noinspection PyTypeChecker
                  x = dict(y.split(":", 1) for y in line.split("\t")[1:])
              except:
                  logging.warn("Unable to parse SAM/BAM header line: %s" % line)
                  continue
              cp = ['unknown', 'unknown', '']
              try:
                  cp[0] = x['PN']
              except:
                  try:
                      cp[0] = x['ID']
                      if "-" in cp[0]:
                          cp[0] = cp[0].split("-")[0]
                  except:
                      pass
              try:
                  cp[1] = x['VN']
              except:
                  pass
              try:
                  cp[2] = x['CL']
              except:
                  pass
  
              self.aligners.append(cp)
function_tokens: def addBAM ( self , bamfile ) : sp = subprocess . Popen ( "samtools view -H '%s'" % bamfile , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) o , e = sp . communicate ( ) if sp . returncode != 0 : raise Exception ( "Samtools call failed: %s / %s" % ( o , e ) ) for line in o . split ( "\n" ) : if not line . startswith ( "@PG" ) : continue try : # noinspection PyTypeChecker x = dict ( y . split ( ":" , 1 ) for y in line . split ( "\t" ) [ 1 : ] ) except : logging . warn ( "Unable to parse SAM/BAM header line: %s" % line ) continue cp = [ 'unknown' , 'unknown' , '' ] try : cp [ 0 ] = x [ 'PN' ] except : try : cp [ 0 ] = x [ 'ID' ] if "-" in cp [ 0 ] : cp [ 0 ] = cp [ 0 ] . split ( "-" ) [ 0 ] except : pass try : cp [ 1 ] = x [ 'VN' ] except : pass try : cp [ 2 ] = x [ 'CL' ] except : pass self . aligners . append ( cp )