CARVIEW |
Select Language
HTTP/2 200
date: Fri, 25 Jul 2025 03:32:31 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"7e20b5f46c62bc117b406723578e0a09"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=cJYToT8JHkKijVHu6WNu7sIK%2BJ85%2BUbadFijrqK55StSdxTJUSo0INszm4BUtO5jJEqUh4FIxIbjG6qsAh9yxxvNfyUFieNunrXtjwhVlAtzoLKo3TCKY38G4iBN5RCMUT2FAc1hpKaAvomYE%2F5AiQziI9ildwmhJ3kZ1JWlL2MigU8mTrItWceXotiwKEL2Cais%2BZOsW9zuwTiwHErbsKQs6Vm5wzCRY3HIA7N2AiyMnzRj4jE9%2F47NsjBMvPNFURb2PcZVNLvhEB0JyJbYkg%3D%3D--ZfmaYMR9bdbkYwLB--OMpDyF77EcWi%2BoP88KbbIg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1098484850.1753414351; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 03:32:31 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 03:32:31 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: CED2:36A896:11C3C9:1A0CFF:6882FACF
Python wrapper for KMC API · refresh-bio/KMC Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 76
Python wrapper for KMC API
marekkokot edited this page Sep 27, 2019
·
9 revisions
Python wrapper for C++ KMC API is made to mimic C++ API interface. C++ are python are very different languages, so some compromise needs to be made. For example in python it is not possible to pass integer by reference, but in C++ KMC API this is the way the counter of k-mer is returnet. One (rather ugly) workaroud is to wrap integer in a class that is passed by reference in python.
py_kmc_api
module contains following classes:
- CountVec - it contains one filed (value) which is a list of integers being an output parameter of
GetCountersForRead
method ofCKMCFile
class. - Count - it contains one filed (value) which is a single integer being an output parameter of
ReadNextKmer
andCheckKmer
methods ofCKMCFile
class. - LongKmerRepresentation - it contains one field (value) wich is a list of integers being a binary k-mer representation (each integer is, at C++ side 8 byte unsigned), it is used in
to_long
method ofKmerAPI
class - CKMCFileInfo - contains base information of KMC database.
- CKmerAPI - represents a single k-mer.
- CKMCFile - represents a KMC database, that may be opened in one of two modes: listing(only part of it is loaded into memory, privides sequential access to the database), random access (whole database is loaded into memory, provides existence query of a specific k-mer).
The public interface of this classes is described below.
Fields:
- kmer_length - the length of a k-mer
- mode - always 0 (1 for older versions of KMC where quake aware counters were supported)
- counter_size - the numer of bytes used to store each counter in kmc database
- lut_prefix_length - internal parameter of kmc database, see more details in API.pdf
- signature_len - the length of signature (it is also internal parameter used while database was constructed)
- min_count - minimum value of a counter (if some k-mer had lower occurences than this value it is not stored in the database)
- max_count - maximal value of a counter (if some k-mer had higher occurences than this value it is not store int the database)
- both_strands - True if kmc was run without
-b
switch, False otherwise - total_kmers - the total numer of k-mers stored in the database
Methods: None
Fields: None
Methods:
-
init(length)
- constructor, takes one parameter, the length of a k-mer (may be skipped then 1 is taken as a default value) -
init(kmer: KmerAPI)
- constructor that created new object beased on existing one (copy ctor in C++ nomenclature) -
assign(kmer: KmerAPI)
- replace kmer with the one passed by parameter (equivalent of C++ copy assignment operator) -
__eq__(kmer: KmerAPI)
- equality comparison -
__lt__(kmer: KmerAPI)
- lower than comparison -
get_asci_symbol(pos)
- returns symbol at 0-based position -
get_num_symbol(pos)
- same as get_asci_sybol, but encoded (A->0, C->1, G->2, T->3) -
__str__
- converts k-mer to string representation -
to_long(result: LongKmerRepresentation)
- converts k-mer to list of integers being its binary representation (each integer is unsigned 8 byte integer at C++ side) -
reverse
- converts k-mer to its reverse complement -
get_signature(sig_len)
- get the numeric representation of signature of a k-mer. Signature is internal term and generalization of minimizer used to achieve better performance of KMC, the concept is described in detains in the paper describing KMC 2 -
from_string(kmer_str)
- converts string k-mer representation to internal KmerAPI representation
Fields: None
Methods:
-
init
- parameterless constructor -
OpenForRA(file_name)
- open database for random access mode, returns True in case of success, False otherwise -
OpenForListing(file_name)
- open database for listing mdoe, returs True in case of success, False otherwise -
ReadNextKmer(kmer: KmerAPI, count: Count)
- reads next k-mer from the database, both parameters are output parameters, avaiable only in listing mode, returns True if successfully readed next k-mer, False otherwise -
Close
- close opened database -
SetMinCount(x)
- sets the minimum value of a counter, if k-mer has lower value it is treated as non existing one -
GetMinCount()
- returns the value set withSetMinCount
-
SetMaxCount(x)
- sets the maximal value of a counter, if k-mer has greater value it is treated as non existing one -
GetMaxCount
- returns the value set withSetMaxCount
-
GetBothStrands
- returns True if KMC was run without-b
switch, False otherwise -
KmerCount
- returns the number of k-mers in the database (ifSetMinCount
orSetMaxCount
overrides values stored in the database, the database is linearly scanned to count this number, otherwise it simply readed from KMC database header) -
KmerLength
- returns the length of k-mers stored in the databse -
RestartListing
- avaiable in listing mode, sets the internal pointer to first k-mer in the database -
Eof
- avaiable in listing mode, returns True is all k-mers have been listed, False otherwise -
CheckKmer(kmer: KmerAPI, count: Count)
- avaiable in random acssess mode, check if kmer passed by first argument exists in the database, if no it returns False, if yes it returns True, the number of k-mer occurences in the database is returned by the second parameter -
IsKmer(kmer: KmerAPI)
- avaiable in random access mode, returns True if k-mer exists in the database, False otherwise -
ResetMinMaxCounts
- restores default values of min and max values of a counter -
Info
- returns object ofCKMCFileInfo
class containing base kmc database informations -
GetCountersForRead(read, counters: CountVec )
- finds all k-mers from read passed as first argument in the database and sets counters of k-mers in the second parameter (if k-mer do not exists in the database its counter is set to 0, also in case when k-mer in a read contains 'N', it means that len(counters.value) always equls len(read) - k + 1)
You can’t perform that action at this time.