Skip to content

Instantly share code, notes, and snippets.

@samuell
Created November 7, 2013 16:18
Show Gist options
  • Select an option

  • Save samuell/7357303 to your computer and use it in GitHub Desktop.

Select an option

Save samuell/7357303 to your computer and use it in GitHub Desktop.
Base complementer example in PaPy
__author__ = 'samuel'
from papy.core import Worker, Plumber, Piper
from papy.core import start_logger
from numap import NuMap
infile_name = "Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa.short"
def base_complement( inbox ):
def basecompl_nucl(nucl):
if nucl == 'A':
return 'T'
elif nucl == 'T':
return 'A'
elif nucl == 'C':
return 'G'
elif nucl == 'G':
return 'C'
else:
return ''
sequence = inbox[0]
new_sequence = ""
for nucl in sequence:
new_sequence += basecompl_nucl(nucl)
return new_sequence
def print_text( inbox ):
text = inbox[0]
print text
base_complementer = Worker(base_complement)
printer = Worker(print_text)
local_computer = NuMap()
base_complementer_node = Piper(base_complementer, parallel=local_computer)
printer_node = Piper(printer, parallel=local_computer, track=True)
network = Plumber()
network.add_pipe((base_complementer_node, printer_node))
end = network.get_outputs()[0]
network.start([(line for line in open(infile_name))])
network.run()
print "Finished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment