'See if file_name is a sorted BAM file'

def dataset_content_needs_grooming(self, file_name):

    version = self._get_samtools_version()
    if (version < '0.1.13'):
        return (not self._is_coordinate_sorted(file_name))
    else:
        if self._is_coordinate_sorted(file_name):
            return False
        index_name = tempfile.NamedTemporaryFile(prefix='bam_index').name
        stderr_name = tempfile.NamedTemporaryFile(prefix='bam_index_stderr').name
        command = ('samtools    index    %s    %s' % (file_name, index_name))
        proc = subprocess.Popen(args=command, shell=True, stderr=open(stderr_name, 'wb'))
        proc.wait()
        stderr = open(stderr_name).read().strip()
        if stderr:
            try:
                os.unlink(index_name)
            except OSError:
                pass
            try:
                os.unlink(stderr_name)
            except OSError:
                pass
            return (stderr.find('[bam_index_core]    the    alignment    is    not    sorted') != (-1))
        try:
            os.unlink(index_name)
        except OSError:
            pass
        try:
            os.unlink(stderr_name)
        except OSError:
            pass
        return False
