-
Notifications
You must be signed in to change notification settings - Fork 0
Iterating Records
Adam Taranto edited this page Sep 24, 2024
·
3 revisions
This section explains how to iterate over records in a KmerCountTable
object.
from oxli import KmerCountTable
kct = KmerCountTable(ksize=4)
kct.count("AAAA") # Count 'AAAA'
kct.count("AATT") # Count 'AATT'
kct.count("GGGG") # Count 'GGGG'
kct.count("GGGG") # Count again.
KmerCountTable
objects are iterable in Python.
Remember that count tables are unsorted by default and order will vary between runs. Use dump()
to get sorted records.
# Convert to list
list(kct)
>>> [(73459868045630124, 2), (17832910516274425539, 1), (382727017318141683, 1)]
# Use with generators
[x for x in kct]
>>> [(73459868045630124, 2), (17832910516274425539, 1), (382727017318141683, 1)]
# Make an iterator
table_iterator = iter(kct)
print(next(table_iterator))
>>> (73459868045630124, 2)
print(next(table_iterator))
>>> (17832910516274425539, 1)
print(next(table_iterator))
>>> (382727017318141683, 1)
Installing Oxli
Basic Setup
For Developers
Getting Started
Getting Started
Counting Kmers
Basic Counting
Extracting from Files
Handling Bad Kmers
Looking up Counts
Single Kmer Lookup
Multiple Kmer Lookup
Removing Records Remove Kmers Abundance Filtering
Exploring Count Tables
Iterating Records
Attributes
Set Operations
Basic SetOps
Exporting Data
Histo: Export Frequency Counts
Dump: Write Hash:Count Pairs
Save and Load KmerCountTables