2. Recipe 2: Loading a kDataFrame file from disk

In Recipe 2 we saved a kDataFrame to the disk with the file name kf1.mqf

  1. Load the kf1 kDataFrame in an new kDataFrame.
  2. Verify the loading by printing the kmerSize and total size.

2.1. Implementation

2.1.1. Importing

[1]:
import kProcessor as kp

2.1.2. Loading the kDataFrame

[2]:
kf = kp.kDataFrame.load("kf1") # Note: We didn't write the extension.

2.1.4. Dump the first 10 kmers

[4]:
it = kf.begin()

for i in range(10):
    print(it.getKmer())
    it.next() # Extremely important to move the iterator to the next kmer position.
CCCAACAGAATTAAAAAGTCA
AAATTAAATAACTTTAGCGCA
CCAAATTACAACAAAATTTGG
TTAATCATTTGGTATAATTGC
ACCTCGTATAACTTCGTATAA
AACAATTCAACAGAGAAGGAC
AGGCTAATCGAACAAAACATC
AGGAAAAACTCCAGCCAGTAA
TACGGGTCGCAGTGACCAGGC
CCAGGTAGTACAGCAATCGTA

2.2. Complete Script

import kProcessor as kp

kf = kp.kDataFrame.load("kf1") # Note: We didn't write the extension.

kSize = kf.ksize()

print(f"kSize: {kSize}")

it = kf.begin()

for i in range(10):
    print(it.getKmer())
    it.next() # Extremely important to move the iterator to the next kmer position.