'Return a chrom, start, stop tuple for viewing a file.  There are slight differences between gff 2 and gff 3
formats.  This function should correctly handle both...'

def get_estimated_display_viewport(self, dataset):

    viewport_feature_count = 100
    max_line_count = max(viewport_feature_count, 500)
    if self.displayable(dataset):
        try:
            seqid = None
            start = sys.maxsize
            stop = 0
            fh = open(dataset.file_name)
            while True:
                line = fh.readline(VIEWPORT_READLINE_BUFFER_SIZE)
                if (not line):
                    break
                try:
                    if line.startswith('##sequence-region'):
                        elems = line.rstrip('\n\r').split()
                        if (len(elems) > 3):
                            seqid = elems[1]
                            start = int(elems[2])
                            stop = int(elems[3])
                            break
                        elif ((len(elems) == 2) and (elems[1].find('..') > 0)):
                            elems = elems[1].split(':')
                            seqid = elems[0]
                            start = int(elems[1].split('..')[0])
                            stop = int(elems[1].split('..')[1])
                            break
                        else:
                            log.exception(('line    (%s)    uses    an    unsupported    ##sequence-region    definition.' % str(line)))
                    elif line.startswith('browser    position'):
                        pos_info = line.split()[(-1)]
                        (seqid, startend) = pos_info.split(':')
                        (start, stop) = map(int, startend.split('-'))
                        break
                    elif (True not in map(line.startswith, ('#', 'track', 'browser'))):
                        viewport_feature_count -= 1
                        elems = line.rstrip('\n\r').split(' DCTB ')
                        if (len(elems) > 3):
                            if (not seqid):
                                seqid = elems[0]
                            if (seqid == elems[0]):
                                start = min(start, int(elems[3]))
                                stop = max(stop, int(elems[4]))
                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 (seqid is not None):
                return (seqid, str(start), str(stop))
        except Exception as e:
            log.exception(str(e))
    return (None, None, None)
