Skip to content

Instantly share code, notes, and snippets.

@pditommaso
Forked from egonw/demo.nf
Last active April 21, 2019 09:32
Show Gist options
  • Save pditommaso/77847724c877a70ebe0dcf33b1175ef0 to your computer and use it in GitHub Desktop.
Save pditommaso/77847724c877a70ebe0dcf33b1175ef0 to your computer and use it in GitHub Desktop.
Using Bioclipse in Nextflow.
#!/usr/bin/env nextflow
@Grab(group='net.bioclipse.bacting', module='managers-cdk', version='0.0.3')
import net.bioclipse.managers.CDKManager
params.str = "./data.tsv"
params.size = 5000
process splitWikidata {
input:
file str from Channel.fromPath(params.str)
output:
file 'chunk_*' into smiChunks
"""
cat $str | tail -n +2 | split -l ${params.size} - chunk_
"""
}
process checkSMILES {
input:
val x from smiChunks
output:
stdout results
exec:
def cdk = new CDKManager(".");
new File(x).readLines().each {
def fields = it.split()
try {
// println "x: " + fields[1]
cdk.fromSMILES(fields[1])
} catch (Exception exc) {
println fields[0] + ": " + exc.message
}
}
}
results.subscribe {
println it
}
@egonw
Copy link

egonw commented Apr 21, 2019

This code fails for me with this error message:

ERROR ~ Error executing process > 'checkSMILES (1)'

Caused by:
  Could not find matching constructor for: java.io.File(ArrayList)

Source block:
  def cdk = new CDKManager(".");
  new File(x).readLines().each {
    def fields = it.split()
    try {
      // println "x: " + fields[1]
      cdk.fromSMILES(fields[1])
    } catch (Exception exc) {
      println fields[0] + ": " + exc.message
    }
  }

Work dir:
  /home/egonw/tmp/nf/work/29/1cd5958914f3c7f5d5c4a88add0a0e

Tip: view the complete command output by changing to the process work dir and entering the command `cat .command.out`

 -- Check '.nextflow.log' file for details

The problem seems to be that x is an Array, so when I iterate over that first it works:

    x.each { chunk ->
      // println "x: " + chunk
      chunk.readLines().each { line ->
        def fields = line.split()
        try {
          // println "x: " + fields[1]
          cdk.fromSMILES(fields[1])
        } catch (Exception exc) {
          println fields[0] + ": " + exc.message
        }
      }
    }

But this change may explain why it only uses one cpu core?

@pditommaso
Copy link
Author

My fault. The input should be declared as:

  input: 
  val x from smiChunks.flatten()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment