def GetNearestTranscriptToPeak(rna_data1, rna_data2, chip_peak):
    """Compare two RNA-seq transcripts against the same ChIP-seq peak.

    Given two RNASeqDataLine objects (one for each of the transcripts)
    and a ChIPSeqDataLine object (for the ChIP peak), return the
    transcript which lies closest (regardless of direction) to the ChIP
    peak.

    Note: if the two transcripts are equidistant from the ChIP peak
    then return the first one.
    """
    if not rna_data1:
        return rna_data2
    elif not rna_data2:
        return rna_data1
    distance1 = rna_data1.getTSS() - chip_peak.start
    distance2 = rna_data2.getTSS() - chip_peak.start
    dist_diff = abs(distance2) - abs(distance1)
    if dist_diff < 0:
        return rna_data2
    else:
        return rna_data1
