def correct_max_relative_intensity(replicate_mass_peak_data):
    """Check that the max peak is 100%.
    If not, find largest peak, set to 100% and apply correction factor to other peak intensities.
    """

    max_average_relative_intensity = 0
    max_intensity_mass = 0
    max_intensity = 0

    for replicate_mass_peak in replicate_mass_peak_data:
        if replicate_mass_peak.average_intensity > max_intensity:
            max_intensity = replicate_mass_peak.average_intensity
        if replicate_mass_peak.relative_intensity > max_average_relative_intensity:
            max_average_relative_intensity = replicate_mass_peak.relative_intensity
            max_intensity_mass = replicate_mass_peak.average_mass

    if max_average_relative_intensity != 100:
        for replicate_mass_peak in replicate_mass_peak_data:
            replicate_mass_peak.relative_intensity = round((replicate_mass_peak.relative_intensity /
                                                            max_average_relative_intensity) * 100, 1)

    return replicate_mass_peak_data, max_intensity_mass, max_intensity