docs: def main(args):
    of = sys.stdout
    if args.output and args.output[-4:] == '.bam':
      cmd = 'samtools view -Sb - -o '+args.output
      pof = Popen(cmd.split(),stdin=PIPE)
      of = pof.stdin
    elif args.output:
      of = open(args.output,'w')
    """Use the valid input file to get the header information."""
  
    header = None
    if args.HQ:
      cmd = 'samtools view -H '+args.HQ
      sys.stderr.write(cmd+"\n")
      header = Popen(cmd.split(),stdout=PIPE).communicate()[0]
      of.write(header)
    if (not header) and args.HQCorrected:
      cmd = 'samtools view -H '+args.HQCorrected
      sys.stderr.write(cmd+"\n")
      header = Popen(cmd.split(),stdout=PIPE).communicate()[0]
      of.write(header)
    if (not header) and args.AQ:
      cmd = 'samtools view -H '+args.AQ
      sys.stderr.write(cmd+"\n")
      header = Popen(cmd.split(),stdout=PIPE).communicate()[0]
      of.write(header)
    if (not header) and args.AQCorrected:
      cmd = 'samtools view -H '+args.AQCorrected
      sys.stderr.write(cmd+"\n")
      header = Popen(cmd.split(),stdout=PIPE).communicate()[0]
      of.write(header)
    if (not header) and args.subreads:
      cmd = 'samtools view -H '+args.subreads
      sys.stderr.write(cmd+"\n")
      header = Popen(cmd.split(),stdout=PIPE).communicate()[0]
      of.write(header)
    if (not header) and args.subreadsCorrected:
      cmd = 'samtools view -H '+args.subreadsCorrected
      sys.stderr.write(cmd+"\n")
      header = Popen(cmd.split(),stdout=PIPE).communicate()[0]
      of.write(header)
  
    _nameprog = re.compile('^(\S+)')
    negative_filter = set() # remove these
    """ Next read throught he alignments THAT ALIGNED in order of priority"""
    negative_filter = get_best_set(negative_filter,'-F 4',of,args,True)
    """After traversing all the aligned reads we can do it all over again
       this time with the unaligned portion of reads"""
  
    """ Finally go through the reads that did NOT ALIGN to get anything left"""
    get_best_set(negative_filter,'-f 4',of,args,False)
    if args.output and args.output[-4:] == '.bam':
      pof.communicate()
    else:
      of.close()