Esempio n. 1
0
    def __format__(self, format_spec):
        """Returns the alignment as a string in the specified file format.

        This method supports the python format() function added in
        Python 2.6/3.0.  The format_spec should be a lower case
        string supported by Bio.AlignIO as an output file format.
        See also the alignment's format() method."""
        if format_spec:
            from anarci.Bio._py3k import StringIO
            from anarci.Bio import AlignIO
            handle = StringIO()
            AlignIO.write([self], handle, format_spec)
            return handle.getvalue()
        else:
            # Follow python convention and default to using __str__
            return str(self)
Esempio n. 2
0
    def __format__(self, format_spec):
        """Returns the record as a string in the specified file format.

        This method supports the python format() function added in
        Python 2.6/3.0.  The format_spec should be a lower case string
        supported by Bio.SeqIO as an output file format. See also the
        SeqRecord's format() method.

        Under Python 3 please note that for binary formats a bytes
        string is returned, otherwise a (unicode) string is returned.
        """
        if not format_spec:
            # Follow python convention and default to using __str__
            return str(self)
        from anarci.Bio import SeqIO
        if format_spec in SeqIO._BinaryFormats:
            # Return bytes on Python 3
            from io import BytesIO
            handle = BytesIO()
        else:
            from anarci.Bio._py3k import StringIO
            handle = StringIO()
        SeqIO.write(self, handle, format_spec)
        return handle.getvalue()
Esempio n. 3
0
 def get(self, offset):
     return self._parse(StringIO(_bytes_to_string(self.get_raw(offset))))
Esempio n. 4
0
>>><<<


579 residues in 3 query   sequences
45119 residues in 180 library sequences
 Scomplib [34.26]
 start: Tue May 20 16:38:45 2008 done: Tue May 20 16:38:45 2008
 Total Scan time:  0.020 Total Display time:  0.010

Function used was FASTA [version 34.26 January 12, 2007]

"""

    from anarci.Bio._py3k import StringIO

    alignments = list(FastaM10Iterator(StringIO(simple_example)))
    assert len(alignments) == 4, len(alignments)
    assert len(alignments[0]) == 2
    for a in alignments:
        print("Alignment %i sequences of length %i" %
              (len(a), a.get_alignment_length()))
        for r in a:
            print("%s %s %i" % (r.seq, r.id, r.annotations["original_length"]))
        # print(a.annotations)
    print("Done")

    import os
    path = "../../Tests/Fasta/"
    files = sorted(f for f in os.listdir(path)
                   if os.path.splitext(f)[-1] == ".m10")
    for filename in files:
Esempio n. 5
0
            raise ValueError("Need a DNA, RNA or Protein alphabet")


if __name__ == "__main__":
    from anarci.Bio._py3k import StringIO
    print("Quick self test")
    print("")
    print("Repeated names without a TAXA block")
    handle = StringIO("""#NEXUS
    [TITLE: NoName]

    begin data;
    dimensions ntax=4 nchar=50;
    format interleave datatype=protein   gap=- symbols="FSTNKEYVQMCLAWPHDRIG";

    matrix
    CYS1_DICDI          -----MKVIL LFVLAVFTVF VSS------- --------RG IPPEEQ---- 
    ALEU_HORVU          MAHARVLLLA LAVLATAAVA VASSSSFADS NPIRPVTDRA ASTLESAVLG 
    CATH_HUMAN          ------MWAT LPLLCAGAWL LGV------- -PVCGAAELS VNSLEK----
    CYS1_DICDI          -----MKVIL LFVLAVFTVF VSS------- --------RG IPPEEQ---X
    ;
    end; 
    """)
    for a in NexusIterator(handle):
        print(a)
        for r in a:
            print("%r %s %s" % (r.seq, r.name, r.id))
    print("Done")

    print("")
    print("Repeated names with a TAXA block")
Esempio n. 6
0
 def get(self, offset):
     """Returns SeqRecord."""
     # Should be overridden for binary file formats etc:
     return self._parse(StringIO(_bytes_to_string(self.get_raw(offset))))