Beispiel #1
0
    def test_both_ways(self):
        filename = "Roche/E3MFGYR02_random_10_reads.sff"
        with open(filename, "rb") as handle:
            index1 = sorted(_sff_read_roche_index(handle))
        with open(filename, "rb") as handle:
            index2 = sorted(_sff_do_slow_index(handle))
        self.assertEqual(index1, index2)
        with open(filename, "rb") as handle:
            self.assertEqual(len(index1), len(list(SffIterator(handle))))
        with open(filename, "rb") as handle:
            self.assertEqual(len(index1),
                             len(list(SffIterator(BytesIO(handle.read())))))

        if sys.platform != "win32" and sys.version_info[0] < 3:
            # Can be lazy and treat as binary...
            with open(filename, "r") as handle:
                self.assertEqual(len(index1), len(list(SffIterator(handle))))
            with open(filename) as handle:
                index2 = sorted(_sff_read_roche_index(handle))
            self.assertEqual(index1, index2)
            with open(filename, "r") as handle:
                index2 = sorted(_sff_do_slow_index(handle))
            self.assertEqual(index1, index2)
            with open(filename, "r") as handle:
                self.assertEqual(len(index1), len(list(SffIterator(handle))))
            with open(filename, "r") as handle:
                self.assertEqual(
                    len(index1),
                    len(list(SffIterator(BytesIO(handle.read())))))
Beispiel #2
0
    def test_both_ways(self):
        filename = "Roche/E3MFGYR02_random_10_reads.sff"
        with open(filename, "rb") as handle:
            index1 = sorted(_sff_read_roche_index(handle))
        with open(filename, "rb") as handle:
            index2 = sorted(_sff_do_slow_index(handle))
        self.assertEqual(index1, index2)
        with open(filename, "rb") as handle:
            self.assertEqual(len(index1), len(list(SffIterator(handle))))
        with open(filename, "rb") as handle:
            self.assertEqual(len(index1), len(list(SffIterator(BytesIO(handle.read())))))

        if sys.platform != "win32" and sys.version_info[0] < 3:
            # Can be lazy and treat as binary...
            with open(filename, "r") as handle:
                self.assertEqual(len(index1), len(list(SffIterator(handle))))
            with open(filename) as handle:
                index2 = sorted(_sff_read_roche_index(handle))
            self.assertEqual(index1, index2)
            with open(filename, "r") as handle:
                index2 = sorted(_sff_do_slow_index(handle))
            self.assertEqual(index1, index2)
            with open(filename, "r") as handle:
                self.assertEqual(len(index1), len(list(SffIterator(handle))))
            with open(filename, "r") as handle:
                self.assertEqual(len(index1), len(list(SffIterator(BytesIO(handle.read())))))
 def test_index(self):
     filename = "Roche/greek.sff"
     with open(filename, "rb") as a_handle, open(filename,
                                                 "rb") as b_handle:
         index1 = sorted(_sff_read_roche_index(a_handle))
         index2 = sorted(_sff_do_slow_index(b_handle))
         self.assertEqual(index1, index2)
Beispiel #4
0
 def test_index(self):
     filename = "Roche/greek.sff"
     # with open(filename, "rb") as handle:
     #     for record in SffIterator(handle):
     #         print(record.id)
     with open(filename, "rb") as a_handle, open(filename, "rb") as b_handle:
         index1 = sorted(_sff_read_roche_index(a_handle))
         index2 = sorted(_sff_do_slow_index(b_handle))
         self.assertEqual(index1, index2)
Beispiel #5
0
 def test_index(self):
     filename = "Roche/greek.sff"
     # with open(filename, "rb") as handle:
     #     for record in SffIterator(handle):
     #         print(record.id)
     with open(filename, "rb") as a_handle, open(filename, "rb") as b_handle:
         index1 = sorted(_sff_read_roche_index(a_handle))
         index2 = sorted(_sff_do_slow_index(b_handle))
         self.assertEqual(index1, index2)
Beispiel #6
0
 def test_both_ways(self):
     filename = "Roche/E3MFGYR02_random_10_reads.sff"
     with open(filename, "rb") as handle:
         index1 = sorted(_sff_read_roche_index(handle))
     with open(filename, "rb") as handle:
         index2 = sorted(_sff_do_slow_index(handle))
     self.assertEqual(index1, index2)
     with open(filename, "rb") as handle:
         self.assertEqual(len(index1), len(list(SffIterator(handle))))
     with open(filename, "rb") as handle:
         self.assertEqual(len(index1), len(list(SffIterator(BytesIO(handle.read())))))
Beispiel #7
0
        w._flow_chars = records[0].annotations["flow_chars"]
        w._number_of_flows_per_read = len(w._flow_chars)
        w.write_header()
        w._index_start = out_handle.tell()
        w._index_length = len(index)
        out_handle.seek(0)
        w.write_header()  # this time with index info
        w.handle.write(index)
        for record in records:
            w.write_record(record)
    with open("Roche/E3MFGYR02_alt_index_at_start.sff", "rb") as handle:
        records2 = list(SffIterator(handle))
    for old, new in zip(records, records2):
        assert old.seq == new.seq
    with open("Roche/E3MFGYR02_alt_index_at_start.sff", "rb") as handle:
        i = list(_sff_do_slow_index(handle))

    # Ugly bit of code to make a fake index in middle
    index = ".diy1.00This is a fake index block (DIY = Do It Yourself), which is allowed under the SFF standard.\0"
    padding = len(index) % 8
    if padding:
        padding = 8 - padding
    index += chr(0) * padding
    with open("Roche/E3MFGYR02_random_10_reads.sff", "rb") as handle:
        records = list(SffIterator(handle))
    with open("Roche/E3MFGYR02_alt_index_in_middle.sff", "w") as out_handle:
        w = SffWriter(out_handle, index=False, xml=None)
        # Fake the header...
        w._number_of_reads = len(records)
        w._index_start = 0
        w._index_length = 0
Beispiel #8
0
    w._number_of_flows_per_read = len(w._flow_chars)
    w.write_header()
    w._index_start = out_handle.tell()
    w._index_length = len(index)
    out_handle.seek(0)
    w.write_header()  # this time with index info
    w.handle.write(index)
    for record in records:
        w.write_record(record)
    out_handle.close()
    records2 = list(
        SffIterator(open("Roche/E3MFGYR02_alt_index_at_start.sff", "rb")))
    for old, new in zip(records, records2):
        assert str(old.seq) == str(new.seq)
    i = list(
        _sff_do_slow_index(open("Roche/E3MFGYR02_alt_index_at_start.sff",
                                "rb")))

    # Ugly bit of code to make a fake index in middle
    records = list(
        SffIterator(open("Roche/E3MFGYR02_random_10_reads.sff", "rb")))
    out_handle = open("Roche/E3MFGYR02_alt_index_in_middle.sff", "w")
    index = ".diy1.00This is a fake index block (DIY = Do It Yourself), which is allowed under the SFF standard.\0"
    padding = len(index) % 8
    if padding:
        padding = 8 - padding
    index += chr(0) * padding
    w = SffWriter(out_handle, index=False, xml=None)
    # Fake the header...
    w._number_of_reads = len(records)
    w._index_start = 0
    w._index_length = 0
Beispiel #9
0
        w._flow_chars = records[0].annotations["flow_chars"]
        w._number_of_flows_per_read = len(w._flow_chars)
        w.write_header()
        w._index_start = out_handle.tell()
        w._index_length = len(index)
        out_handle.seek(0)
        w.write_header()  # this time with index info
        w.handle.write(index)
        for record in records:
            w.write_record(record)
        out_handle.close()
        records2 = list(SffIterator(
            open("Roche/E3MFGYR02_alt_index_at_start.sff", "rb")))
        for old, new in zip(records, records2):
            assert str(old.seq) == str(new.seq)
        i = list(_sff_do_slow_index(
            open("Roche/E3MFGYR02_alt_index_at_start.sff", "rb")))

        # Ugly bit of code to make a fake index in middle
        records = list(SffIterator(
            open("Roche/E3MFGYR02_random_10_reads.sff", "rb")))
        out_handle = open(
            "Roche/E3MFGYR02_alt_index_in_middle.sff", "w")
        index = ".diy1.00This is a fake index block (DIY = Do It Yourself), which is allowed under the SFF standard.\0"
        padding = len(index) % 8
        if padding:
            padding = 8 - padding
        index += chr(0) * padding
        w = SffWriter(out_handle, index=False, xml=None)
        # Fake the header...
        w._number_of_reads = len(records)
        w._index_start = 0