Back to index

python-biopython  1.60
Classes | Functions | Variables
test_GenomeDiagram Namespace Reference

Classes

class  TrackTest
 End of utility functions for graph plotting #. More...
class  ColorsTest
class  GraphTest
class  LabelTest
class  SigilsTest
class  DiagramTest

Functions

def fill_and_border
def apply_to_window
 Utility functions for graph plotting, originally in GenomeDiagram.Utilities # See Bug 2705 for discussion on where to put these functions in Biopython...
def calc_gc_content
def calc_at_content
def calc_gc_skew
def calc_at_skew
def calc_dinucleotide_counts

Variables

tuple runner = unittest.TextTestRunner(verbosity = 2)

Class Documentation

class test_GenomeDiagram::TrackTest

End of utility functions for graph plotting #.

Definition at line 190 of file test_GenomeDiagram.py.


Function Documentation

def test_GenomeDiagram.apply_to_window (   sequence,
  window_size,
  function,
  step = None 
)

Utility functions for graph plotting, originally in GenomeDiagram.Utilities # See Bug 2705 for discussion on where to put these functions in Biopython...

apply_to_window(sequence, window_size, function) -> [(int, float),(int, float),...]

    o sequence      Bio.Seq.Seq object

    o window_size   Int describing the length of sequence to consider

    o step          Int describing the step to take between windows
                    (default = window_size//2)

    o function      Method or function that accepts a Bio.Seq.Seq object
                    as its sole argument and returns a single value

    Returns a list of (position, value) tuples for fragments of the passed
    sequence of length window_size (stepped by step), calculated by the
    passed function.  Returned positions are the midpoint of each window.

Definition at line 54 of file test_GenomeDiagram.py.

00054 
00055 def apply_to_window(sequence, window_size, function, step=None):
00056     """ apply_to_window(sequence, window_size, function) -> [(int, float),(int, float),...]
00057 
00058         o sequence      Bio.Seq.Seq object
00059 
00060         o window_size   Int describing the length of sequence to consider
00061 
00062         o step          Int describing the step to take between windows
00063                         (default = window_size//2)
00064 
00065         o function      Method or function that accepts a Bio.Seq.Seq object
00066                         as its sole argument and returns a single value
00067 
00068         Returns a list of (position, value) tuples for fragments of the passed
00069         sequence of length window_size (stepped by step), calculated by the
00070         passed function.  Returned positions are the midpoint of each window.
00071     """
00072     seqlen = len(sequence)      # Total length of sequence to be used
00073     if step is None:    # No step specified, so use half window-width or 1 if larger
00074         step = max(window_size//2, 1)
00075     else:               # Use specified step, or 1 if greater
00076         step = max(step, 1)
00077 
00078     results = []    # Holds (position, value) results
00079 
00080     # Perform the passed function on as many windows as possible, short of
00081     # overrunning the sequence
00082     pos = 0
00083     while pos < seqlen-window_size+1:
00084         # Obtain sequence fragment
00085         start, middle, end = pos, (pos+window_size+pos)//2, pos+window_size
00086         fragment = sequence[start:end]
00087         # Apply function to the sequence fragment
00088         value = function(fragment)
00089         results.append((middle, value)) # Add results to list
00090         # Advance to next fragment
00091         pos += step
00092 
00093     # Use the last available window on the sequence, even if it means
00094     # re-covering old ground
00095     if pos != seqlen - window_size:
00096         # Obtain sequence fragment
00097         pos = seqlen - window_size
00098         start, middle, end = pos, (pos+window_size+pos)//2, pos+window_size
00099         fragment = sequence[start:end]
00100         # Apply function to sequence fragment
00101         value = function(fragment)
00102         results.append((middle, value)) # Add results to list
00103         
00104     # Check on last sequence
00105     #print fragment
00106     #print seq[-100:]
00107     return results      # Return the list of (position, value) results

Here is the caller graph for this function:

calc_at_content(sequence)

    o sequence  A Bio.Seq.Seq object

    Returns the % A+T content in a passed sequence

Definition at line 125 of file test_GenomeDiagram.py.

00125 
00126 def calc_at_content(sequence):
00127     """ calc_at_content(sequence)
00128 
00129         o sequence  A Bio.Seq.Seq object
00130 
00131         Returns the % A+T content in a passed sequence
00132     """
00133     d = {}
00134     for nt in ['A','T','G','C']:
00135         d[nt] = sequence.count(nt) + sequence.count(nt.lower())
00136     at = d.get('A',0) + d.get('T',0)
00137 
00138     if at == 0: return 0
00139     return at*1./(d['G'] +d['G'] + at)
00140 

def test_GenomeDiagram.calc_at_skew (   sequence)
calc_at_skew(sequence)

    o sequence   A Bio.Seq.Seq object

    Returns the (A-T)/(A+T) AT skew in a passed sequence

Definition at line 156 of file test_GenomeDiagram.py.

00156 
00157 def calc_at_skew(sequence):
00158     """ calc_at_skew(sequence)
00159 
00160         o sequence   A Bio.Seq.Seq object
00161 
00162         Returns the (A-T)/(A+T) AT skew in a passed sequence
00163     """
00164     a = sequence.count('A') + sequence.count('a')
00165     t = sequence.count('T') + sequence.count('t')
00166     if a+t == 0:
00167         return 0.0 #TODO - return NaN or None here?
00168     else:
00169         return (a-t)/float(a+t)

Returns the total count of di-nucleotides repeats (e.g. "AA", "CC").

This is purely for the sake of generating some non-random sequence
based score for plotting, with no expected biological meaning.

NOTE - Only considers same case pairs.
NOTE - "AA" scores 1, "AAA" scores 2, "AAAA" scores 3 etc.

Definition at line 170 of file test_GenomeDiagram.py.

00170 
00171 def calc_dinucleotide_counts(sequence):
00172     """Returns the total count of di-nucleotides repeats (e.g. "AA", "CC").
00173 
00174     This is purely for the sake of generating some non-random sequence
00175     based score for plotting, with no expected biological meaning.
00176 
00177     NOTE - Only considers same case pairs.
00178     NOTE - "AA" scores 1, "AAA" scores 2, "AAAA" scores 3 etc.
00179     """
00180     total = 0
00181     for letter in "ACTGUactgu":
00182         total += sequence.count(letter+letter)
00183     return total
00184     

calc_gc_content(sequence)

    o sequence  A Bio.Seq.Seq object

    Returns the % G+C content in a passed sequence

Definition at line 108 of file test_GenomeDiagram.py.

00108 
00109 def calc_gc_content(sequence):
00110     """ calc_gc_content(sequence)
00111 
00112         o sequence  A Bio.Seq.Seq object
00113 
00114         Returns the % G+C content in a passed sequence
00115     """
00116     d = {}
00117     for nt in ['A','T','G','C']:
00118         d[nt] = sequence.count(nt) + sequence.count(nt.lower())
00119     gc = d.get('G',0) + d.get('C',0)
00120 
00121     if gc == 0: return 0
00122     #print gc*100.0/(d['A'] +d['T'] + gc)
00123     return gc*1./(d['A'] +d['T'] + gc)
00124 

def test_GenomeDiagram.calc_gc_skew (   sequence)
calc_gc_skew(sequence)

    o sequence   A Bio.Seq.Seq object

    Returns the (G-C)/(G+C) GC skew in a passed sequence

Definition at line 141 of file test_GenomeDiagram.py.

00141 
00142 def calc_gc_skew(sequence):
00143     """ calc_gc_skew(sequence)
00144 
00145         o sequence   A Bio.Seq.Seq object
00146 
00147         Returns the (G-C)/(G+C) GC skew in a passed sequence
00148     """
00149     g = sequence.count('G') + sequence.count('g')
00150     c = sequence.count('C') + sequence.count('c')
00151     if g+c == 0:
00152         return 0.0 #TODO - return NaN or None here?
00153     else:
00154         return (g-c)/float(g+c)
00155 

def test_GenomeDiagram.fill_and_border (   base_color,
  alpha = 0.5 
)

Definition at line 41 of file test_GenomeDiagram.py.

00041 
00042 def fill_and_border(base_color, alpha=0.5):
00043     try:
00044         c = base_color.clone()
00045         c.alpha = alpha
00046         return c, base_color
00047     except AttributeError:
00048         #Old ReportLab, no transparency and/or no clone
00049         return base_color, base_color

Here is the caller graph for this function:


Variable Documentation

tuple test_GenomeDiagram.runner = unittest.TextTestRunner(verbosity = 2)

Definition at line 880 of file test_GenomeDiagram.py.