Package: setriq
setriq: pairwise sequence distancesAPythonpackage written inC++for computing pairwise distances between (immunoglobulin) sequences.DocumentationInstallThis package is available on PyPIpipinstallsetriqQuickstartsetriqinherits from thetorchphilosophy of callable objects. EachMetricsubclass is a callable upon
initialisation, taking a list of objects (usuallystr) and returning a list offloatvalues.importsetriqmetric=setriq.CdrDist()sequences=['CASSLKPNTEAFF','CASSAHIANYGYTF','CASRGATETQYF']distances=metric(sequences)The returned list is flat and containsN * (N - 1) / 2elements, i.e. the lower (or upper) triangle of the distance
matrix. To get the square form of the matrix, usescipy.spatial.distance.squareformon the returned distances.AboutAs the header suggests,setriqis a no-frills Python package for fast computation of pairwise sequence distances, with
a focus on immunoglobulins. It is a declarative framework and borrows many concepts from the populartorchlibrary. It
has been optimized for parallel compute on CPU architectures.Available distance functions:CDRdistLevenshteinTCRdistHammingJaroJaro-WinklerLongest Common SubstringOptimal String AlignmentThese distance functions are available either through the object-based API (as seen above), which provides the CPU-based
parallelism, or the functional API insetriq.single_dispatch. Unlike the object-based API, the functional API does a
single comparison between two sequences for every call, i.e. it exposes theC++distance functions without the
parallelism wrapper. This can be useful for integration ofsetriqwith other tools such asPySpark. For example:frompyspark.sqlimportSparkSessionfrompyspark.sql.functionsimportudffrompyspark.sql.typesimportDoubleTypefromsetriqimportsingle_dispatchassdspark=SparkSession\.builder\.appName("setriq-spark")\.getOrCreate()df=spark.createDataFrame([('CASSLKPNTEAFF',),('CASSAHIANYGYTF',),('CASRGATETQYF',)],['sequence'])df=df.withColumnRenamed('sequence','a').crossJoin(df.withColumnRenamed('sequence','b'))lev_udf=udf(sd.levenshtein,returnType=DoubleType())# single dispatch levenshtein distancedf=df.withColumn('distance',lev_udf('a','b'))df.show()It is important to note, that forsetriq.single_dispatchthe returned value is always a single float value.RequirementsAPythonversion of 3.7 or above is required, as well as aC++compiler equipped with OpenMP. The package has been
tested on Linux and macOS. To get the required OpenMP resources, run:On Linux:sudoaptinstalllibomp-dev&&sudoaptshowlibomp-devOn macOS:brewinstalllibompllvmReferencesDash, P., Fiore-Gartland, A.J., Hertz, T., Wang, G.C., Sharma, S., Souquette, A., Crawford, J.C., Clemens, E.B.,
Nguyen, T.H., Kedzierska, K. and La Gruta, N.L., 2017. Quantifiable predictive features define epitope-specific T cell
receptor repertoires. Nature, 547(7661), pp.89-93. (https://doi.org/10.1038/nature22383)Jaro, M.A., 1989. Advances in record-linkage methodology as applied to matching the 1985 census of Tampa,
Florida. Journal of the American Statistical Association, 84(406), pp.414-420.Levenshtein, V.I., 1966, February. Binary codes capable of correcting deletions, insertions, and reversals. In
Soviet physics doklady (Vol. 10, No. 8, pp. 707-710).python-Levenshtein (https://github.com/ztane/python-Levenshtein)Thakkar, N. and Bailey-Kellogg, C., 2019. Balancing sensitivity and specificity in distinguishing TCR groups by CDR
sequence similarity. BMC bioinformatics, 20(1), pp.1-14. (https://doi.org/10.1186/s12859-019-2864-8)Van der Loo, M.P., 2014. The stringdist package for approximate string matching. R J., 6(1), p.111.Winkler, W.E., 1990. String comparator metrics and enhanced decision rules in the Fellegi-Sunter model of record
linkage.