0

Not sure how to explain, I mean statemtents like:

for i in l:
if a==b:
def x():
lambda x:
class spam:
while True:

basically those control statements that end with :

can I create novel ones? (like in snakemake that has a long list of new control statements)

I tried reading documentation, but could not find anything useful.

I just want to make some tools to help develop rules for snakemake. I am currently using this:

class SM(object):
    def __init__(self,**xargs):
        self.items = xargs
    def __getattribute__(self,attr):
        return object.__getattribute__(self, "items")[attr]

input = SM(genome="Genome/genome.fa",
            table="rmats/binding_strength.maxent.CLIP.csv")
table = pd.read_csv(input.table,index_col=0)

In that example I can use the class SM to emulate all the input, output, wildcard... then I can just move the code into its rule in the Snakefile without needing to manually edit all the inputs/wildcards/outputs...

However, I will still need to write the "input:".

Is there a way I could make:

input: 
    table="table.csv"

do

input=SM(table:"table.csv")
#or input=SM(**xargs)
General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • What are you trying to achieve with this functionality? FWIW you cannot do that in Python – Abirbhav G. Dec 19 '22 at 10:40
  • @AbirbhavG. I just want to make an elegantish environment to test snakemake code snippets in an IDE so i can just copy paste code back and forth. – user3392394 Dec 19 '22 at 19:40

1 Answers1

-1

Sorry, but no can do...You would have to modify the language implementation itself (the interpreter actually). When you are programming you are bound by the syntax of the language, you cannot modify the syntax "on the fly". It's not the same as e.g. defining functions, classes and whatnot.

Take a look at these:

Here's the most comprehensive answer to this kind of questions imho: https://stackoverflow.com/a/9108164/15923186

Gameplay
  • 1,142
  • 1
  • 4
  • 16
  • Thanks for your answer, I wasn't sure if it was possible, without modifying the python interpreter. but those are some useful links. – user3392394 Dec 19 '22 at 19:38