Exemple #1
0
def write(motifs, format):
    """Return a string representation of motifs in the given format.

    Currently supported formats (case is ignored):
     - clusterbuster: Cluster Buster position frequency matrix format
     - pfm : JASPAR simple single Position Frequency Matrix
     - jaspar : JASPAR multiple PFM format
     - transfac : TRANSFAC like files

    """
    format = format.lower()
    if format in ("pfm", "jaspar"):
        from Bio.motifs import jaspar

        return jaspar.write(motifs, format)
    elif format == "transfac":
        from Bio.motifs import transfac

        return transfac.write(motifs)
    elif format == "clusterbuster":
        from Bio.motifs import clusterbuster

        return clusterbuster.write(motifs)
    else:
        raise ValueError("Unknown format type %s" % format)
Exemple #2
0
    def __format__(self, format_spec):
        """Return a string representation of the Motif in the given format.

        Currently supported formats:
         - clusterbuster: Cluster Buster position frequency matrix format
         - pfm : JASPAR single Position Frequency Matrix
         - jaspar : JASPAR multiple Position Frequency Matrix
         - transfac : TRANSFAC like files

        """
        if format_spec in ("pfm", "jaspar"):
            from Bio.motifs import jaspar

            motifs = [self]
            return jaspar.write(motifs, format_spec)
        elif format_spec == "transfac":
            from Bio.motifs import transfac

            motifs = [self]
            return transfac.write(motifs)
        elif format_spec == "clusterbuster":
            from Bio.motifs import clusterbuster

            motifs = [self]
            return clusterbuster.write(motifs)
        else:
            raise ValueError("Unknown format type %s" % format_spec)
Exemple #3
0
 def _PSSM_model_to_jaspar(self, filename):
     """Writes the PSSM to the given file in jaspar format."""
     header = self.strain_name
     jaspar_motif = jaspar.Motif(matrix_id='', name=header,
                                 counts=self.TF_binding_model.pwm)
     with open(filename, 'w') as f:
         f.write(jaspar.write([jaspar_motif], 'jaspar'))
Exemple #4
0
 def to_jaspar(self, filename):
     """Writes the PWM to the given file in JASPAR format."""
     jaspar_motif = jaspar.Motif(matrix_id=self.TF.accession_number,
                                 name=self.name,
                                 instances=self._motif.instances)
     with open(filename, 'w') as f:
         f.write(jaspar.write([jaspar_motif], 'jaspar'))
Exemple #5
0
 def _PSSM_model_to_jaspar(self, filename):
     """Writes the PSSM to the given file in jaspar format."""
     header = self.strain_name
     jaspar_motif = jaspar.Motif(matrix_id='',
                                 name=header,
                                 counts=self.TF_binding_model.pwm)
     with open(filename, 'w') as f:
         f.write(jaspar.write([jaspar_motif], 'jaspar'))
Exemple #6
0
    def format(self, format):
        """Returns a string representation of the Motif in a given format

        Currently supported fromats:
         - pfm : JASPAR Position Frequency Matrix
         - transfac : TRANSFAC like files
        """

        if format=="pfm":
            from Bio.motifs import jaspar
            return jaspar.write(self)
        elif format=="transfac":
            from Bio.motifs import transfac
            motifs = [self]
            return transfac.write(motifs)
        else:
            raise ValueError("Unknown format type %s" % format)
Exemple #7
0
def write(motifs, format):
    """Returns a string representation of motifs in a given format

    Currently supported formats (case is ignored):
     - pfm : JASPAR simple single Position Frequency Matrix
     - jaspar : JASPAR multiple PFM format
     - transfac : TRANSFAC like files
    """
    format = format.lower()
    if format in ("pfm", "jaspar"):
        from Bio.motifs import jaspar
        return jaspar.write(motifs, format)
    elif format == "transfac":
        from Bio.motifs import transfac
        return transfac.write(motifs)
    else:
        raise ValueError("Unknown format type %s" % format)
Exemple #8
0
    def format(self, format):
        """Return a string representation of the Motif in the given format.

        Currently supported fromats:
         - pfm : JASPAR single Position Frequency Matrix
         - jaspar : JASPAR multiple Position Frequency Matrix
         - transfac : TRANSFAC like files

        """
        if format in ('pfm', 'jaspar'):
            from Bio.motifs import jaspar
            motifs = [self]
            return jaspar.write(motifs, format)
        elif format == "transfac":
            from Bio.motifs import transfac
            motifs = [self]
            return transfac.write(motifs)
        else:
            raise ValueError("Unknown format type %s" % format)
Exemple #9
0
    def format(self, format):
        """Return a string representation of the Motif in the given format.

        Currently supported fromats:
         - pfm : JASPAR single Position Frequency Matrix
         - jaspar : JASPAR multiple Position Frequency Matrix
         - transfac : TRANSFAC like files

        """
        if format in ('pfm', 'jaspar'):
            from Bio.motifs import jaspar
            motifs = [self]
            return jaspar.write(motifs, format)
        elif format == "transfac":
            from Bio.motifs import transfac
            motifs = [self]
            return transfac.write(motifs)
        else:
            raise ValueError("Unknown format type %s" % format)
Exemple #10
0
def write(motifs, format):
    """Returns a string representation of motifs in a given format

    Currently supported fromats (case is ignored):
     - pfm : JASPAR Position Frequency Matrix
             [only if len(motifs)==1]
     - transfac : TRANSFAC like files
    """

    format = format.lower()
    if format=="pfm":
        from Bio.motifs import jaspar
        if len(motifs)!=1:
            raise Exception("Only a single motif can be written in the JASPAR Position Frequency Matrix (pfm) format")
        motif = motifs[0]
        return jaspar.write(motif)
    elif format=="transfac":
        from Bio.motifs import transfac
        return transfac.write(motifs)
    else:
        raise ValueError("Unknown format type %s" % format)