code: def star(args):
      
      p = OptionParser(star.__doc__)
      p.add_option("--single", default=False, action="store_true",
                   help="Single end mapping")
      p.set_fastq_names()
      p.set_cpus()
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      folder, reference = args
      cpus = opts.cpus
      mm = MakeManager()
  
      num = 1 if opts.single else 2
      folder, reference = args
      gd = "GenomeDir"
      mkdir(gd)
      STAR = "STAR --runThreadN {0} --genomeDir {1}".format(cpus, gd)
  
      # Step 0: build genome index
      genomeidx = op.join(gd, "Genome")
      if need_update(reference, genomeidx):
          cmd = STAR + " --runMode genomeGenerate"
          cmd += " --genomeFastaFiles {0}".format(reference)
          mm.add(reference, genomeidx, cmd)
  
      # Step 1: align
      for p, prefix in iter_project(folder, opts.names, num):
          pf = "{0}_star".format(prefix)
          bamfile = pf + "Aligned.sortedByCoord.out.bam"
          cmd = STAR + " --readFilesIn {0}".format(" ".join(p))
          if p[0].endswith(".gz"):
              cmd += " --readFilesCommand zcat"
          cmd += " --outSAMtype BAM SortedByCoordinate"
          cmd += " --outFileNamePrefix {0}".format(pf)
          cmd += " --twopassMode Basic"
          # Compatibility for cufflinks
          cmd += " --outSAMstrandField intronMotif"
          cmd += " --outFilterIntronMotifs RemoveNoncanonical"
          mm.add(p, bamfile, cmd)
  
      mm.write()
docs: %prog star folder reference
  
      Run star on a folder with reads.