Skip to content

Instantly share code, notes, and snippets.

View samuell's full-sized avatar
💻
Hacking away

Samuel Lampa samuell

💻
Hacking away
View GitHub Profile
<?php
require_once('ARC2.php');
// Init parser
$parser = ARC2::getTurtleParser();
$turtle = <<<EOD
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@samuell
samuell / exec_cmd.py
Last active December 27, 2015 09:49
A convenience method for executing external commands and getting the output, in python
import subprocess as sub
def exec_cmd(commandstr):
proc = sub.Popen(commandstr, stdout=sub.PIPE, shell=True)
return proc.communicate()[0].strip()
@samuell
samuell / numap_test.py
Last active December 27, 2015 11:28
Spawning parallel jobs with NuMap
from numap import NuMap
import time
def capitalizer(name):
time.sleep(1)
return name.capitalize()
namelist = ('rolf', 'mariann', 'samuel', 'sandra', 'simon', 'theresa', 'jonathan', 'elias', 'miryam')
result_iterator = NuMap(capitalizer, namelist)
@samuell
samuell / basecompl_papy.py
Created November 7, 2013 16:14
Base complementer example in Papy, trying to add multple workers in to a single piper
__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):
@samuell
samuell / basecompl_papy.py
Created November 7, 2013 16:18
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):
class ATask(luigi.Task):
def requires(self):
# Defines what is the upstream task to this one.
# Is later used by the input() function.
return APreviousTask()
def output(self):
return luigi.LocalTarget(self.input().path + ".new_extension")
@samuell
samuell / stream_editing_tsv.py
Last active December 28, 2015 03:39
Example showing how to manipulate tab separated data on the standard input, and write the manipulated data to standard output.
import csv
from sys import stdin, stdout
tsv_in = csv.reader(stdin, delimiter="\t")
tsv_out = csv.writer(stdout, delimiter="\t")
for row in tsv_in:
# Write out only columns 2-*
tsv_out.writerow(row[1:])
@samuell
samuell / select_parent_luigi_task_by_param.py
Created December 3, 2013 18:51
Demonstrates how one can select which parent task a luigi task should depend on, by specifying the parent task class name via a parameter.
import luigi
class ATask(luigi.Task):
def output(self):
return luigi.LocalTarget("atask_output.txt")
def run(self):
with self.output().open("w") as outfile:
outfile.write("Test")
@samuell
samuell / luigi_dynamic_dependency_graph_definition.py
Last active March 21, 2020 14:57
Dynamically specify luigi data flow
import luigi
class ATask(luigi.Task):
def output(self):
return luigi.LocalTarget("atask_output.txt")
def run(self):
with self.output().open("w") as outfile:
outfile.write("Test")
@samuell
samuell / neat.py
Last active December 31, 2015 01:29
"Neat way to {do_what} in {lang}".format(do_what="format strings", lang="python")