Nextflow dynamic includes and output - nextflow

I'm trying to use dynamic includes but I have problem to manage output files:
/*
* enables modules
*/
nextflow.enable.dsl = 2
include { requestData } from './modules/get_xapi_data'
include { uniqueActors } from './modules/unique_actors'
include { compileJson } from './modules/unique_actors'
if (params.user_algo) {
include { userAlgo } from params.user_algo
}
workflow {
dataChannel = Channel.from("xapi_data.json")
requestData(dataChannel)
uniqueActors(requestData.out.channel_data)
if (params.user_algo) {
user_algo = userAlgo(requestData.out.channel_data)
} else {
user_algo = null
}
output_json = [user_algo, uniqueActors.out]
// Filter output
Channel.fromList(output_json)
.filter{ it != null } <--- problem here
.map{ file(it) }
.set{jsonFiles}
compileJson(jsonFiles)
}
The problem is userAlgo can be dynamically loaded. And I don't know how I can take care of it. With this solution, I got a Unknown method invocation getFileSystem on ChannelOut type error.

The problem is that fromList expects a list of values, not a list of channels. If you use an empty Channel instead of checking for a null value, you could use:
if( params.user_algo ) {
user_algo = userAlgo(requestData.out.channel_data)
} else {
user_algo = Channel.empty()
}
user_algo
| concat( uniqueActors.out )
| map { file(it) }
| compileJson

Related

How to get object of Maximum value from LiveData?

I have liveData of market data. I want one market data object which have highest 'volume'. Here, volume is string value("277927.5793846733451135"), it could be null also.
I am using below code to achieve this. but, its not working.
viewModel.marketlist.observe(this as LifecycleOwner, { marketdata ->
val marketData = marketdata.getOrNull()
if(marketData !=null) {
val mData: MarketData? = marketData.marketData?.maxByOrNull { checkNotNull(it.volume) }
if (mData != null) {
binding.textViewPrice.text = mData.price
}
}
else {
//TODO
}
})
Any help would be appreciated!
You should be able to do something like this:
viewModel.marketList.observe(viewLifecycleOwner) { marketData ->
val maxData = marketData.getOrNull()?.marketData?.let { dataValues ->
dataValues.maxByOrNull { it.volume?.toDoubleOrNull() ?: -1.0 }
}
if (maxData != null) {
binding.textViewPrice.text = maxData.price
}
}
I cleaned up the observe call a bit, then I'm checking if marketData.getOrNull().marketData is null right away with my let { ... } block.
If you do have marketData (the inner one), it'll then safely call maxByOrNull { it.volume }.

How to merge collections based on object's particular key's value match in laravel6?

I have three collections.
SalaryCollection
BonusCollection
Deduction Collection
All of them have date which is common in some of them.
I want to merge these three into one collection in a way that object with same date in three becomes one as a result.
Something like this:
#items:array:2[
0=>{
+"date":"1-2020"
+"salaries":36500.0
+"deductions":1500.0
+"bonuses":7000.0
}
1=>{
+"date":"2-2020"
+"salaries":20000.0
+"deductions":1000.0
+"bonuses":5000.0
}
]
How can i do it?
I am not sure if this is the best way to do it but this is how i made it worked.
$salaryCollection = $salaryCollection->map(function ($item, $key) use ($bonusCollection) {
$single_bonus = $bonusCollection->where('date', $item->date);
if (!$single_bonus->isEmpty()) {
return collect($item)->put('bonuses', $single_bonus->first()->bonuses);
} else {
return collect($item)->put('bonuses', 0);
}
});
$salaryCollection = $salaryCollection->map(function ($item, $key) use ($deductionCollection) {
$single_deduction = $deductionCollection->where('date', $item['date']);
if (!$single_deduction->isEmpty()) {
return collect($item)->put('deductions', $single_deduction->first()->deductions);
} else {
return collect($item)->put('deductions', 0);
}
});

Map within a map in terraform variables

Does anyone know if it's possible with possibly code snipits representing whether I can create a map variable within a map variable in terraform variables?
variable "var" {
type = map
default = {
firstchoice = {
firstAChoice ="foo"
firstBChoice = "bar"
}
secondchoice = {
secondAChoice = "foobar"
secondBChoice = "barfoo"
}
}
}
If anyone has any insight to whether this is possible or any documentation that elaborates that would be great.
Yes, it's possible to have map variable as value of map variable key. Your variable just needed right indentation. Also I am putting ways to access that variable.
variable "var" {
default = {
firstchoice = {
firstAChoice = "foo"
firstBChoice = "bar"
}
secondchoice = {
secondAChoice = "foobar"
secondBChoice = "barfoo"
}
}
}
To access entire map value of a map key firstchoice, you can try following
value = "${var.var["firstchoice"]}"
output:
{
firstAChoice = foo
firstBChoice = bar
}
To access specific key of that map key (example firstAChoice), you can try
value = "${lookup(var.var["firstchoice"],"firstAChoice")}"
output: foo
Would this syntax be possible? ${var.var[firstchoice[firstAchoice]]}
With Terraform 0.12+ nested blocks are supported seamlessly. Extending #Avichal Badaya's answer to explain it using an example:
# Nested Variable
variable "test" {
default = {
firstchoice = {
firstAChoice = "foo"
firstBChoice = "bar"
}
secondchoice = {
secondAChoice = "foobar"
secondBChoice = "barfoo"
}
thirdchoice = {
thirdAChoice = {
thirdBChoice = {
thirdKey = "thirdValue"
}
}
}
}
}
# Outputs
output "firstchoice" {
value = var.test["firstchoice"]
}
output "FirstAChoice" {
value = var.test["firstchoice"]["firstAChoice"]
}
output "thirdKey" {
value = var.test["thirdchoice"]["thirdAChoice"]["thirdBChoice"]["thirdKey"]
}
Applying the above, you can verify that Terraform map nesting is now quite powerful and this makes a lot of things easier.
# Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
# Outputs:
firstchoice = {
"firstAChoice" = "foo"
"firstBChoice" = "bar"
}
thirdKey = thirdValue
For more complex structures and Rich Value Types, see HashiCorp Terraform 0.12 Preview: Rich Value Types

How to implement an AST given a grammar with JJTree

I'm trying to implement a parser from LaTeX to HTML, to complete my exercise I need to write a JavaCC grammar, generate the Abstract syntax tree and implement a visitor to parse the code.
I've written my .jj grammar file, now I'm confused about how to use jjtree to generate the AST based on grammar file. Anyone can help me?
Here you are my grammar file, if it can help.
ArrayList<LaTeXObject> LaTeX() :
{
ArrayList<LaTeXObject> objects;
}
{
objects = ObjectList() <EOF>
{
return objects;
}
}
ArrayList<LaTeXObject> ObjectList() :
{
ArrayList<LaTeXObject> objects = new ArrayList<LaTeXObject>();
LaTeXObject object;
}
{
( object = Object() { objects.add(object); } )*
{
return objects;
}
}
LaTeXObject Object() :
{
LaTeXObject object;
}
{
(
object = Command()
|
object = Group()
|
object = String()
)
{
return object;
}
}
LaTeXCommand Command() :
{
String name;
}
{
<BACKSLASH>
(
name = Name() Whitespace()
|
name = SpecialCharacter()
|
name = NonSpecialCharacter()
)
{
return new LaTeXCommand(name);
}
}
String Name() :
{
StringBuilder sb = new StringBuilder();
Token token;
}
{
token = <ASCII_LETTER> { sb.append(token.image); } ( LOOKAHEAD( <ASCII_LETTER> ) token = <ASCII_LETTER> { sb.append(token.image); } )*
{
return sb.toString();
}
}
void Whitespace() :
{}
{
( LOOKAHEAD( WhitespaceCharacter() ) WhitespaceCharacter() )*
}
String WhitespaceCharacter() :
{
Token token;
}
{
token = <WHITESPACE>
{
return token.image;
}
}
String SpecialCharacter() :
{
Token token;
}
{
(
token = <BACKSLASH>
|
token = <LBRACE>
|
token = <RBRACE>
|
token = <SPECIAL>
)
{
return token.image;
}
}
String NonSpecialCharacter() :
{
Token token;
}
{
token = <NON_SPECIAL>
{
return token.image;
}
}
LaTeXGroup Group() :
{
ArrayList<LaTeXObject> objects;
}
{
<LBRACE> objects = ObjectList() <RBRACE>
{
return new LaTeXGroup(objects);
}
}
LaTeXString String() :
{
StringBuilder sb = new StringBuilder();
String string;
}
{
string = TextCharacter() { sb.append(string); } ( LOOKAHEAD( TextCharacter() ) string = TextCharacter() { sb.append(string); } )*
{
return new LaTeXString(sb.toString());
}
}
String TextCharacter() :
{
Token token;
}
{
(
token = <WHITESPACE>
|
token = <NON_SPECIAL>
|
token = <SPECIAL>
|
token = <ASCII_LETTER>
|
token = <ASCII_DIGIT>
|
token = <LATIN_SUPPLEMENT>
|
token = <UNICODE_LETTER>
)
{
return token.image;
}
}
So what you have now does build an abstract syntax tree. If you are happy with that, you don't need JJTree at all.
If you really want to use JJTree, you should strip out all the code that makes LatexObjectobjects. Just make all your nonterminal productions return void. Also rename the file from .jj to .jjt. Now run JJTree with your .jjt files as input. Low and behold you'll have a new .jj file that builds an abstract syntax tree. Now fiddle with the .jjt file until the abstract syntax tree it produces is one you are happy with.

Pass by value. Array

I have two arrays. But when I change second - first change too.
I tried
.clone()
.copyOf()
but it didn't work for me.
object MatrixObject {
var table: Array<Array<Int>>? = null
fun randOf(n: Int) {
table= Array(n, { Array(n, { Random().nextInt(100 - 0) + 0 }) })
}
var tableF: Array<Array<Int>>? = null
get() {
if (field==null)
factorization()
return field
}
fun factorization() {
tableF = table!!
... //here I change elements of tableF
}
}
I tried
for(row in 0 until table!!.size)
tableF!![row] = Arrays.copyOf(table!![row], table!![row].size)
and
for(row in 0 until table!!.size)
tableF!![row] = table!![row].clone() // and copyOf()
but it still doesn't work.
I found the solution.I initialized the array.
tableF= Array(table!!.size, { Array(table!!.size, {0}) })
for(row in 0 until table!!.size)
tableF!![row] = table!![row].clone()