Beispiel #1
0
def ReturnBlossum62Dict():
    from Bio.SubsMat.MatrixInfo import blosum62
    subMat = {}
    for p, v in blosum62.items():
        subMat[p] = v
        subMat[p[::-1]] = v
    return (subMat)
Beispiel #2
0
    def blosum(msa, ref):
        """
        blosum score: sum of BLOSUM(ref, L) for L in all ligands.
        Normalized by the number of sums and min/max blos62 score
        :param msa:
        :param ref:
        :return:
        """
        Mb, mb = max([v for k, v in blosum62.items()
                      ]), min([v for k, v in blosum62.items()])
        out = []
        reflen = len(msa.loc[ref])

        for i in range(reflen):
            norm = 0
            res_list = list(msa.iloc[:, i])
            reference_res = str(msa.iloc[:, i].loc[ref])

            if reference_res not in "-.":
                # now min and max is residue specific
                this_score = -blosum62[
                    (reference_res, reference_res
                     )]  # starts in debt to cover self reference hit
                for res in res_list:
                    if res not in "-.":
                        norm += 1
                        # exception to catch stupid triangular matrix
                        try:
                            bloscore = blosum62[(reference_res, res)]
                        except KeyError:
                            bloscore = blosum62[(res, reference_res)]
                        this_score += bloscore
                # print(", ".join([reference_res, "\t"] + res_list + [str(round(this_freq,2))]))
                out.append(np.round(((this_score / norm) - mb) / (Mb - mb), 2))

        return out
Beispiel #3
0
    dest='dMutRate',
    help='Enter the pct of AA\'s to mutate. Examples: .03, .10, ,... ')

args = parser.parse_args()

# ---------------------------------------------------------------
# constants
# ---------------------------------------------------------------

c_strGoodAAs = re.sub("[BOJUXZ]", "", uppercase)

c_dictSelfScore = {}
c_dictSelfScore["X"] = 0
c_dictdictExchangeScores = {}

for (strAA1, strAA2), fValue in blosum62.items():
    if strAA1 in c_strGoodAAs and strAA2 in c_strGoodAAs:
        if strAA1 != strAA2:
            c_dictdictExchangeScores.setdefault(strAA1,
                                                {})[strAA2] = math.exp(fValue)
            c_dictdictExchangeScores.setdefault(strAA2,
                                                {})[strAA1] = math.exp(fValue)
        else:
            # higher self score should be mutated less, hence negative
            c_dictSelfScore[strAA1] = math.exp(-fValue)
# convert exchanges to weighted chooser objects
c_dictChoosers = {}
for strAA, dictWeights in c_dictdictExchangeScores.items():
    c_dictChoosers[strAA] = weighted_chooser(dictWeights)

# process codon table
Beispiel #4
0
import matplotlib
matplotlib.use("Agg")
from matplotlib import pyplot as pl
import numpy as np

import maps
import standards

DGSolCommand = "dgsol"

gap = "_"

# Amino acid alphabet
aa = "ACDEFGHIKLMNPQRSTVWY" + gap

b62.update({(b, a): v for (a, b), v in b62.items()})  # make BLOSUM62 symmetric


def rank(array):
    order = array.argsort()
    ranks = np.empty(len(array), dtype=int)
    ranks[order] = np.arange(len(array))
    return ranks


def triangle_inequality(matrix):
    # NOTE: only works on square matrices
    if isinstance(matrix, dict):
        N = set()
        for (k1, k2) in matrix.keys():
            N.add(k1)
Beispiel #5
0
from Bio.Seq import Seq
from Bio.SubsMat.MatrixInfo import blosum62
from Bio.Data import CodonTable

from zopy.stats import WeightedChooser
from zopy.dictation import col2dict

# ---------------------------------------------------------------
# constants
# ---------------------------------------------------------------

c_good_aas = re.sub("[BOJUXZ]", "", uppercase)

c_self_score = {}
c_exchange_scores = {}
for (aa1, aa2), value in blosum62.items():
    if aa1 in c_good_aas and aa2 in c_good_aas:
        if aa1 != aa2:
            c_exchange_scores.setdefault(aa1, {})[aa2] = math.exp(value)
            c_exchange_scores.setdefault(aa2, {})[aa1] = math.exp(value)
        else:
            # higher self score should be mutated less, hence negative
            c_self_score[aa1] = math.exp(-value)
# convert exchanges to WeightedChooser objects
c_choosers = {}
for aa, weights in c_exchange_scores.items():
    c_choosers[aa] = WeightedChooser(weights)

# process codon table
c_codons = {}
for codon, aa in CodonTable.unambiguous_dna_by_name[
#! /usr/bin/env python3.2

from homPolDist import writeBothToFile, fastaParser, stripLowerCase
from subprocess import call, check_output
from Bio.Seq import translate
from math import log10
from numpy import median,std
from Bio.SubsMat.MatrixInfo import blosum62 as blosum
import binascii
import sys

blosum62 = {}
for (a,b),val in blosum.items():
    oldT = (a,b)
    newT = (b,a)
    blosum62[tuple(newT)] = val
    blosum62[tuple(oldT)] = val
randGeneFN = "randGene.fasta"
transGeneFN = "transGene.fasta"
# Trans gene no homopolymer errors
tnhpReadsFN = "tnhpReads.fasta"
randSffFN = "randFlow.sff"
transSffFN = "transFlow.sff"
randReadsFN = "randReads.fasta"
transReadsFN = "transReads.fasta"
randCodonAlnInFile = "randCodonAlnInFile.fasta"
transCodonAlnInFile = "transCodonAlnInFile.fasta"
tnhpCodonAlnInFile = "tnhpCodonAlnInFile.fasta"
randCodonAlnOutFile = "randCodonAlnOutFile.fasta"
transCodonAlnOutFile = "transCodonAlnOutFile.fasta"
tnhpCodonAlnOutFile = "tnhpCodonAlnOutFile.fasta"