Skip to content

Commit

Permalink
refactor: Move script into bin
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundmiller committed Jul 30, 2024
1 parent d45365b commit d74eaba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
27 changes: 27 additions & 0 deletions bin/results2fasta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
import re
import os
import os.path

with open("!{results}", "r") as input_handle:
data = input_handle.read()
##print(data)

id_match = re.search('SEQUENCE_ID=(.+)',data)
id = id_match.group(1)

bespoke_regex = '(?P<id>PRIMER_PAIR_[0-9]+)_PENALTY=(?P<penalty>[0-9.]+).+?PRIMER_LEFT_[0-9]+_SEQUENCE=(?P<left>[atcgATCGnN]+).+?PRIMER_RIGHT_[0-9]+_SEQUENCE=(?P<right>[atcgATCGnN]+).+?PRIMER_PAIR_[0-9]+_PRODUCT_SIZE=(?P<size>[0-9]+).+?PRIMER_PAIR_[0-9]+_PRODUCT_TM=[0-9.]+'

matches = list(re.finditer(bespoke_regex,data,flags=re.MULTILINE|re.DOTALL))

output_handle = open("!{results}.fa", "w")
for m in matches:
line = ">{ID} primer3 {SUBID} penalty:{PEN} type:LEFT product:{PROD}bp".format(ID=id,SUBID=m.group("id"),PEN=m.group("penalty"),PROD=m.group("size"))+os.linesep
output_handle.write(line)
line = m.group("left")+os.linesep
output_handle.write(line)
line = ">{ID} primer3 {SUBID} penalty:{PEN} type:RIGHT product:{PROD}bp".format(ID=id,SUBID=m.group("id"),PEN=m.group("penalty"),PROD=m.group("size"))+os.linesep
output_handle.write(line)
line = m.group("right")+os.linesep
output_handle.write(line)
output_handle.close()
35 changes: 4 additions & 31 deletions modules/primer3_results2fasta/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,8 @@ process primer3_results2fasta {
output:
path "${results}.fa"

shell:
'''
#!/usr/bin/env python
import re
import os
import os.path
print("hello world!")
with open("!{results}", "r") as input_handle:
data = input_handle.read()
##print(data)
id_match = re.search('SEQUENCE_ID=(.+)',data)
id = id_match.group(1)
bespoke_regex = '(?P<id>PRIMER_PAIR_[0-9]+)_PENALTY=(?P<penalty>[0-9.]+).+?PRIMER_LEFT_[0-9]+_SEQUENCE=(?P<left>[atcgATCGnN]+).+?PRIMER_RIGHT_[0-9]+_SEQUENCE=(?P<right>[atcgATCGnN]+).+?PRIMER_PAIR_[0-9]+_PRODUCT_SIZE=(?P<size>[0-9]+).+?PRIMER_PAIR_[0-9]+_PRODUCT_TM=[0-9.]+'
matches = list(re.finditer(bespoke_regex,data,flags=re.MULTILINE|re.DOTALL))
output_handle = open("!{results}.fa", "w")
for m in matches:
line = ">{ID} primer3 {SUBID} penalty:{PEN} type:LEFT product:{PROD}bp".format(ID=id,SUBID=m.group("id"),PEN=m.group("penalty"),PROD=m.group("size"))+os.linesep
output_handle.write(line)
line = m.group("left")+os.linesep
output_handle.write(line)
line = ">{ID} primer3 {SUBID} penalty:{PEN} type:RIGHT product:{PROD}bp".format(ID=id,SUBID=m.group("id"),PEN=m.group("penalty"),PROD=m.group("size"))+os.linesep
output_handle.write(line)
line = m.group("right")+os.linesep
output_handle.write(line)
output_handle.close()
'''
script:
"""
results2fasta.py ${results} ${results}.fa
"""
}

0 comments on commit d74eaba

Please sign in to comment.