コード例 #1
0
ファイル: mage.py プロジェクト: miklou/pycogent
def MagePointFromBaseFreqs(freqs, get_label=None, get_color=None, \
    get_radius=None):
    """Returns a MagePoint from an object with counts for the bases.
    
    get_label should be a function that calculates a label from the freqs.
    If get_label is not supplied, checks freqs.Label, freqs.Species, freqs.Id,
    freqs.Accession, and freqs.Name in that order. If get_label fails or none
    of the attributes is found, no label is written.

    get_color should be a function that calculates a color from the freqs. 
    Default is no color (i.e. the point has the color for the series), which
    will also happen if get_color fails.

    get_radius is similar to get_color.
    """
    label = None
    if get_label:
        try:
            label = get_label(freqs)
        except:
            pass    #label will be assigned None below
    else:
        for attr in ['Label', 'Species', 'Id', 'Accession', 'Name']:
            if hasattr(freqs, attr):
                label = getattr(freqs, attr)
                #keep going if the label is empty
                if label is not None and label != '':
                    break
    if not label and label != 0:
        label = None
    if get_color:
        try:
            color = get_color(freqs)
        except:
            color=None
    else:
        if hasattr(freqs, 'Color'):
            color = freqs.Color
        else:
            color = None
            
    if get_radius:
        try:
            radius = get_radius(freqs)
        except:
            radius=None
    else:
        if hasattr(freqs, 'Radius'):
            try:
                radius = float(freqs.Radius)
            except:
                radius = None
        else:
            radius = None
            
    relevant = Freqs({'A':freqs.get('A',0), 'C':freqs.get('C',0), 
        'G':freqs.get('G',0), 'U':freqs.get('U',0) or  freqs.get('T',0)})
    relevant.normalize()
    return MagePoint((relevant['A'],relevant['C'],relevant['G']), Label=label,\
        Color=color, Radius=radius)
コード例 #2
0
ファイル: mage.py プロジェクト: cxhernandez/pycogent
def MagePointFromBaseFreqs(freqs, get_label=None, get_color=None, \
    get_radius=None):
    """Returns a MagePoint from an object with counts for the bases.
    
    get_label should be a function that calculates a label from the freqs.
    If get_label is not supplied, checks freqs.Label, freqs.Species, freqs.Id,
    freqs.Accession, and freqs.Name in that order. If get_label fails or none
    of the attributes is found, no label is written.

    get_color should be a function that calculates a color from the freqs. 
    Default is no color (i.e. the point has the color for the series), which
    will also happen if get_color fails.

    get_radius is similar to get_color.
    """
    label = None
    if get_label:
        try:
            label = get_label(freqs)
        except:
            pass    #label will be assigned None below
    else:
        for attr in ['Label', 'Species', 'Id', 'Accession', 'Name']:
            if hasattr(freqs, attr):
                label = getattr(freqs, attr)
                #keep going if the label is empty
                if label is not None and label != '':
                    break
    if not label and label != 0:
        label = None
    if get_color:
        try:
            color = get_color(freqs)
        except:
            color=None
    else:
        if hasattr(freqs, 'Color'):
            color = freqs.Color
        else:
            color = None
            
    if get_radius:
        try:
            radius = get_radius(freqs)
        except:
            radius=None
    else:
        if hasattr(freqs, 'Radius'):
            try:
                radius = float(freqs.Radius)
            except:
                radius = None
        else:
            radius = None
            
    relevant = Freqs({'A':freqs.get('A',0), 'C':freqs.get('C',0), 
        'G':freqs.get('G',0), 'U':freqs.get('U',0) or  freqs.get('T',0)})
    relevant.normalize()
    return MagePoint((relevant['A'],relevant['C'],relevant['G']), Label=label,\
        Color=color, Radius=radius)
コード例 #3
0
    def codons(self, genetic_code=SGC, codon_usage=_equal_codons):
        """Predicts most likely set of codon frequencies.

        Optionally uses genetic_code (to figure out which codons belong
        with each amino acid), and codon_usage (to get most likely codons for
        each amino acid). Defaults are the standard genetic code and unbiased
        codon frequencies.
        """
        result = {}
        normalized = Freqs(self)
        normalized.normalize()
        for aa, aa_freq in list(normalized.items()):
            curr_codons = [c.upper().replace('T','U') for c in genetic_code[aa]]
            if not curr_codons:
                continue    #code might be missing some amino acids?
            curr_codon_freqs = Numbers([codon_usage[c] for c in curr_codons])
            curr_codon_freqs.normalize()
            for codon, c_freq in zip(curr_codons, curr_codon_freqs):
                result[codon] = c_freq * aa_freq
        return CodonUsage(result, self.info, genetic_code)
コード例 #4
0
ファイル: usage.py プロジェクト: GavinHuttley/pycogent
    def codons(self, genetic_code=SGC, codon_usage=_equal_codons):
        """Predicts most likely set of codon frequencies.

        Optionally uses genetic_code (to figure out which codons belong
        with each amino acid), and codon_usage (to get most likely codons for 
        each amino acid). Defaults are the standard genetic code and unbiased 
        codon frequencies.
        """
        result = {}
        normalized = Freqs(self)
        normalized.normalize()
        for aa, aa_freq in normalized.items():
            curr_codons = [c.upper().replace('T','U') for c in genetic_code[aa]]
            if not curr_codons:
                continue    #code might be missing some amino acids?
            curr_codon_freqs = Numbers([codon_usage[c] for c in curr_codons])
            curr_codon_freqs.normalize()
            for codon, c_freq in zip(curr_codons, curr_codon_freqs):
                result[codon] = c_freq * aa_freq
        return CodonUsage(result, self.info, genetic_code)
コード例 #5
0
ファイル: mage.py プロジェクト: pombredanne/pycogent-1
def MagePointFromBaseFreqs(freqs, get_label=None, get_color=None, get_radius=None):
    """Returns a MagePoint from an object with counts for the bases.
    
    get_label should be a function that calculates a label from the freqs.
    If get_label is not supplied, checks freqs.Label, freqs.Species, freqs.Id,
    freqs.Accession, and freqs.Name in that order. If get_label fails or none
    of the attributes is found, no label is written.

    get_color should be a function that calculates a color from the freqs. 
    Default is no color (i.e. the point has the color for the series), which
    will also happen if get_color fails.

    get_radius is similar to get_color.
    """
    label = None
    if get_label:
        try:
            label = get_label(freqs)
        except:
            pass  # label will be assigned None below
    else:
        for attr in ["Label", "Species", "Id", "Accession", "Name"]:
            if hasattr(freqs, attr):
                label = getattr(freqs, attr)
                # keep going if the label is empty
                if label is not None and label != "":
                    break
    if not label and label != 0:
        label = None
    if get_color:
        try:
            color = get_color(freqs)
        except:
            color = None
    else:
        if hasattr(freqs, "Color"):
            color = freqs.Color
        else:
            color = None

    if get_radius:
        try:
            radius = get_radius(freqs)
        except:
            radius = None
    else:
        if hasattr(freqs, "Radius"):
            try:
                radius = float(freqs.Radius)
            except:
                radius = None
        else:
            radius = None

    relevant = Freqs(
        {
            "A": freqs.get("A", 0),
            "C": freqs.get("C", 0),
            "G": freqs.get("G", 0),
            "U": freqs.get("U", 0) or freqs.get("T", 0),
        }
    )
    relevant.normalize()
    return MagePoint((relevant["A"], relevant["C"], relevant["G"]), Label=label, Color=color, Radius=radius)