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

def get_estimated_display_viewport(self, dataset, chrom_col=None, start_col=None, end_col=None):

    max_line_count = 100
    variable_step_wig = False
    chrom = None
    span = 1
    if self.displayable(dataset):
        try:
            fh = open(dataset.file_name)
            while True:
                line = fh.readline(VIEWPORT_READLINE_BUFFER_SIZE)
                if (not line):
                    break
                if (not line.startswith('#')):
                    try:
                        if variable_step_wig:
                            fields = line.rstrip().split()
                            if (len(fields) == 2):
                                start = int(fields[0])
                                return (chrom, str(start), str((start + span)))
                        elif (line and (line.lower().startswith('variablestep') or line.lower().startswith('fixedstep'))):
                            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 ('start=' in line):
                                start = int(line.rstrip('\n\r').split('start=')[1].split()[0])
                                return (chrom, str(start), str((start + span)))
                            else:
                                variable_step_wig = True
                        else:
                            fields = line.rstrip().split(' DCTB ')
                            if (len(fields) >= 3):
                                chrom = fields[0]
                                start = int(fields[1])
                                end = int(fields[2])
                                return (chrom, str(start), str(end))
                    except Exception:
                        continue
                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 max_line_count):
                    break
        except Exception as e:
            log.exception(str(e))
    return (None, None, None)
