Best Python code snippet using tempest_python
chunkify.smk
Source: chunkify.smk
1# =================================================================================================2# Chunkify and Unchunkify3# =================================================================================================4# We want the sample names of the output files to fit the naming given by the user.5# In case our input for the samples is a table with two columns, the sample names (first column)6# can be different from the file names. However, the gappa chunkify command uses file names as7# sample names. For now, it is easiest to just symlink to the files to get a list of properly8# named files. In the future, we might add an option to rename samples in gappa chunkify,9# to make this step a bit less convoluted...10rule chunkify_sample_prep:11 input:12 fasta=get_sample_fasta13 output:14 "{outdir}/chunkify/samples/{sample}.fasta"15 shell:16 "ln -s {input.fasta} {output}"17# No need to execute this on the cluster computed nodes.18localrules: chunkify_sample_prep19# The rule to chunkify input fasta samples (query sequences) into chunks of equal size without20# duplicate sequences.21# We need a snakemake checkpoint here, because we cannot predict the number of chunks being produced.22checkpoint chunkify:23 input:24 # Request renamed samples, using the rule above, to get chunkify to use proper sample names.25 expand( "{outdir}/chunkify/samples/{sample}.fasta", outdir=outdir, sample=sample_names )26 output:27 abundances = expand( "{outdir}/chunkify/abundances/abundances_{sample}.json",28 outdir=outdir,29 sample=sample_names30 )31 params:32 chunks_dir = directory("{outdir}/chunkify/chunks"),33 abundances_dir = directory("{outdir}/chunkify/abundances"),34 hashfunction = config["params"]["chunkify"]["hash-function"],35 minabun = config["params"]["chunkify"]["min-abundance"],36 chunksize = config["params"]["chunkify"]["chunk-size"]37 # log:38 # "{outdir}/logs/chunkify.log"39 conda:40 "../envs/gappa.yaml"41 shell:42 "mkdir -p {params.chunks_dir} ;"43 " mkdir -p {params.abundances_dir} ;"44 " gappa prepare chunkify"45 " --fasta-path {input}"46 " --chunks-out-dir {params.chunks_dir}"47 " --abundances-out-dir {params.abundances_dir}"48 " --hash-function {params.hashfunction}"49 " --min-abundance {params.minabun}"50 " --chunk-size {params.chunksize}"51 " > {log} 2>&1"52# Following the documentation tutorial here:53# https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#data-dependent-conditional-execution54def aggregate_chunkify_chunks(wildcards):55 # Wildcards are ignored here, as the chunkify process is for the whole dataset,56 # so we do not have any wildcards to take into account;57 # but still have to use them in the argument list,58 # because otherwise snakemake complains.59 chunks = checkpoints.chunkify.get().output["chunks"]60 # abundances = checkpoints.chunkify.get().output[1]61 return expand(62 "chunkify/placed/{chunk}.jplace",63 chunk = glob_wildcards( os.path.join(chunks, "{chunk}.fasta")).chunk64 )65rule unchunkify:66 input:67 aggregate_chunkify_chunks,68 expand("{outdir}/chunkify/abundances/abundances_{sample}.json", outdir=outdir, sample=sample_names)69 output:70 protected( expand( "{outdir}/placed/{sample}.jplace", outdir=outdir, sample=sample_names ))71 params:72 hash_function = config["params"]["chunkify"]["hash-function"]73 # log:74 # "{outdir}/logs/unchunkify.log"75 conda:76 "../envs/gappa.yaml"77 shell:78 "gappa prepare unchunkify"79 " --abundances-path {outdir}/chunkify/abundances"80 " --chunk-file-expression {outdir}/chunkify/placed/chunk_@.jplace"81 " --hash-function {params.hash_function}"82 " --out-dir {outdir}/placed"...
chunkify.py
Source: chunkify.py
1def chunkify(lst, s):2 n=[lst[(i-1)*s:i*s] for i in range(1,len(lst)+1)]3 return [i for i in n if i]4print(chunkify([2, 3, 4, 5], 2), [[2, 3], [4, 5]])5print(chunkify([2, 3, 4, 5, 6], 2), [[2, 3], [4, 5], [6]])6print(chunkify([2, 3, 4, 5, 6, 7], 3), [[2, 3, 4], [5, 6, 7]])7print(chunkify([2, 3, 4, 5, 6, 7], 1), [[2], [3], [4], [5], [6], [7]] )8print(chunkify([2, 3, 4, 5, 6, 7], 7), [[2, 3, 4, 5, 6, 7]] )9print(chunkify([2, 3, 4, 5], 3), [[2, 3, 4], [5]])10print(chunkify([2, 3, 4, 5, 6, 7, 8], 3), [[2, 3, 4], [5, 6, 7], [8]])...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!