'Checks for \'bedness\'
BED lines have three required fields and nine additional optional fields.
The number of fields per line must be consistent throughout any single set of data in
an annotation track.  The order of the optional fields is binding: lower-numbered
fields must always be populated if higher-numbered fields are used.  The data type of
all 12 columns is:
1-str, 2-int, 3-int, 4-str, 5-int, 6-str, 7-int, 8-int, 9-int or list, 10-int, 11-list, 12-list
For complete details see http://genome.ucsc.edu/FAQ/FAQformat#format1
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname( \'test_tab.bed\' )
>>> Bed().sniff( fname )
True
>>> fname = get_test_fname( \'interval1.bed\' )
>>> Bed().sniff( fname )
True
>>> fname = get_test_fname( \'complete.bed\' )
>>> Bed().sniff( fname )
True'

def sniff(self, filename):

    if (not get_headers(filename, ' DCTB ', comment_designator='#', count=1)):
        return False
    try:
        headers = iter_headers(filename, ' DCTB ', comment_designator='#')
        for hdr in headers:
            if (hdr[0] == ''):
                continue
            valid_col1 = False
            if ((len(hdr) < 3) or (len(hdr) > 12)):
                return False
            for str in data.col1_startswith:
                if hdr[0].lower().startswith(str):
                    valid_col1 = True
                    break
            if valid_col1:
                try:
                    int(hdr[1])
                    int(hdr[2])
                except:
                    return False
                if (len(hdr) > 4):
                    try:
                        if ((int(hdr[4]) < 0) or (int(hdr[4]) > 1000)):
                            return False
                    except:
                        return False
                if (len(hdr) > 5):
                    if (hdr[5] not in data.valid_strand):
                        return False
                if (len(hdr) > 6):
                    try:
                        int(hdr[6])
                    except:
                        return False
                if (len(hdr) > 7):
                    try:
                        int(hdr[7])
                    except:
                        return False
                if (len(hdr) > 8):
                    try:
                        int(hdr[8])
                    except:
                        try:
                            hdr[8].split(',')
                        except:
                            return False
                if (len(hdr) > 9):
                    try:
                        block_count = int(hdr[9])
                    except:
                        return False
                if (len(hdr) > 10):
                    try:
                        block_sizes = hdr[10].rstrip(',').split(',')
                    except:
                        return False
                if (len(hdr) > 11):
                    try:
                        block_starts = hdr[11].rstrip(',').split(',')
                    except:
                        return False
                    if ((len(block_sizes) != block_count) or (len(block_starts) != block_count)):
                        return False
            else:
                return False
        return True
    except:
        return False
