def get_rule_doc(name):
    """Decode and return the docstring(s) of a sequana/snakemake rule."""
    try:
        from sequana import Module
        rule = Module(name)
        filename = rule.path + '/%s.rules' % name
        data = open(filename, 'r').read()
    except ValueError:
        data = open(name, 'r').read()
    if name.endswith('_dynamic'):
        name = name[:-8]
    rulename_tag = 'rule %s' % name
    if rulename_tag in data:
        data = data.split(rulename_tag, 1)[1]
    else:
        return 'no docstring found for %s ' % name
    single = data.find("'''")
    double = data.find('"""')
    if single > 0 and double > 0:
        if single > double:
            quotes = '"""'
        else:
            quotes = "'''"
    elif single > 0:
        quotes = "'''"
    elif double > 0:
        quotes = '"""'
    else:
        return 'no docstring found for %s ' % name
    start = data.find(quotes)
    end = data[start + 3:].find(quotes) + start + 3
    if end == -1 or end < start:
        return 'no end of docstring found for %s ' % name
    docstring = data[start + 3:end]
    return docstring
