code: func (bh *Header) Validate(r *Record) error {
  	rp := r.AuxFields.Get(programTag)
  	found := false
  	for _, hp := range bh.Progs() {
  		if hp.UID() == rp.Value() {
  			found = true
  			break
  		}
  	}
  	if !found && len(bh.Progs()) != 0 {
  		return fmt.Errorf("sam: program uid not found: %v", rp.Value())
  	}
  
  	rg := r.AuxFields.Get(readGroupTag)
  	found = false
  	for _, hg := range bh.RGs() {
  		if hg.Name() == rg.Value() {
  			rPlatformUnit := r.AuxFields.Get(platformUnitTag).Value()
  			if rPlatformUnit != hg.PlatformUnit() {
  				return fmt.Errorf("sam: mismatched platform for read group %s: %v != %v", hg.Name(), rPlatformUnit, hg.platformUnit)
  			}
  			rLibrary := r.AuxFields.Get(libraryTag).Value()
  			if rLibrary != hg.Library() {
  				return fmt.Errorf("sam: mismatched library for read group %s: %v != %v", hg.Name(), rLibrary, hg.library)
  			}
  			found = true
  			break
  		}
  	}
  	if !found && len(bh.RGs()) != 0 {
  		return fmt.Errorf("sam: read group not found: %v", rg.Value())
  	}
  
  	return nil
  }
docs: // Validate checks r against the Header for record validity according to the
  // SAM specification:
  //
  //  - a program auxiliary field must refer to a program listed in the header
  //  - a read group auxiliary field must refer to a read group listed in the
  //    header and these must agree on platform unit and library.