How to use the lingpy.util.dotjoin function in lingpy

To help you get started, we’ve selected a few lingpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lingpy / lingpy / lingpy / align / multiple.py View on Github external
def _update_alignments(self):
        self.alm_matrix = [0 for i in range(len(self.numbers))]

        for i, line in enumerate(self._alm_matrix):
            indices = self.int2ext[i]
            for j in indices:
                numbers = []
                for num in line:
                    try:
                        numbers.append(dotjoin(j + 1, num.split('.')[1]))
                    except:
                        numbers.append('X')
                self.alm_matrix[j] = [self._get(num, 'tokens') for num in numbers]
github lingpy / lingpy / lingpy / align / _align / confidence.py View on Github external
# store confidences per line
            confidences = []

            # store chars per line
            chars = []

            # iterate over the sequence
            for j, num in enumerate(nums):
                col = [alm[j] for alm in alignment]
                score = 0
                count = 0

                # get the char
                if num != '-':
                    charA = dotjoin(taxa[i], msa['alignment'][i][j], num.split('.')[2])
                    chars += [charA]
                    try:
                        occs[charA] += [concept]
                    except:
                        occs[charA] = [concept]
                else:
                    chars += ['-']

                for k, numB in enumerate(col):
                    if k != i:
                        if num == '-' and numB == '-':
                            pass
                        else:
                            if numB != '-' and num != '-':
                                # get the second char
                                charB = dotjoin(
github lingpy / lingpy / lingpy / align / _align / confidence.py View on Github external
chars += [charA]
                    try:
                        occs[charA] += [concept]
                    except:
                        occs[charA] = [concept]
                else:
                    chars += ['-']

                for k, numB in enumerate(col):
                    if k != i:
                        if num == '-' and numB == '-':
                            pass
                        else:
                            if numB != '-' and num != '-':
                                # get the second char
                                charB = dotjoin(
                                    taxa[k],
                                    msa['alignment'][k][j],
                                    numB.split('.')[2])
                                try:
                                    corrs[charA][charB] += 1
                                except:
                                    try:
                                        corrs[charA][charB] = 1
                                    except:
                                        corrs[charA] = {charB: 1}

            character_matrix += [chars]

        # append confidence matrix to alignments
        alms.msa[ref][key]['_charmat'] = character_matrix
github lingpy / lingpy / lingpy / align / _align / confidence.py View on Github external
chars += [charA]
                    try:
                        occs[charA] += [concept]
                    except:
                        occs[charA] = [concept]
                else:
                    chars += ['-']

                for k, numB in enumerate(col):
                    if k != i:
                        if num == '-' and numB == '-':
                            pass
                        else:
                            if numB != '-' and num != '-':
                                # get the second char
                                charB = dotjoin(
                                    taxa[k], msa['alignment'][k][j], numB.split('.')[2])
                                try:
                                    corrs[charA][charB] += 1
                                except:
                                    try:
                                        corrs[charA][charB] = 1
                                    except:
                                        corrs[charA] = {charB: 1}

                            gaps = False
                            if num == '-' and numB != '-':
                                numA = charstring(idx)
                                gaps = True
                            elif numB == '-' and num != '-':
                                numB = charstring(alms.taxa.index(taxa[k]))
                                numA = num
github lingpy / lingpy / lingpy / align / _align / confidence.py View on Github external
counter = 0
        for a, b, c, d in new_sorts:
            new_lang = a
            if new_lang != old_lang:
                old_lang = new_lang

                tmp = ''
                tmp += ''.format(spans[a])
                tmp += a + ''
                tmp += '<span span="">'
                tmp += ''
                tmp += c + ''
                tmp += '' + str(d) + ''
                tmp += '' + str(len(occs[dotjoin(a, b, c)])) + ''
                tmp += ''
                t = 'dolgo_' + token2class(b, rcParams['dolgo'])

                # bad check for three classes named differently
                if t == 'dolgo__':
                    t = 'dolgo_X'
                elif t == 'dolgo_1':
                    t = 'dolgo_TONE'
                elif t == 'dolgo_0':
                    t = 'dolgo_ERROR'

                bestis += [tmp.format(t)]
                counter += 1

            elif counter &gt; 0:
                tmp = ''</span>
github lingpy / lingpy / lingpy / align / multiple.py View on Github external
# compute only one alignment for each set of identical sequences
        indices = defaultdict(list)
        for i, seq in enumerate(self.classes):
            indices[tuple(seq)].append(i)

        # create additional matrices for the internal representation of the
        # class sequences
        if self.unique_seqs:
            keys = [val[0] for val in indices.values()]
        else:
            keys = range(len(self.classes))
        self.height = len(keys)

        # add the classes
        self._classes = [self.classes[key] for key in keys]
        self._numbers = [[dotjoin(i + 1, j + 1) for j in
                          range(len(self._classes[i]))] for i in range(self.height)]

        # create an index which allows to quickly interchange between classes
        # and given sequences (trivial without sequence uniqueness
        if self.unique_seqs:
            self.int2ext = {i: indices[tuple(self._classes[i])] for i in range(len(keys))}
        else:
            self.int2ext = {i: [i] for i in range(len(keys))}

        # store sonars if they are passed as a list
        if sonar and sonars:  # == list:
            self._sonars = [sonars[key] for key in keys]
            self._prostrings = list([prosodic_string(s) for s in self._sonars])
        # create sonars if the argument is true
        elif sonar:
            self._sonars = list(
github lingpy / lingpy / lingpy / meaning / colexification.py View on Github external
G[c1][c2]['families'] += [f]
                G[c1][c2]['doculects'] += [t]
                G[c1][c2]['words'] += [entry]
            except:
                G.add_node(c1, ntype='concept')
                G.add_node(c2, ntype='concept')
                G.add_edge(c1, c2, families=[f], doculects=[t], words=[entry])
        for a, b, d in G.edges(data=True):
            d['familyWeight'] = len(set(d['families']))
            d['wordWeight'] = len(d['words'])
            d['doculectWeight'] = len(set(d['doculects']))
            d['family'] = sorted(set(d['families']))
            d['doculects'] = sorted(set(d['doculects']))
    elif bipartite:
        for idx, (c1, c2, t, f, entry) in enumerate(colexifications):
            nindex = dotjoin(t, idx + 1)
            try:
                G[nindex][c1]['weight'] += 1
                G[nindex][c2]['weight'] += 1
            except KeyError:
                G.add_node(nindex, ntype='word', entry=entry, doculect=t, family=f)
                G.add_node(c1, ntype='concept')
                G.add_node(c2, ntype='concept')
                G.add_edge(nindex, c1, weight=1)
                G.add_edge(nindex, c2, weight=1)
    return G