'Nexus data is stored in blocks between a line starting with begin and another line starting with end;
Commends inside square brackets are to be ignored,
For more information: http://wiki.christophchamp.com/index.php/NEXUS_file_format
Nexus can store multiple trees'

def parseNexus(self, filename):

    with open(filename, 'rt') as nex_file:
        nexlines = nex_file.readlines()
    rowCount = 0
    inTreeBlock = False
    intranslateBlock = False
    self.inCommentBlock = False
    self.nameMapping = None
    treeNames = []
    for line in nexlines:
        line = line.replace(';\n', '')
        lline = line.lower()
        if ((rowCount > MAX_READLINES) or (not nex_file)):
            break
        rowCount += 1
        if (('begin' in lline) and ('tree' in lline) and (not inTreeBlock)):
            inTreeBlock = True
            continue
        if (inTreeBlock and ('end' in lline[:3])):
            (inTreeBlock, currPhyloTree) = (False, None)
            continue
        if inTreeBlock:
            if ('title' in lline):
                continue
            if ('translate' in lline):
                intranslateBlock = True
                self.nameMapping = {}
                continue
            if intranslateBlock:
                mappingLine = self.splitLinebyWhitespaces(line)
                (key, value) = (mappingLine[1], mappingLine[2].replace(',', '').replace("'", ''))
                self.nameMapping[key] = value
            if ('tree' in lline):
                intranslateBlock = False
                treeLineCols = self.splitLinebyWhitespaces(line)
                (treeName, newick) = (treeLineCols[2], treeLineCols[(-1)])
                if (newick == ''):
                    continue
                currPhyloTree = self._parseNewickToJson(newick, treeName, nameMap=self.nameMapping)
                self.phyloTrees.append(currPhyloTree)
                treeIndex = (len(self.phyloTrees) - 1)
                treeNames.append((treeName, treeIndex))
                continue
    return (self.phyloTrees, treeNames)
