I'm trying to figure out how to write in HAML the use of link_to_if helper with a do block.
I tried this one but it generate an error :
= link_to_if(test, my_text, my_path) do
- some_other_text
Error : syntax error, unexpected ';', expecting ')' end;_hamlout.buffer << _hamlout.f...
I know I could reach the same result with a if else statement and link_to helper, but I'd like to understand how to do it with link_to_if.
This should work (tested):
= link_to_if(test, my_text, my_path) do
= some_other_text # this is a variable holding text
In HAML = means: print the result of the evaluated code, - means: evaluate the following code.
If this does not fix your problem you probably have an error somewhere else in your code when one of the variables used get evaluated.
Related
With snakemake, I would like to have a different input (including a wildcard) within a rule according to a boolean
I've tried :
rule quantify:
input:
if trimmed_fastq:
forward = path_trimmed_fastq + "/{sample}_R1_val_1.fq.gz",
rev = path_trimmed_fastq + "/{sample}_R2_val_2.fq.gz"
else:
forward = fastq_path + "/{sample}_R1.fastq.gz",
rev = fastq_path + "/{sample}_R2.fastq.gz"
But it gives me an "invalid syntax" error, I think it doesn't like if else statement in input, anyone has an idea how to fix this?
I know I could have two different "quantify" and "quantify_trimmed" rules with if else statement around them, but I'm wondering if there is a more elegant solution.
Thank you for your help
Indeed, you cannot have an if..else statement inside an input. Instead, a function can be used to achieve what you want:
def getInputFilesForQuantify(wildcards):
files = dict()
if(trimmed_fastq):
files["forward"] = os.path.join(path_trimmed_fastq,wildcards.sample,"_R1_val_1.fq.gz")
files["rev"] = os.path.join(path_trimmed_fastq,wildcards.sample,"_R2_val_2.fq.gz")
else:
files["forward"] = os.path.join(fastq_path,wildcards.sample,"_R1.fastq.gz")
files["rev"] = os.path.join(fastq_path,wildcards.sample,"_R2.fastq.gz")
return files
rule quantify:
input: unpack(getInputFilesForQuantify)
output: ....
Note:
wildcards are passed to the parameters of the function.
unpack is here used because you're returning a dictionnary if naming of your inputs are needed. Otherwise, a simple list of files is returned.
Long story short, I have a sql query pulling data from a database into a spreadsheet. I want to be able to change the Plant filter inside the query via Power Query, I have tried using a custom function and adding that into the query where the variable is set (see below)
Sql.Database("server", "database", [Query="DECLARE #FilterOnPlant AS varchar(3)#(lf)SET #FilterOnPlant = '" + filterOnPlant + "'#(lf)#(lf)SELECT
In doing this I keep getting the following error:
Expression.Error: We cannot apply operator + to types Text and Table.
Details:
Operator=+
Left=DECLARE #FilterOnPlant AS varchar(3)
SET #FilterOnPlant = '
Right=[Table]
I figure it has something to do with the '+' operator used but can't find an alternative.
I have tried using:
'&'
'+'
'and'
but they all yield the same error (with the exception of 'and' that error states that it's not being used in a logical statement which makes sense)
For further info:
The custom function to get the value I want is:
filterOnPlant = Excel.CurrentWorkbook(){[Name="Active_Plant"]}[Content]
The intention is to get the Value from a cell Named "Active_Plant"
EDIT:
after further testing I have found the issue lies with variable filterOnPlant, when I exchange that for a string value then the query works as expected. If anyone knows how I can get CELL().Value of a named range in power query would be super helpful
Solved!
In my filterOnPlant function I was missing {0}[Column1]
Original: filterOnPlant = Excel.CurrentWorkbook(){[Name="Active_Plant"]}[Content]
New (Working): filterOnPlant = Excel.CurrentWorkbook(){[Name="Active_Plant"]}[Content]{0}[Column1]
i'm facing issue in xpath-I need do a check two attribute values, if the condition satisfies need to do hard code my own value. Below is my xml.
I need to check the condition like inside subroot- if ItemType=Table1 and ItemCondition=Chair1 then i have to give a hard coded value 'Proceed'( this hard coded value i will map to target side of datamapper).
<Root>
<SubRoot>
<ItemType>Table1</ItemType>
<ItemCondition>Chair1</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
<SubRoot>
<ItemType>Table2</ItemType>
<ItemCondition>chair2</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
....Will have multiple subroot
</Root>
I have tried to define rules as below, but it is throwing error
Type: String
Context:/Root
Xpath: substring("Proceed", 1 div boolean(/SubRoot[ItemType="Table1" and ItemCondition="Chair1"]))
But it is throwing error like
net.sf.saxon.trans.XPathException: Arithmetic operator is not defined for arguments of types (xs:integer, xs:boolean)
Is there any other shortcut way to perform this.Could you please help me, i have given lot more effort. Not able to resolve it. Thanks in advance.
I am not sure where you are applying this but the XPath expression you are looking for is:
fn:contains(/Root/SubRoot[2]/ItemCondition, "chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")
So here is an example returning "Proceed" or "Stop" as appropriate:
if (fn:contains(/Root/SubRoot[1]/ItemCondition, "Chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")) then 'Proceed' else 'Stop'
To implement the above condition , i was initially tired to do in xpath, gave me lot of error. I have implemented by simple if else condition in script part of data mapper
if ( (input.ItemType == 'Table') and (input.ItemCondition == 'chair')) {
output.Item = 'Proceed'}
else {
output.Item = 'Stop '};
Make sure about your precedence. Example, Here in the xml structure( or converted POJO) ItemType has to be checked first then followed with ItemCondition.
&& not seems to be working for me, change to 'and' operator
If you were first time trying to implement the logic. It may help you.
I have a pig macro
define chop_massive (my, maxev) returns grouped, massive {
gr = foreach (group $my by id) generate group as id, $my;
split gr into
massive if COUNT($my) > $maxev,
grouped otherwise;
$grouped = grouped;
$massive = foreach massive generate id, COUNT($my) as $my;
};
my problem is with passing maxev parameter.
when I use a constant literal (e.g., 100L) all is fine.
however, I want to use $MAX_EVENTS specified using -param on the command line.
I tried
A, massive = chop_massive(A, $MAX_EVENTS);
and got
mismatched input '100L' expecting set null
I tried
A, massive = chop_massive(A, ($MAX_EVENTS));
and got
mismatched input '(' expecting set null
I tried
A, massive = chop_massive(A, '$MAX_EVENTS');
and got
Macro doesn't support user defined schema that contains name that conflicts with alias name: A
I tried
massive if COUNT($my) > $MAX_EVENTS,
inside the macro and got
Macro inline failed for macro 'chop_massive'. Reason: Undefined parameter : MAX_EVENTS
(this error is at least clear and reasonable).
So what should I do?
While I don't see it documented anywhere, it wouldn't surprise me if expressions are not supported as macro arguments. Why not just pass $EVENTS_PER_DAY and $DAYS as parameters to the macro (three parameters instead of two)?
When I call a find with an id, it becomes a targeted find, and will throw an error RecordNotFound.
Foo::Bar.find(123) # RecordNotFound if no Bar with id 123 exists.
But when I call that with conditions, I get nil if not found:
Foo::Bar.find(:first, :conditions => [ "lower(name) = ?", name.downcase ])
I want such a conditional search to raise an error too. I know I can do:
Foo::Bar.find_by_name!("CocktailBar") #=> raises Recordnotfount if not not found.
But that has only really simple conditions. Mine need a little more complexity; actually something like:
Foo.Bar.select{ |pm| pm.name.downcase =~ /cocktail/}.first
And, if nothing is found, I want it to raise the RecordNotFound error. Is that possible at all? Or should I simply add some code to check against nil? and if nil? raise the error myself? And if so, how do I do that in Rails 3?
In the last snippet of code you are actually fetching all records from DB and then doing select on a Ruby array. It has nothing to do with ActiveRecord, so you can do whatever you like to raise exception manually, either use the code suggested by Douglas, or if, or unless etc. But it seems that you don't quite understand what your code does. Your select {...} is not translated into SQL SELECT ... WHERE(...).
If you need an exception raised automatically by ActiveRecord query, use this:
Foo::Bar.where([ "lower(name) = ?", name.downcase ]).first!
The equivalent bang methods exist for find_by methods as well, for example Foo::Bar.find_by_name!(name)
For anyone coming across this question, now you have the method find_by!
that does exactly what the OP asked for the find case.
example:
Foo::Bar.find_by!(name: "CocktailBar")
https://apidock.com/rails/v4.0.2/ActiveRecord/FinderMethods/find_by%21
Your final paragraph is what you need to do. Either check against nil, or raise the exceptions yourself. To raise the exception yourself, do the following:
Foo::Bar.find(:first, :conditions => [ "lower(name) = ?", name.downcase ]) || raise(ActiveRecord::RecordNotFound)