Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 KB | None | 0 0
  1. #!/usr/bin/env Nextflow
  2.  
  3. /*
  4. * Defining pipeline input data
  5. */
  6. params.query = "$baseDir/data/sample.fa"
  7. params.db = "$baseDir/blast-db/pdb/tiny"
  8. params.out = "result.txt"
  9. params.chunkSize = 5
  10.  
  11. db_name = file(params.db).name
  12. db_path = file(params.db).parent
  13. /*
  14. * Given the query parameter creates a channel emitting the query fasta file(s),
  15. * the file is split in chunks containing as many sequences as defined by 'chunkSize'.
  16. * Finally assign the result channel to the variable 'fasta'
  17. */
  18. Channel
  19. .fromPath(params.query)
  20. .splitFasta(by: params.chunkSize)
  21. .set { fasta }
  22. /*
  23. * Executes a BLAST job for each chunk emitted by the 'fasta' channel
  24. * and creates as output a channel named 'top_hits' emitting BLAST matches
  25. */
  26. process blast {
  27. input:
  28. file 'query.fa' from fasta
  29. file db_path
  30.  
  31. output:
  32. file top_hits
  33.  
  34. """
  35. blastp -db $db_path/$db_name -query query.fa -outfmt 6 > blast_result
  36. cat blast_result | head -n 10 | cut -f 2 > top_hits
  37. """
  38. }
  39. /*
  40. * Each time a file emitted by the 'top_hits' channel an extract job is executed
  41. * producing a file containing the matching sequences
  42. */
  43. process extract {
  44. input:
  45. file top_hits
  46. file db_path
  47.  
  48. output:
  49. file sequences
  50.  
  51. """
  52. blastdbcmd -db $db_path/$db_name -entry_batch top_hits | head -n 10 > sequences
  53. """
  54. }
  55. /*
  56. * Collects all the sequences files into a single file
  57. * and prints the resulting file content when complete
  58. */
  59. sequences
  60. .collectFile(name: params.out)
  61. .println { file -> "matching sequences:\n ${file.text}" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement