Skip to content

Instantly share code, notes, and snippets.

@cnh
Created November 28, 2017 10:42
Show Gist options
  • Save cnh/5e0dbd028827d89d7ca823be6f9fd517 to your computer and use it in GitHub Desktop.
Save cnh/5e0dbd028827d89d7ca823be6f9fd517 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 28 12:56:51 2017
@author: tp53
'''
'''
http://biopython.org/DIST/docs/api/Bio.SeqUtils-module.html
seq3(seq, custom_map=None, undef_code='Xaa')
source code
Turn a one letter code protein sequence into one with three letter codes.
The single required input argument 'seq' should be a protein sequence using single letter codes, either as a python string or as a Seq or MutableSeq object.
This function returns the amino acid sequence as a string using the three letter amino acid codes. Output follows the IUPAC standard (including ambiguous characters B for "Asx", J for "Xle" and X for "Xaa", and also U for "Sel" and O for "Pyl") plus "Ter" for a terminator given as an asterisk. Any unknown character (including possible gap characters), is changed into 'Xaa' by default.
e.g.
>>> from Bio.SeqUtils import seq3
>>> seq3("MAIVMGRWKGAR*")
'MetAlaIleValMetGlyArgTrpLysGlyAlaArgTer'
You can set a custom translation of the codon termination code using the dictionary "custom_map" argument (which defaults to {'*': 'Ter'}), e.g.
>>> seq3("MAIVMGRWKGAR*", custom_map={"*": "***"})
'MetAlaIleValMetGlyArgTrpLysGlyAlaArg***'
You can also set a custom translation for non-amino acid characters, such as '-', using the "undef_code" argument, e.g.
>>> seq3("MAIVMGRWKGA--R*", undef_code='---')
'MetAlaIleValMetGlyArgTrpLysGlyAla------ArgTer'
If not given, "undef_code" defaults to "Xaa", e.g.
>>> seq3("MAIVMGRWKGA--R*")
'MetAlaIleValMetGlyArgTrpLysGlyAlaXaaXaaArgTer'
This function was inspired by BioPerl's seq3.
"""
from Bio.SeqUtils import seq3
seq3("MAIVMGRWKGAR*")
from Bio.SeqUtils import seq1
seq1("MetAlaIleValMetGlyArgTrpLysGlyAlaArgTer")
seq1("MetAlaIleValMetGlyArgTrpLysGlyAlaArg***", custom_map={"***": "*"})
seq1("MetAlaIleValMetGlyArgTrpLysGlyAla------ArgTer", undef_code='?')
'''
You can set a custom translation of the codon termination code using the dictionary "custom_map" argument (defaulting to {'Ter': '*'}), e.g.
>>> seq1("MetAlaIleValMetGlyArgTrpLysGlyAlaArg***", custom_map={"***": "*"})
'MAIVMGRWKGAR*'
You can also set a custom translation for non-amino acid characters, such as '-', using the "undef_code" argument, e.g.
>>> seq1("MetAlaIleValMetGlyArgTrpLysGlyAla------ArgTer", undef_code='?')
'MAIVMGRWKGA??R*'
If not given, "undef_code" defaults to "X", e.g.
>>> seq1("MetAlaIleValMetGlyArgTrpLysGlyAla------ArgTer")
'MAIVMGRWKGAXXR*'
'''
import rpy2.robjects as robjects
dir(robjects)
from rpy2.robjects.packages import importr
# import R's "base" package
base = importr('base')
# import R's "utils" package
utils = importr('utils')
dir(base)
type(base)
dir(utils)
type(utils)
# select a mirror for R packages
utils.chooseCRANmirror(ind=1) # select the first mirror in the list
# R package names
#packnames = ('ggplot2', 'hexbin')
packnames = ('devtools')
# R vector of strings
from rpy2.robjects.vectors import StrVector
import rpy2.robjects.packages as rpackages
print(rpackages.isinstalled
#print(importr.isinstalled)
# Selectively install what needs to be install.
# We are fancy, just because we can.
#code block below, gives synytax error in the line below,
#maybe try using the 'in' operator
'''
names_to_install = [x for packnames if not rpackages.isinstalled(x)]
if len(names_to_install) > 0:
utils.install_packages(StrVector(names_to_install))
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment