'Galaxy Dbn (Dot-Bracket notation) rules:
* The first non-empty line is a header line: no comment lines are allowed.
* A header line starts with a \'>\' symbol and continues with 0 or multiple symbols until the line ends.
* The second non-empty line is a sequence line.
* A sequence line may only include chars that match the FASTA format (https://en.wikipedia.org/wiki/FASTA_format#Sequence_representation) symbols for nucleotides: ACGTURYKMSWBDHVN, and may thus not include whitespaces.
* A sequence line has no prefix and no suffix.
* A sequence line is case insensitive.
* The third non-empty line is a structure (Dot-Bracket) line and only describes the 2D structure of the sequence above it.
* A structure line must consist of the following chars: \'.{}[]()\'.
* A structure line must be of the same length as the sequence line, and each char represents the structure of the nucleotide above it.
* A structure line has no prefix and no suffix.
* A nucleotide pairs with only 1 or 0 other nucleotides.
* In a structure line, the number of \'(\' symbols equals the number of \')\' symbols, the number of \'[\' symbols equals the number of \']\' symbols and the number of \'{\' symbols equals the number of \'}\' symbols.
* The format accepts multiple entries per file, given that each entry is provided as three lines: the header, sequence and structure line.
* Sniffing is only applied on the first entry.
* Empty lines are allowed.'

def sniff(self, filename):

    state = 0
    with open(filename, 'r') as handle:
        for line in handle:
            line = line.strip()
            if line:
                if (state == 0):
                    if (line[0] != '>'):
                        return False
                    else:
                        state = 1
                elif (state == 1):
                    if (not self.sequence_regexp.match(line)):
                        return False
                    else:
                        sequence_size = len(line)
                        state = 2
                elif (state == 2):
                    if ((sequence_size != len(line)) or (not self.structure_regexp.match(line)) or (line.count('(') != line.count(')')) or (line.count('[') != line.count(']')) or (line.count('{') != line.count('}'))):
                        return False
                    else:
                        return True
    return False
