Is there a way to do something like awk in nf-test...
# nf-test
u
Is there a way to do something like awk in nf-test? I'm running a process that outputs a log file looking like this ERR204916.Aligned.out.bam USED: 0 NOT_PAIRED: 0 The first line is a header, and then there are statuses with numbers. Is there anyway I can check that the number next to USED: is bigger than 0, for example?
m
maybe use https://github.com/lukfor/nft-csv with a space delimiter?
u
So, something like this?
Copy code
with (path("file.csv").csv(sep: ": ") {
    assert rows[1][1] > 0
}
I guess I can use println for debugging, right? So start with
Copy code
with (path("file.csv").csv(sep: ": ") {
    println(rows[1])
}
and see what I get?
m
yes, i think it should work
u
Hi, So CSV doesn't work, because the first line has only one column, which confuses it. So I'm trying to use regular expressions. I have a bit of code in my main.nf.test that looks like this
Copy code
def lines = path(process.out.prep_read_outcomes_file[0][1]).readLines()
println(lines[1])
println(lines[1] == "USED: 93265")
def reads_used = lines[1] =~ /USED: (\d+)/
reads_used.println()
Now, the line is "USED: 93265", so the println(lines[1]==) line prints true However, the regular expression doesn't manage to find any matches. I tested the groovy regular expression at https://onecompiler.com/groovy/44eaxf8qe, so it feels like I'm missing something on the difference between nf-test and groovy regular expressions. Any advice?
Bumping this up if anyone knows how to solve this please?
n
You still need to fetch the matched regex:
Copy code
println(reads_used[0][1])
Your regex looks correct
Ideally you should also add some error handling in case the regex isn't found:
Copy code
if (reads_used.matches()) {
    amount = reads_used[0][1]
} else {
    println("couldn't find how many reads are used")
}
u
Okay. That works really great. Is there a groovy tutorial you would recommend? AFAIK nf-test is written in groovy, and I just have no idea on the data structures I should be getting. This feels like the second time where if I knew more groovy, I could just solve this. Or is there an nf-test debugger/groovy debugger I can practice with? Like, can I save the nf-test process results into a file, and somehow load it into https://groovy-lang.org/groovyconsole.html That groovy console seems useful, but I don't know how to get the process.out data structure (?) into it.
n
There was an nf-test debugger announced some time ago but I'm not sure if it's finished already