code: def readlength(self):
          logging.info('Estimating read lengths of FASTQ files')
          for sample in self.samples:
              sample.run.Date = 'NA'
              sample.run.InvestigatorName = 'NA'
              sample.run.TotalClustersinRun = 'NA'
              sample.run.NumberofClustersPF = 'NA'
              sample.run.PercentOfClusters = 'NA'
              sample.run.SampleProject = 'NA'
              if not GenObject.isattr(sample.run, 'forwardlength') and not GenObject.isattr(sample.run, 'reverselength'):
                  sample.header = GenObject()
                  sample.commands = GenObject()
                  devnull = open(os.devnull, 'wb')
                  if type(sample.general.fastqfiles) is list:
                      forwardfastq = sorted(sample.general.fastqfiles)[0]
                      if '.gz' in forwardfastq:
                          command = 'zcat'
                      else:
                          command = 'cat'
                      forwardreads = subprocess.Popen("{} {} | head -n 1000".format(command, forwardfastq),
                                                      shell=True,
                                                      stdout=subprocess.PIPE,
                                                      stderr=devnull).communicate()[0].rstrip()
                      try:
                          forwardreads = forwardreads.decode('utf-8')
                      except UnicodeDecodeError:
                          sample.run.forwardlength = 0
                      try:
                          forwardlength = max([len(sequence) for iterator, sequence in enumerate(forwardreads.split('\n'))
                                               if iterator % 4 == 1])
                          sample.run.forwardlength = forwardlength
                      except (ValueError, TypeError):
                          sample.run.forwardlength = 0
                      if len(sample.general.fastqfiles) == 2:
                          reversefastq = sorted(sample.general.fastqfiles)[1]
                          reversereads = subprocess.Popen("{} {} | head -n 1000".format(command, reversefastq),
                                                          shell=True,
                                                          stdout=subprocess.PIPE,
                                                          stderr=devnull).communicate()[0].rstrip()
                          try:
                              reversereads = reversereads.decode('utf-8')
                          except UnicodeDecodeError:
                              sample.run.reverselength = 0
                          try:
                              sample.run.reverselength = max([len(sequence) for iterator, sequence in
                                                              enumerate(reversereads.split('\n')) if iterator % 4 == 1])
                          except (ValueError, TypeError):
                              sample.run.reverselength = 0
                      else:
                          sample.run.reverselength = 0