Package: zhuntr
Z-Hunt(r)This repository contains a Rust port of theZ-Hunt algorithm, which is
designed to predict the propensity of DNA to adopt a left-handed Z-DNA conformation. Unlike the original implementation,
this version is intended to be used as a standalone Python library.This Rust port is fully compatible with the original C implementation. Please refer to
theCompatibilitysection for more details.InstallationThe library can be installed from PyPI usingpip:pipinstallzhuntrUsageHere is a simple example of how to use the library in Python:importzhuntrsequence="nATGCGCGCGGCATGC".encode("ASCII")# The target sequence (only ATGCN are accepted, case insensitive)mindn,maxdn=3,6# Minimum and maximum length of evaluated DNA windows in dinucleotidesthreshold=1_000# Windows with a ZH-score below this threshold will not be reported# Make a predictionstart,end,score,window,conformation=zhuntr.predict(sequence,mindn,maxdn,threshold)# start: start coordinates of evaluated DNA windowsassertstart==[0,1,2]# end: end coordinates of DNA windows starting at the above coordinates and#      having the highest ZH-score among [mindn; maxdn] windowsassertend==[10,11,10]# score: ZH-score for each windowassert[int(zh)forzhinscore]==[2220,1057,3428]# window: DNA sequence for each window:#         window[i] = sequence[start[i]:end[i]]assertwindow==['NATGCGCGCG','ATGCGCGCGG','TGCGCGCG']# conformation: DNA conformation (anti/syn) for each windowassertconformation==['ASASASASAS','SASASASASA','ASASASAS']Note: the default behaviour of the original implementation is to "wrap around" windows at the end of the sequence.
It can be enabled by passingwrap=Trueto thepredictfunction.The library also supports stream predictions, wherein the sequence is evaluated slice by slice to minimize the memory
footprint and allow interruption when required. This feature is especially useful when processing large sequences:slice_size=512# Size of each slice, default is 1024forstart,end,score,window,conformationinzhuntr.stream(sequence,mindn,maxdn,threshold,ssize=slice_size):length=len(start)# The last slice may be shorter than slice_size but not emptyassert0<length<=slice_size# All arrays have the same length and semantics as beforeassertlen(start)==len(end)==len(score)==len(window)==len(conformation)...This mode is equivalent to callingzhuntr.predicton the entire sequence and processing the output slice by slice,
where each slice has a size equal tossize, except, perhaps, for the last one. Note that the 'wrapping around' of the
sequence in this mode occurs as usual, i.e., only once, and all coordinates are provided relative to the original
sequence.CompatibilityThis version has been tested against the original C implementation compiled with all compile optimizations turned off.
The output for human mtDNA, a random 1kb sequence, and subsequences of human chrY or HSV-1 genome matches the output of
the C implementation (see tests; 12 digits after the decimal point are identical).Reference outputs were generated using thetests/resources/make-references.shscript. The reference implementation
used is also provided in the same folder (zhunt3-reference.c).DevelopmentPublishing to PyPI is done automatically by the CI pipeline. To publish a new version, simply create a new tag and push
it to the repository. The CI pipeline will take care of the rest.