import re


def take_first_chain_from_list(chainList):
    """
    Takes first chain from a chain list
    returns the header: "chain 52633 chr..." and a list of lines of this chain
    returns twice None if no chains are present
    """
    headLine = None
    chainContent = None
    chainStart = None
    chainEnd = None

    for pos in range(0, len(chainList)):

        line = chainList[pos]

        # check if chain line
        m = re.match(r"chain", line)
        if m is not None:
            headLine = line.strip("\n")

            # process and store end position
            pos += 1
            line = chainList[pos]
            chainStart = pos

            while re.match("^\d+", line) is not None:
                pos += 1
                line = chainList[pos]
            chainEnd = pos  # actually position after chain

            # don't process lower scoring chains
            break

    # extract chain
    if chainStart is not None:
        chainContent = chainList[chainStart:chainEnd]
    return (headLine, chainContent)