from numpy import array
a = array([1,2,3])
a.dtype # dtype('int32')
a.dtype.kind # 'i', for 'integer'
s = array(['a','b','c'])
s.dtype # dtype('|S1')
s.dtype.kind # 'S' for 'string'
f = array([1., 2., 3.])
f.dtype # dtype('float64')
f.dtype.kind # 'f' for 'float'
Archive for the ‘BioPython’ Category
Check the type of array in Numpy
Monday, March 17th, 2008Return a list of codons from a sequence
Thursday, January 10th, 2008There are no built-in functions (that I know of) for returning a list of codons from a sequence, but making your own is quite simple. This function is from Solution A.5 from the Python Course in Bioinformatics
def codons(s, frame=0):
"""Return a list of codons from a string, s, giving an optional frameshift."""
codons=[]
end=len(s[frame:]) - (len(s[frame:]) % 3) - 1
for i in range(frame,end,3):
codons.append(s[i:i+3])
return codons
A quick codon table
Wednesday, December 5th, 2007Sometimes it’s nice to be able to have a codon table handy. Rather than typing out one by hand, theTranslate module contains the codon table of your choice in dictionary form: (more…)
Read FASTA files with BioPython
Wednesday, December 5th, 2007Here are several ways to parse a FASTA file into BioPython Seq objects.
Getting a FASTA file into Python is as simple as importing the necessary functions from BioPython, opening the file, and calling a parser on the file. Then you have sequences in BioPython that can be readily used. There are a couple of different ways to parse the file, depending on your preference. Choices are: (more…)
Working with BioPython Sequences
Sunday, December 2nd, 2007Much of BioPython uses Seq objects for dealing with sequences of all kinds. Here’s how to create, get the complement, transcribe, and translate sequences, either from scratch or from a FASTA or GenBank file. (more…)
Run BLAST from BioPython
Sunday, December 2nd, 2007BioPython can send sequences directly to NCBI and will download the results when they’re ready. Once you have the output, you can parse it to, say, just pull out the hits with the top 10 lowest E values. Or generate a list of the species most frequently found in the results . . . or other useful things. (more…)
Parse GenBank files with BioPython
Sunday, December 2nd, 2007BioPython handles GenBank files nicely. Here are a couple of ways of getting them into Python and working with them. (more…)