Profile Searches#
- pyinfernal.infernal.cmsearch(queries, sequences, cpus=0, callback=None, backend='threading', parallel=None, **options)#
Search CM profiles against a sequence database.
In Infernal many-to-many comparisons, a search is the operation of querying with profile CMs a database of sequences.
The
cmsearchfunction offers two ways of managing the database that will be selected based on the type of thesequencesargument. Ifsequencesis aSequenceFileobject,cmsearchwill reopen the file in each thread, and load targets iteratively to scan with the query. Otherwise, it will pre-fetch the target sequences into aDigitalSequenceBlockcollection, and share them across threads without copy. The pre-fetching gives much higher performance at the cost of extra startup time and much higher memory consumption. You may want to check how much memory is available (for instance withpsutil.virtual_memory) before trying to load a whole sequence database, but it is really recommended to do so whenever possible.- Parameters:
queries (iterable of
CM) – The query CMs or profiles to search for in the database. Note that passing a single object is supported, but the function will always return an iterator.sequences (iterable of
DigitalSequence) – A database of sequences to query. If you plan on using the same sequences several times, consider storing them into aDigitalSequenceBlockdirectly. If aSequenceFileis given, profiles will be loaded iteratively from disk rather than prefetched.cpus (
int) – The number of threads to run in parallel. Pass1to run everything in the main thread,0to automatically select a suitable number (usingpsutil.cpu_count), or any positive number otherwise.callback (callable) – A callback that is called everytime a query is processed with two arguments: the query, and the total number of queries. This can be used to display progress in UI.
backend (
str) – The parallel backend to use for workers to be executed. Supportsthreadingto use thread-based parallelism, ormultiprocessingto use process-based parallelism.parallel (
str) – The parallel strategy to use. Supportsqueriesto run queries in parallel, ortargetsto parallelize on targets while running one query at a time. IfNonegiven, usequeriesby default unless we can detect that there is a single or a small number of queries. Note that parallelization ontargetsdoes not work withSequenceFiletargets.
- Yields:
TopHits– An object reporting top hits for each query, in the same order the queries were passed in the input. The number of included hits depends on theincEthreshold passed as an option to the internalPipeline.- Raises:
AlphabetMismatch – When any of the query CMs and the sequences do not share the same alphabet.
RuntimeError – When attempting to use
targetsparallel strategy with targets from aSequenceFile.
Note
Any additional arguments passed to the
cmsearchfunction will be passed transparently to thePipelineto be created. For instance, to run acmsearchusing a bitscore cutoffs of 5 instead of the default E-value cutoff, use:>>> hits = next(cmsearch(trna, sequences, T=5)) >>> hits[0].score 12.06...
mypyshould be able to detection which keywords can be passed tocmsearchusing aTypedDictannotation.