'Return a chrom, start, stop tuple for viewing a file.'

def get_estimated_display_viewport(self, dataset):

    viewport_feature_count = 100
    max_line_count = max(viewport_feature_count, 500)
    if self.displayable(dataset):
        try:
            chrom = None
            start = sys.maxsize
            end = 0
            span = 1
            step = None
            fh = open(dataset.file_name)
            while True:
                line = fh.readline(VIEWPORT_READLINE_BUFFER_SIZE)
                if (not line):
                    break
                try:
                    if line.startswith('browser'):
                        chr_info = line.rstrip('\n\r').split()[(-1)]
                        (chrom, coords) = chr_info.split(':')
                        (start, end) = map(int, coords.split('-'))
                        break
                    if (line and (line.lower().startswith('variablestep') or line.lower().startswith('fixedstep'))):
                        if (chrom is not None):
                            break
                        chrom = line.rstrip('\n\r').split('chrom=')[1].split()[0]
                        if ('span=' in line):
                            span = int(line.rstrip('\n\r').split('span=')[1].split()[0])
                        if ('step=' in line):
                            step = int(line.rstrip('\n\r').split('step=')[1].split()[0])
                            start = int(line.rstrip('\n\r').split('start=')[1].split()[0])
                    else:
                        fields = line.rstrip('\n\r').split()
                        if fields:
                            if (step is not None):
                                if (not end):
                                    end = (start + span)
                                else:
                                    end += step
                            else:
                                start = min(int(fields[0]), start)
                                end = max(end, (int(fields[0]) + span))
                            viewport_feature_count -= 1
                except:
                    pass
                readline_count = VIEWPORT_MAX_READS_PER_LINE
                while (line.rstrip('\n\r') == line):
                    assert (readline_count > 0), Exception(('Viewport    readline    count    exceeded    for    dataset    %s.' % dataset.id))
                    line = fh.readline(VIEWPORT_READLINE_BUFFER_SIZE)
                    if (not line):
                        break
                    readline_count -= 1
                max_line_count -= 1
                if ((not viewport_feature_count) or (not max_line_count)):
                    break
            if (chrom is not None):
                return (chrom, str(start), str(end))
        except Exception as e:
            log.exception(str(e))
    return (None, None, None)
