Could anyone explain me this makefile? - makefile

this is the makefile :
TOP=../..
DIRNAME=base_class/string
H = regexp.h regmagic.h string_version.h
CSRCS = regerror.c regsub.c EST_strcasecmp.c
TSRCS =
CPPSRCS = EST_String.cc EST_Regex.cc EST_Chunk.cc regexp.cc
LOCAL_DEFAULT_LIBRARY = eststring
SRCS = $(CPPSRCS) $(CSRCS)
OBJS = $(CPPSRCS:.cc=.o) $(CSRCS:.c=.o)
FILES = $(SRCS) $(TSRCS) $(H) Makefile
LOCAL_INCLUDES=-I.
ALL = .buildlibs
include $(TOP)/config/common_make_rules
now i know these part is variable
TOP=../..
DIRNAME=base_class/string
H = regexp.h regmagic.h string_version.h
CSRCS = regerror.c regsub.c EST_strcasecmp.c
TSRCS =
CPPSRCS = EST_String.cc EST_Regex.cc EST_Chunk.cc regexp.cc
LOCAL_DEFAULT_LIBRARY = eststring
SRCS = $(CPPSRCS) $(CSRCS)
what i do not know is :
OBJS = $(CPPSRCS:.cc=.o) $(CSRCS:.c=.o)
pls tell me the meaning of above statement , it is best if you figure out what above statement omit. thanks.

You can look this up in the GNU make manual. The above is equivalent to writing $(CPPSRCS:%.cc=%.o) (and ditto for CSRCS). In both of these, it goes through each word in the variable and if it matches the left-hand side of the equality, it's replaced with the right-hand side. So if a word matches the pattern %.cc (where % to make matches any sequence of characters), then it's replaced with %.o (where % is the same as in the original). The form you see is a special case where you can omit the % if it's the first thing in both sides.
So, given CPPSRCS = EST_String.cc EST_Regex.cc EST_Chunk.cc regexp.cc, then $(CPPSRCS:.cc=.o) expands to EST_String.o EST_Regex.o EST_Chunk.o regexp.o.

Related

WildcardError in Snakefile

I've been trying to run the following bioinformatic script:
configfile: "config.yaml"
WORK_TRIM = config["WORK_TRIM"]
WORK_KALL = config["WORK_KALL"]
rule all:
input:
expand(WORK_KALL + "quant_result_{condition}", condition=config["conditions"])
rule kallisto_quant:
input:
fq1 = WORK_TRIM + "{sample}_1_trim.fastq.gz",
fq2 = WORK_TRIM + "{sample}_2_trim.fastq.gz",
idx = WORK_KALL + "Homo_sapiens.GRCh38.cdna.all.fa.index"
output:
WORK_KALL + "quant_result_{condition}"
shell:
"kallisto quant -i {input.idx} -o {output} {input.fq1} {input.fq2}"
However, I keep obtaing an error like this:
WildcardError in line 13 of /home/user/directory/Snakefile:
Wildcards in input files cannot be determined from output files:
'sample'
Just to explain briefly, kallisto quant will produce 3 outputs: abundance.h5, abundance.tsv and run_injo.json. Each of those files need to be sent to their own newly created condition directory. I not getting exactly what is going on wrong. I'll appreciated any help on this.
If you think about it, you are not giving snakemake enough information.
Say "condition" is either "control" or "treated" with samples "C" and "T", respectively. You need to tell snakemake about the association control: C, treated: T. You could do this using functions-as-input files or lambda functions. For example:
cond2samp = {'control': 'C', 'treated': 'T'}
rule all:
input:
expand("quant_result_{condition}", condition=cond2samp.keys())
rule kallisto_quant:
input:
fq1 = lambda wc: "%s_1_trim.fastq.gz" % cond2samp[wc.condition],
fq2 = lambda wc: "%s_2_trim.fastq.gz" % cond2samp[wc.condition],
idx = "Homo_sapiens.GRCh38.cdna.all.fa.index"
output:
"quant_result_{condition}"
shell:
"kallisto quant -i {input.idx} -o {output} {input.fq1} {input.fq2}"

How Ruby Interprets $(foo)

When I read RbConfig::CONFIG['libdir'] it gives me lib folder location. But in rbconfig.rb file CONFIG["libdir"] = "$(exec_prefix)/lib". How the value is interpreted here.
$(exec_prefix) refers to a key in RbConfig::CONFIG.
But that's not a Ruby feature. rbconfig.rb contains code to expand these values: every occurrence of $(key) is replaced with the corresponding value of RbConfig::CONFIG['key']
My rbconfig.rb contains these lines:
CONFIG["prefix"] = (TOPDIR || DESTDIR + "/Users/sos/.rubies/ruby-2.2.2")
CONFIG["exec_prefix"] = "$(prefix)"
CONFIG["libdir"] = "$(exec_prefix)/lib"
And their values are:
RbConfig::CONFIG["prefix"] #=> "/Users/sos/.rubies/ruby-2.2.2"
RbConfig::CONFIG["exec_prefix"] #=> "/Users/sos/.rubies/ruby-2.2.2"
RbConfig::CONFIG["libdir"] #=> "/Users/sos/.rubies/ruby-2.2.2/lib"

Generate macros from names defined by list

I have this definitions in Makefile:
PREFIX = PRE
POSTFIXES = POST1 POST2 POST3
Now I would like to generate programmatically the following macros:
NAME_1 = PRE_POST1
NAME_2 = PRE_POST2
NAME_3 = PRE_POST3
#...
How to do that?
This does what you want assuming NAME_# was literal.
$(foreach f,$(POSTFIXES),$(eval NAME_$(subst POST,,$f) = $(PREFIX)_$f))
Result:
NAME_1 = PRE_POST1
NAME_2 = PRE_POST2
NAME_3 = PRE_POST3
Explanation:
Remove POST from each postfix leaving just the number: $(subst POST,,$f)
Concatenate NAME_ with the number from the previous step: NAME_$(subst POST,,$f)
Concatenate $(PREFIX) and the current postfix to create the desired value string: $(PREFIX)_$f
Use $(eval) to assign the value to the computed variable name: $(eval NAME_$(subst POST,,$f) = $(PREFIX)_$f)
Do that all for each postfix in the list: $(foreach f,$(POSTFIXES),$(eval NAME_$(subst POST,,$f) = $(PREFIX)_$f))
Update for sequential NAME_# variables unrelated to POSTFIXES values:
make doesn't do math, at all really, so you need to play games to "count". (Thanks to the fantastic GMSL for showing me this trick.)
POSTFIXES = POST_X POST_Y POST_Z
N := x
$(foreach f,$(POSTFIXES),$(eval NAME_$(words $N) = $(PREFIX)_$f)$(eval N += x))
Result:
NAME_1 = PRE_POST_X
NAME_2 = PRE_POST_Y
NAME_3 = PRE_POST_Z

Extract keywords in a pystache template with gettext

I have html-template in my project that they are contain pystache codes such as
{{#_}}Word{{\_}}
I want to know , how I can extract this words by PoEditor parsers
You could use a regular expression to get them, and then remove what you don't want:
import re
regex=re.compile("\{\{\#\_\}\}.+\{\\\_\}\} ")
words=re.findall(regex, data)
#To remove it use re.split or simply now searching for [A-Z].
now I just using this code for making a file for using in PoEdit for scan and extracting the keywords:
def makeTempLang():
fs = getFiles('templates/')
words = []
regex =re.compile("\{\{\#\_\}\}(.+)\{\{/\_\}\}")
for f in fs:
data=open(f,'r').read()
fwords=re.findall(regex, data)
words.extend(fwords)
clean = (words[4:])
data='from core import config\n_=config.i18n\n'
for c in clean:
data = "%s_('%s')\n"%(data,c)
open('locale/temp2.py','w+').write(data)
pass
def getFiles(spath=''):
res =[]
arr = os.listdir(spath)
for d in arr:
dpath =os.path.join(spath,d)
if d.endswith('.htm'):
res.append(dpath)
if os.path.isdir(dpath):
sub=getFiles(dpath)
if len(sub) > 0 :
res.extend(sub)
return res

Makefile: $subst in dependency list

I have a Makefile which looks roughly like this:
FIGURES = A1_B1_C1.eps A2_B2_C2.eps A3_B3_C3.eps
NUMBERS = 1 2 3
all : $(FIGURES)
%.eps : $(foreach num, $(NUMBERS), $(subst B, $(num), %).out)
# my_program($+, $#);
%.out :
The point is that the file names of my figures contain certain information (A, B, C) and that each figure is created by my_program from several (in the example 3) files.
While the filename of each figure has the format Ax_Bx_Cx.eps, the names of the data files to create the figures from look like this:
Ax_1x_Cx.out
Ax_2x_Cx.out
Ax_3x_Cx.out
So for each figure, I need a dynamically created dependency list with several file names. In other words, my desired output for the example above would be:
# my_program(A1_11_C1.out A1_21_C1.out A1_31_C1.out, A1_B1_C1.eps);
# my_program(A2_12_C2.out A2_22_C2.out A2_32_C2.out, A2_B2_C2.eps);
# my_program(A3_13_C3.out A3_23_C3.out A3_33_C3.out, A3_B2_C3.eps);
Unfortunately, the subst command seems to be ignored, for the output looks like this:
# my_program(A1_B1_C1.out A1_B1_C1.out A1_B1_C1.out, A1_B1_C1.eps);
# my_program(A2_B2_C2.out A2_B2_C2.out A2_B2_C2.out, A2_B2_C2.eps);
# my_program(A3_B3_C3.out A3_B3_C3.out A3_B3_C3.out, A3_B3_C3.eps);
I had a look at this possible duplicate but figured that the answer cannot help me, since I am using % and not $#, which should be ok in the prerequisites.
Clearly I am getting something wrong here. Any help is greatly appreciated.
To do fancy prerequisite manipulations you need at least make-3.82 which supports Secondary Expansion feature:
FIGURES = A1_B1_C1.eps A2_B2_C2.eps A3_B3_C3.eps
NUMBERS = 1 2 3
all : $(FIGURES)
.SECONDEXPANSION:
$(FIGURES) : %.eps : $$(foreach num,$$(NUMBERS),$$(subst B,$$(num),$$*).out)
#echo "my_program($+, $#)"
%.out :
touch $#
Output:
$ make
touch A1_11_C1.out
touch A1_21_C1.out
touch A1_31_C1.out
my_program(A1_11_C1.out A1_21_C1.out A1_31_C1.out, A1_B1_C1.eps)
touch A2_12_C2.out
touch A2_22_C2.out
touch A2_32_C2.out
my_program(A2_12_C2.out A2_22_C2.out A2_32_C2.out, A2_B2_C2.eps)
touch A3_13_C3.out
touch A3_23_C3.out
touch A3_33_C3.out
my_program(A3_13_C3.out A3_23_C3.out A3_33_C3.out, A3_B3_C3.eps)

Resources