Giter Site home page Giter Site logo

Comments (6)

iromeo avatar iromeo commented on May 27, 2024

Features like #43 could be easily implemented if we will detect substitution at parser level (like f-string support in PyCharm)

from snakecharm.

iromeo avatar iromeo commented on May 27, 2024

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.

iromeo avatar iromeo commented on May 27, 2024

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.

nikita-nazarov avatar nikita-nazarov commented on May 27, 2024

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.

iromeo avatar iromeo commented on May 27, 2024

Related PyCharm bug - https://youtrack.jetbrains.com/issue/PY-37374

from snakecharm.

iromeo avatar iromeo commented on May 27, 2024

Done

image

image

from snakecharm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.