code: def generate_psms_quanted(quantdb, tsvfn, isob_header, oldheader,
                            isobaric=False, precursor=False):
      
      allquants, sqlfields = quantdb.select_all_psm_quants(isobaric, precursor)
      quant = next(allquants)
      for rownr, psm in enumerate(readers.generate_tsv_psms(tsvfn, oldheader)):
          outpsm = {x: y for x, y in psm.items()}
          if precursor:
              pquant = quant[sqlfields['precursor']]
              if pquant is None:
                  pquant = 'NA'
              outpsm.update({mzidtsvdata.HEADER_PRECURSOR_QUANT: str(pquant)})
          if isobaric:
              isoquants = {}
              while quant[0] == rownr:
                  isoquants.update({quant[sqlfields['isochan']]:
                                    str(quant[sqlfields['isoquant']])})
                  try:
                      quant = next(allquants)
                  except StopIteration:
                      # last PSM, break from while loop or it is not yielded at all
                      break
              outpsm.update(get_quant_NAs(isoquants, isob_header))
          else:
              try:
                  quant = next(allquants)
              except StopIteration:
                  # last PSM, needs explicit yield/break or it will not be yielded
                  yield outpsm
                  break
          yield outpsm
docs: Takes dbfn and connects, gets quants for each line in tsvfn, sorts
      them in line by using keys in quantheader list.