code: def _add_metadata(item, metadata, remotes, only_metadata=False):
      
      for check_key in [item["description"]] + _get_file_keys(item) + _get_vrn_keys(item):
          item_md = metadata.get(check_key)
          if item_md:
              break
      if not item_md:
          item_md = _find_glob_metadata(item["files"], metadata)
      if remotes.get("region"):
          item["algorithm"]["variant_regions"] = remotes["region"]
      TOP_LEVEL = set(["description", "genome_build", "lane", "vrn_file", "files", "analysis"])
      keep_sample = True
      if item_md and len(item_md) > 0:
          if "metadata" not in item:
              item["metadata"] = {}
          for k, v in item_md.items():
              if v:
                  if k in TOP_LEVEL:
                      item[k] = v
                  elif k in run_info.ALGORITHM_KEYS:
                      v = _handle_special_yaml_cases(v)
                      item["algorithm"][k] = v
                  else:
                      v = _handle_special_yaml_cases(v)
                      item["metadata"][k] = v
      elif len(metadata) > 0:
          warn = "Dropped sample" if only_metadata else "Added minimal sample information"
          print("WARNING: %s: metadata not found for %s, %s" % (warn, item["description"],
                                                                [os.path.basename(f) for f in item["files"]]))
          keep_sample = not only_metadata
      if tz.get_in(["metadata", "ped"], item):
          item["metadata"] = _add_ped_metadata(item["description"], item["metadata"])
      return item if keep_sample else None
docs: Add metadata information from CSV file to current item.
  
      Retrieves metadata based on 'description' parsed from input CSV file.
      Adds to object and handles special keys:
      - `description`: A new description for the item. Used to relabel items
         based on the pre-determined description from fastq name or BAM read groups.
      - Keys matching supported names in the algorithm section map
        to key/value pairs there instead of metadata.