Best Python code snippet using locust
create_assets.smk
Source:create_assets.smk
1###-----------------------------------------------------------------------------------------------------------------###2# Notes on where variables are defined, if not defined in obs_exp.smk3#4# output_directory - workflow/Snakefile5# config - workflow/Snakefile6# get_biscuit_refererence - workflow/rules/biscuit.smk7#8###-----------------------------------------------------------------------------------------------------------------###9# Verify the provided genome is one of the available genomes10def check_genome(wildcards):11 if config['create_assets']['run'] and config['create_assets']['genome'] not in ['hg38', 'hg19', 'mm10', 'mm9']:12 print('hg38, hg19, mm10, and mm9 are the only available genomes for creating asset files')13 exit(1)14 elif config['create_assets']['run'] and config['create_assets']['genome'] in ['hg38', 'hg19', 'mm10', 'mm9']:15 return config['create_assets']['genome']16# Determine which GENCODE annotation file to download17def get_annotation_file(wildcards):18 base = 'http://ftp.ebi.ac.uk/pub/databases/gencode'19 gen = check_genome(wildcards)20 if gen == 'hg38':21 return f'{base}/Gencode_human/release_38/gencode.v38.annotation.gtf.gz'22 elif gen == 'hg19':23 return f'{base}/Gencode_human/release_19/gencode.v19.annotation.gtf.gz'24 elif gen == 'mm9':25 return f'{base}/Gencode_mouse/release_M1/gencode.vM1.annotation.gtf.gz'26 else:27 return f'{base}/Gencode_mouse/release_M27/gencode.vM27.annotation.gtf.gz'28rule general_assets:29 input:30 ref = get_biscuit_reference,31 output:32 cpg = f'assets/{config["create_assets"]["genome"]}/cpg.bed.gz',33 bot = f'assets/{config["create_assets"]["genome"]}/windows100bp.gc_content.bot10p.bed.gz',34 top = f'assets/{config["create_assets"]["genome"]}/windows100bp.gc_content.top10p.bed.gz',35 cgi = f'assets/{config["create_assets"]["genome"]}/cpg_islands.bed.gz',36 opn = f'assets/{config["create_assets"]["genome"]}/cpg_open_seas.bed.gz',37 shl = f'assets/{config["create_assets"]["genome"]}/cpg_shelves.bed.gz',38 sho = f'assets/{config["create_assets"]["genome"]}/cpg_shores.bed.gz',39 exn = f'assets/{config["create_assets"]["genome"]}/exon.bed.gz',40 gen = f'assets/{config["create_assets"]["genome"]}/genic.bed.gz',41 inr = f'assets/{config["create_assets"]["genome"]}/intergenic.bed.gz',42 msk = f'assets/{config["create_assets"]["genome"]}/rmsk.bed.gz',43 params:44 annt = get_annotation_file,45 gen = check_genome,46 dir = f'assets/{config["create_assets"]["genome"]}',47 tmp_sho = f'assets/{config["create_assets"]["genome"]}/shores.tmp.bed',48 tmp_shl = f'assets/{config["create_assets"]["genome"]}/shelves.tmp.bed',49 tmp_gen = f'assets/{config["create_assets"]["genome"]}/gene.tmp.bed',50 tmp_exn = f'assets/{config["create_assets"]["genome"]}/exon.tmp.bed',51 log:52 f'{output_directory}/logs/general_assets.log',53 benchmark:54 f'{output_directory}/benchmarks/general_assets.txt',55 threads: 156 resources:57 mem_gb = config['hpcParameters']['intermediateMemoryGb'],58 walltime = config['walltime']['medium']59 conda:60 '../envs/biscuit.yaml'61 envmodules:62 config['envmodules']['bedtools'],63 config['envmodules']['biscuit'],64 shell:65 """66 set +o pipefail;67 echo "Create output directory" 1> {log}68 mkdir -p {params.dir}69 70 echo "Set reference location" 1> {log}71 # Reference location72 REFLOC={input.ref}.fai73 echo "Retrieve CpG island file" 1> {log}74 # CpG Islands from UCSC on only the canonical chromosomes75 wget -qO- http://hgdownload.cse.ucsc.edu/goldenpath/{params.gen}/database/cpgIslandExt.txt.gz | \76 gunzip -c | \77 awk 'BEGIN{{ OFS="\\t"; }}{{ print $2, $3, $4; }}' | \78 awk '{{ if ($1 ~ /^chr[1234567890XYM]{{1,2}}$/) {{ print }} }}' | \79 bedtools sort -i - | \80 gzip -c > {output.cgi}81 echo "CpG island file retrieved" 1> {log}82 # Create middles for finding locations83 bedtools slop \84 -i {output.cgi} \85 -g ${{REFLOC}} \86 -b 2000 | \87 bedtools merge -i - \88 > {params.tmp_sho}89 bedtools slop \90 -i {output.cgi} \91 -g ${{REFLOC}} \92 -b 4000 | \93 bedtools merge -i - \94 > {params.tmp_shl}95 # CpG Open Seas (intervening locations)96 sort -k1,1 -k2,2n ${{REFLOC}} | \97 bedtools complement -L -i {params.tmp_shl} -g - | \98 gzip -c > {output.opn}99 # CpG Shelves (shores +/- 2kb)100 bedtools subtract \101 -a {params.tmp_shl} \102 -b {params.tmp_sho} | \103 gzip -c > {output.shl}104 # CpG Shores (island +/- 2kb)105 bedtools subtract \106 -a {params.tmp_sho} \107 -b {output.cgi} | \108 gzip -c > {output.sho}109 # Clean up CpG temporary files110 rm -f {params.tmp_shl} {params.tmp_sho}111 echo "CpG seascape created and cleaned up" 1> {log}112 # BISCUIT assets (includes CpG and top/bottom 10% GC-content files)113 build_biscuit_QC_assets.pl --outdir {params.dir} --ref {input.ref} 1> {log}114 # Repeat-masked file115 if [[ {params.gen} != "mm9" ]]; then116 wget -qO- http://hgdownload.cse.ucsc.edu/goldenpath/{params.gen}/database/rmsk.txt.gz | \117 gunzip -c | \118 awk 'BEGIN{{ OFS="\\t"; }}{{ print $6, $7, $8; }}' | \119 awk '{{ if ($1 ~ /^chr[1234567890XYM]{{1,2}}$/) {{ print }} }}' | \120 bedtools sort -i - | \121 bedtools merge -i - | \122 gzip -c > {output.msk}123 else124 wget -q -nd -r -nH -np --accept-regex 'chr[1234567890XYM]*_rmsk.txt.gz$' \125 --regex-type=posix http://hgdownload.cse.ucsc.edu/goldenpath/mm9/database/126 cat chr*_rmsk.txt.gz | \127 gunzip -c | \128 awk 'BEGIN{{ OFS="\\t"; }}{{ print $6, $7, $8; }}' | \129 bedtools sort -i - | \130 bedtools merge -i - | \131 gzip -c > {output.msk}132 if [[ -f index.html ]]; then rm index.html; fi133 if [[ -f robots.txt ]]; then rm robots.txt; fi134 rm chr*_rmsk.txt.gz135 fi136 # Genic, intergenic, and exon files137 wget -qO- {params.annt} | \138 gunzip -c | \139 awk 'BEGIN{{ OFS="\\t"; }}{{ if ($3 == "gene") {{ print $1, $4, $5 > "{params.tmp_gen}"; }} else if ($3 == "exon") {{ print $1, $4, $5 > "{params.tmp_exn}"; }} }}'140 bedtools sort -i {params.tmp_gen} | \141 bedtools merge -i - | \142 gzip -c > {output.gen}143 bedtools sort -i {params.tmp_exn} | \144 bedtools merge -i - | \145 gzip -c > {output.exn}146 sort -k1,1 -k2,2n {input.ref}.fai | \147 bedtools complement -L -i {output.gen} -g - | \148 gzip -c > {output.inr}149 # Clean up150 rm -f {params.tmp_gen} {params.tmp_exn}151 """ 152rule bismap_assets:153 input:154 cpg = f'assets/{config["create_assets"]["genome"]}/cpg.bed.gz',155 cgi = f'assets/{config["create_assets"]["genome"]}/cpg_islands.bed.gz',156 exn = f'assets/{config["create_assets"]["genome"]}/exon.bed.gz',157 gen = f'assets/{config["create_assets"]["genome"]}/genic.bed.gz',158 inr = f'assets/{config["create_assets"]["genome"]}/intergenic.bed.gz',159 msk = f'assets/{config["create_assets"]["genome"]}/rmsk.bed.gz',160 ref = get_biscuit_reference,161 output:162 bis = f'assets/{config["create_assets"]["genome"]}/k100.bismap.bedgraph.gz',163 sor = f'assets/{config["create_assets"]["genome"]}/k100.bismap.sorted.bed.gz',164 wgt = f'assets/{config["create_assets"]["genome"]}/k100.bismap.10kb_avg.bed.gz',165 cpg = f'assets/{config["create_assets"]["genome"]}/cpg_bismap.bed.gz',166 cgi = f'assets/{config["create_assets"]["genome"]}/cgi_bismap.bed.gz',167 exn = f'assets/{config["create_assets"]["genome"]}/exon_bismap.bed.gz',168 gen = f'assets/{config["create_assets"]["genome"]}/genic_bismap.bed.gz',169 inr = f'assets/{config["create_assets"]["genome"]}/intergenic_bismap.bed.gz',170 msk = f'assets/{config["create_assets"]["genome"]}/rmsk_bismap.bed.gz',171 byn = f'assets/{config["create_assets"]["genome"]}/genome_window_10kb.bed.gz',172 params:173 gen = check_genome,174 dir = f'assets/{config["create_assets"]["genome"]}',175 log:176 f'{output_directory}/logs/bismap_assets.log',177 benchmark:178 f'{output_directory}/benchmarks/bismap_assets.txt',179 threads: 1180 resources:181 mem_gb = config['hpcParameters']['intermediateMemoryGb'],182 walltime = config['walltime']['medium']183 conda:184 '../envs/biscuit.yaml'185 envmodules:186 config['envmodules']['bedtools'],187 shell:188 """189 set +o pipefail;190 #cd {params.dir}191 wget -P {params.dir} --no-check-certificate -q https://bismap.hoffmanlab.org/raw/{params.gen}/k100.bismap.bedgraph.gz192 # Create average mappability scores in 10kb windows193 zcat {output.bis} | sort -k1,1 -k2,2n | gzip > {output.sor}194 bedtools makewindows -w 10000 -g {input.ref}.fai | gzip 1> {output.byn} 2> {log}195 bedtools map -a {output.byn} -b {output.sor} -c 4 -o mean | gzip 1> {output.wgt} 2> {log}196 bedtools intersect -a {output.bis} -b {input.cpg} | gzip -c 1> {output.cpg} 2> {log}197 bedtools intersect -a {output.bis} -b {input.cgi} | gzip -c 1> {output.cgi} 2> {log}198 bedtools intersect -a {output.bis} -b {input.exn} | gzip -c 1> {output.exn} 2> {log}199 bedtools intersect -a {output.bis} -b {input.gen} | gzip -c 1> {output.gen} 2> {log}200 bedtools intersect -a {output.bis} -b {input.inr} | gzip -c 1> {output.inr} 2> {log}201 bedtools intersect -a {output.bis} -b {input.msk} | gzip -c 1> {output.msk} 2> {log}...
generate_static_assets.py
Source:generate_static_assets.py
1from pathlib import Path2from types import ModuleType3import erdantic as erd4import erdantic.erd5import erdantic.examples.dataclasses6import erdantic.examples.pydantic7import erdantic.version8ASSETS_DIR = Path(__file__).resolve().parents[1] / "assets"9# monkeypatch __version__10erd.__version__ = erdantic.erd.__version__ = erdantic.version.__version__ = "TEST"11def create_assets(examples: ModuleType):12 stem = examples.__name__.rsplit(".", 1)[1]13 (ASSETS_DIR / stem).mkdir(exist_ok=True)14 diagram = erd.create(examples.Party)15 diagram.draw(out=ASSETS_DIR / stem / "diagram.png")16 diagram.draw(out=ASSETS_DIR / stem / "diagram.svg")17 with (ASSETS_DIR / stem / "diagram.dot").open("w") as fp:18 fp.write(diagram.to_dot())19if __name__ == "__main__":20 for module in [erdantic.examples.dataclasses, erdantic.examples.pydantic]:...
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!!