code: def trimquality(self):
          logging.info("Trimming fastq files")
          with progressbar(self.metadata) as bar:
              for sample in bar:
                  if type(sample.general.fastqfiles) is list:
                      fastqfiles = sorted(sample.general.fastqfiles)
                      outputdir = sample.general.outputdirectory
                      cleanforward = os.path.join(outputdir, '{}_R1_trimmed.fastq.gz'.format(sample.name))
                      cleanreverse = os.path.join(outputdir, '{}_R2_trimmed.fastq.gz'.format(sample.name))
                      try:
                          lesser_length = min(int(sample.run.forwardlength), int(sample.run.reverselength))
                      except ValueError:
                          lesser_length = int(sample.run.forwardlength)
                      min_len = 50 if lesser_length >= 50 else lesser_length
                      trim_left = 0
                      try:
                          if 'R2' in fastqfiles[0]:
                              if not os.path.isfile(cleanreverse):
                                  out, \
                                      err, \
                                      bbdukcall = bbtools.bbduk_trim(forward_in=fastqfiles[0],
                                                                     reverse_in=None,
                                                                     forward_out=cleanreverse,
                                                                     trimq=10,
                                                                     minlength=min_len,
                                                                     forcetrimleft=trim_left,
                                                                     returncmd=True)
                              else:
                                  bbdukcall = str()
                                  out = str()
                                  err = str()
                          else:
                              if not os.path.isfile(cleanforward):
                                      out, \
                                          err, \
                                          bbdukcall = bbtools.bbduk_trim(forward_in=fastqfiles[0],
                                                                         forward_out=cleanforward,
                                                                         trimq=10,
                                                                         minlength=min_len,
                                                                         forcetrimleft=trim_left,
                                                                         returncmd=True)
                              else:
                                  bbdukcall = str()
                                  out = str()
                                  err = str()
                      except (IndexError, CalledProcessError):
                          bbdukcall = str()
                          out = str()
                          err = str()
                      write_to_logfile(bbdukcall, bbdukcall, self.logfile, sample.general.logout, sample.general.logerr,
                                       None, None)
                      write_to_logfile(out, err, self.logfile, sample.general.logout, sample.general.logerr, None, None)
                      trimmedfastqfiles = sorted(glob(os.path.join(sample.general.outputdirectory, '*trimmed.fastq.gz')))
                      sample.general.trimmedfastqfiles = trimmedfastqfiles if trimmedfastqfiles else list()
          logging.info('Fastq files trimmed')