Getting an output value from a python script within nextflow process

65 views
Skip to first unread message

Dave Deandre

unread,
Dec 20, 2018, 5:12:39 PM12/20/18
to Nextflow
Hi,

Is there a way to output a value initialized from within python code block in a nextflow process so it can be stored in a channel?

For instance, here is my code:

process getFirstMinimumCoverage {

       input:

               file coverageInfo from coverageFileChannel

       output:

               val firstMinPair into firstMinPairChannel

       script:

               """


                #!/usr/bin/env python


                sampleName = "$coverageInfo".replace(".ctx.covg","")




                fh = open("$coverageInfo", "r")




                pairsList = []




                for line in fh:


                        line = line.strip()


                        pairsList.append(line.split("\t"))


                fh.close()






                firstMinPair = pairsList[2]


                for i in range(2,len(pairsList) - 2):


                        if int(pairsList[i][1]) < int(pairsList[i+1][1]):


                                firstMinPair = pairsList[i]


                                break




                """


}


Nextflow errors the following statement in the s

Caused by:


  Missing value declared as output parameter: firstMinPair



Thank you in advance!

Dave

Marc Logghe

unread,
Dec 21, 2018, 6:23:03 AM12/21/18
to next...@googlegroups.com
Hi Dave,
As far as I know it is not possible to access python variables from NextFlow. The only way to get hands on that value is to print it in your python script and grab that with NextFlow from the stdout.

Then, in your process:

output:

               stdout into firstMinPairChannel


HTH,
Marc

--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+u...@googlegroups.com.
Visit this group at https://groups.google.com/group/nextflow.
For more options, visit https://groups.google.com/d/optout.

Steve

unread,
Dec 21, 2018, 3:25:49 PM12/21/18
to Nextflow
Similarly, consider writing the output value to a file then setting that file as the 'output' of the task, then you can read the contents of the file from within your Channel and pass on the value.

Dave Deandre

unread,
Dec 25, 2018, 2:41:12 PM12/25/18
to Nextflow
Hi Marc,

Thank you for the suggestion, now I am using this method to output the value.

Best,

Dave

Dave Deandre

unread,
Dec 25, 2018, 2:41:53 PM12/25/18
to Nextflow
Hi Steve,

I think the standard out value works better for me, but I will keep in mind of this method in the future. Thanks for the help!

Dave
Reply all
Reply to author
Forward
0 new messages