Comments (6)
Features like #43 could be easily implemented if we will detect substitution at parser level (like f-string support in PyCharm)
from snakecharm.
Format strings use Python Mini Language Format, see https://docs.python.org/3/library/string.html
Let's try to implement this using language injection approach.
- here format language is much more simple than syntax of f-strings
- mini language format isn't a valid python, e.g. in
{foo.some_dict[key]}
quotes around key are omitted - we'd like to support this not for all strings in *.smk file, but only for some cases, e.g. args of sections, "shell" call, etc.
- we don't need to many features there, e.g. highlighting, completion, resolve, inline/extract param are enough
- completion/resolve isn't very complicated there, not required to make python completion work there
See PyDocstringLanguageInjector, PyTypingAnnotationInjector, PyDocstringLanguageDialect, PyDocReference
from snakecharm.
Some examples:
Wildcards regexp constraints:
rule index_bams:
input: '{anywhere}/{sample}.bam'
output: '{anywhere}/{sample, [^/]*}.bam.bai'
wrapper: '0.31.1/bio/samtools/index'
Escaped {
and }
:
rule bam_qc_pbc_nrf:
input: rules.bam_to_pileup.output
output: 'qc/pbc_nrf/{sample}.pbc_nrf.tsv'
params:
tmp_dir='tmp'
shell: '''
mkdir -p {params.tmp_dir} &&
(T=$'\\t'
>&2 echo "TotalReadPairs${{T}}DistinctReadPairs${{T}}OneReadPair${{T}}TwoReadPairs${{T}}\
NRF=Distinct/Total${{T}}PBC1=OnePair/Distinct${{T}}PBC2=OnePair/TwoPair"
cat {input} | \
sort -k1,1 -k3,3n -k2,2n -k6,6 -T {params.tmp_dir} | \
awk -v OFS='\\t' '{{print $1,$2,$3,$6}}' | uniq -c | \
awk 'BEGIN{{mt=0;m0=0;m1=0;m2=0}}
($1==1){{m1=m1+1}} ($1==2){{m2=m2+1}} {{m0=m0+1}} {{mt=mt+$1}}
END{{
if (mt!=0){{m0_t=m0/mt}} else {{m0_t=-1.0}};
if (m0!=0){{m1_0=m1/m0}} else {{m1_0=-1.0}};
if (m2!=0){{m1_2=m1/m2}} else {{m1_2=-1.0}};
printf "%d\\t%d\\t%d\\t%d\\t%f\\t%f\\t%f\\n",mt,m0,m1,m2,m0_t,m1_0,m1_2;
}}') > {output}
'''
from snakecharm.
Identifiers of string language in some rule sections that are not executable sections turn into wildcards in snakemake (See snakemake/io.py:565). These sections are:
- conda
- resources
- group
- benchmark
- log
- output
- params
- input
See snakemake/rules.py:596-758
e.g. sample will be considered as wildcard in
rule NAME:
input: "{sample}.txt"
Notice, that you can't use the same wildcard with different regular expression constraints. The code will fail at runtime with Constraint regex must be defined only in the first occurence of the wildcard in a string. error
Furthermore, there are sections, that generate wildcards, and sections, where wildcards are expanded. The list of first ones is:
- output
- log
- benchmark
(see usages of register_wildcards in snakemake/rules.py:265)
Wildcards are created once by one of these sections in priority in which they are listed above.
E. g.:
rule NAME:
log: "{sample}.txt"
output: "{sample}.txt"
The wildcard sample will be created by output
section
If wildcards sets are not equal in output
, log
, benchmark
, the code will fail at runtime with error:
Not all output, log and benchmark files of rule contain the same wildcards...
(see snakemake/rule.py:270)
Another error will occur for example in this situation:
rule NAME:
input: "{sample}.txt"
output: "{output_file}"
In this example code will fail with error:
Wildcards in input files cannot be determined from output files: 'sample'
This happens because wildcard sample was not created.
from snakecharm.
Related PyCharm bug - https://youtrack.jetbrains.com/issue/PY-37374
from snakecharm.
Done
from snakecharm.
Related Issues (20)
- Current version of SnakeCharm is incompatible with PyCharm 2023.1 HOT 2
- Exception: "Access is allowed from write thread only" creating project in dumb mode HOT 2
- PyCharm 2023.3 Support
- Show notice on deprecated features HOT 1
- Unresolved reference warning when iterating over 'input' key-value pairs using '.items()'
- [7.11] Resources scopes support
- Unresolved reference 'snakemake' HOT 3
- Wildcard not defined in output of Target Rule HOT 3
- PyCharm 2024.1 support HOT 5
- Improve parser error message when rule/module is declared with name but lacks ':'
- Completion for wrapper names rarely works
- Section names cannot be resolved for rules after inheritance using use
- After using import, fuctions from other smk files are not detected HOT 1
- Importing rules using github function does not work
- Gitfile command is not recognized by snakecharm
- Snakecharm does not recognize localrule directive
- Cache and bechmark are not reported as an error
- Multiple functions are not recognized by snakecharm
- Snakecharm marks error on comment in last line HOT 1
- Improve target rules support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snakecharm.