code: def merge_pairs(self):
          
          logging.info('Merging paired reads')
          for sample in self.metadata:
              # Can only merge paired-end
              if len(sample.general.fastqfiles) == 2:
                  # Set the name of the merged, and unmerged files
                  sample.general.mergedreads = \
                      os.path.join(sample.general.outputdirectory, '{}_paired.fastq.gz'.format(sample.name))
                  sample.general.unmergedforward = \
                      os.path.join(sample.general.outputdirectory, '{}_unpaired_R1.fastq.gz'.format(sample.name))
                  sample.general.unmergedreverse = \
                      os.path.join(sample.general.outputdirectory, '{}_unpaired_R2.fastq.gz'.format(sample.name))
                  try:
                      # Run the merging command - forward_in=sample.general.normalisedreads[0],
                      out, err, cmd = bbtools.bbmerge(forward_in=sorted(sample.general.trimmedcorrectedfastqfiles)[0],
                                                      merged_reads=sample.general.mergedreads,
                                                      returncmd=True,
                                                      outu1=sample.general.unmergedforward,
                                                      outu2=sample.general.unmergedreverse,
                                                      threads=self.cpus)
                      sample[self.analysistype].bbmergecmd = cmd
                      write_to_logfile(out, err, self.logfile, sample.general.logout, sample.general.logerr, None, None)
                  except CalledProcessError:
                      delattr(sample.general, 'mergedreads')
                      delattr(sample.general, 'unmergedforward')
                      delattr(sample.general, 'unmergedreverse')
                  except IndexError:
                      delattr(sample.general, 'mergedreads')
                      delattr(sample.general, 'unmergedforward')
                      delattr(sample.general, 'unmergedreverse')
              else:
                  sample.general.mergedreads = sorted(sample.general.trimmedcorrectedfastqfiles)[0]
docs: Use bbmerge from the bbmap suite of tools to merge paired-end reads