~ubuntu-branches/ubuntu/trusty/python-biopython/trusty-proposed

« back to all changes in this revision

Viewing changes to Bio/Motif/_Motif.py

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2009-08-24 09:29:27 UTC
  • mfrom: (1.3.3 upstream) (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090824092927-2wwh36vwnfgn98kl
Tags: 1.51final-2
Merged patch from ubuntu to make the package ready for
python2.6 (Closes: #543236).

Show diffs side-by-side

added added

removed removed

Lines of Context:
757
757
            return formatters[format]()
758
758
        except KeyError:
759
759
            raise ValueError("Wrong format type")
 
760
 
 
761
    def scanPWM(self,seq):
 
762
        """
 
763
        scans (using a fast C extension) a nucleotide sequence and returns the matrix of log-odds scores for all positions
 
764
 
 
765
        - the result is a one-dimensional numpy array
 
766
        - the sequence can only be a DNA sequence
 
767
        - the search is performed only on one strand
 
768
        """
 
769
        if self.alphabet!=IUPAC.unambiguous_dna:
 
770
            raise ValueError("Wrong alphabet! Use only with DNA motifs")
 
771
        if seq.alphabet!=IUPAC.unambiguous_dna:
 
772
            raise ValueError("Wrong alphabet! Use only with DNA sequences")
 
773
 
 
774
        
 
775
        import numpy
 
776
        # get the log-odds matrix into a proper shape (each column contains sorted (ACGT) log-odds values)
 
777
        logodds=numpy.array([map(lambda x: x[1],sorted(x.items())) for x in self.log_odds()]).transpose()
 
778
        
 
779
        import _pwm
 
780
        
 
781
        return _pwm.calculate(seq.tostring(),logodds)