Skip to content

Commit

Permalink
Merge branch 'moa.0.11' of ssh.github.com:mfiers/Moa into moa.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Oct 23, 2012
2 parents 993179a + c5e150c commit 0abfe76
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 6 deletions.
13 changes: 8 additions & 5 deletions README
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Moa - lightweight workflows in bioinformatics.

For information on how to install and operate Moa, please refer to
http://mfiers.github.com/Moa/
f
or try:
For information on how to install and operate Moa, please read the documentation at:

moa --help
http://moa.readthedocs.org/en/latest/index.html

check the source code at:

https://github.com/mfiers/Moa

or run:

moa --help
6 changes: 5 additions & 1 deletion lib/python/moa/plugin/job/smw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def _savePage2(page, txt):
#moa.ui.message("saved change message to SMW")
except mwclient.errors.LoginError:
moa.ui.error("Invalid login for smw - cannot save change message")
except:
moa.ui.error("Cannot save to SMW - uncertain why")
return

def _savePage(page, txt):
background = sysConf.plugins.job.smw.get('background', False)
Expand Down Expand Up @@ -155,11 +158,12 @@ def hook_finish(job):
message = moa.ui._textFormattedMessage(
[sysConf.args.changeMessage,
sysConf.doc.changeMessage] )

if sysConf.commands[sysConf.args.command]['logJob']:
if sysConf.args.command != 'smw_save_job':
_saveJobToSmw(job)
_saveChangeMessage(job, message)

sys.exit(0)

def _checkJobInSmw(job):
Expand Down
116 changes: 116 additions & 0 deletions lib/python/moa/plugin/system/evernote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Copyright 2009-2011 Mark Fiers
# The New Zealand Institute for Plant & Food Research
#
# This file is part of Moa - http://github.com/mfiers/Moa
#
# Licensed under the GPL license (see 'COPYING')
#
"""
**evernote** - Use evernote to store job results
------------------------------------------------
Use evernote to store a small message on job completion
Depends on an authenticated geeknote installation in the path. Moa
expects it to be aliased as `geeknote`
see:
http://www.geeknote.me/
"""

import os
import sys
import time
import socket
from datetime import datetime, timedelta
import subprocess as sp

import moa.logger
l = moa.logger.getLogger(__name__)
import moa.ui

from moa.sysConf import sysConf

def niceRunTime(d):
"""
Nice representation of the run time
d is time duration string
"""
d = str(d)
if ',' in d:
days, time = d.split(',')
else:
days = 0
time = d

hours, minutes, seconds = time.split(':')
hours, minutes = int(hours), int(minutes)
seconds, miliseconds = seconds.split('.')
seconds = int(seconds)
miliseconds = int(miliseconds)

if days > 0:
if days == 1:
return "1 day, %d hrs" % hours
else:
return "%d days, %d hrs" % (days, hours)

if hours == 0 and minutes == 0 and seconds == 0:
return "<1 sec"
if hours > 0:
return "%d:%02d hrs" % (hours, minutes)
elif minutes > 0:
return "%d:%02d min" % (minutes, seconds)
else:
return "%d sec" % seconds

def hook_postRun():
"""
Send a tweet out upon completing the default run
"""
runtime = datetime.today() - sysConf.logger.start_time
#print runtime
#print timedelta(seconds=1)
if timedelta(seconds=1) > runtime:
# do not return anythin unless it ran for at least a certain
# amount of time
return

short_title = '%s/%s finished' % (
socket.gethostname().split('.')[0],
sysConf.job.wd.rsplit('/', 1)[-1])

content = ['Moa job finished\n']
content.append(" Run time: %s\n" % niceRunTime(runtime))
content.append(" Host: %s\n" % socket.gethostname())
content.append(" Wd: %s\n" % sysConf.job.wd)

#fork - don't wait for this!
pid = os.fork()
if pid != 0:
return
print short_title
print "\n".join(content)
#start geeknote process
moa.ui.message('Sending message to evernote', store=False)
cl = '%s create --title "%s" --content - --notebook Moa' % (
sysConf.plugins.system.evernote.geeknote, short_title)
print cl
P = sp.Popen(cl, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE, shell=True)

o,e = P.communicate("\n".join(content))
o = o.strip()
e = e.strip()

if o or e:
with open('.moa/geeknote.log', 'a') as F:
F.write("------\n%s\n%s\n" % (short_title, "\n".join(content)))
if o:
F.write('\n\nSTDOUT:\n')
F.write(o)
if e:
F.write('\n\nSTDERR:\n')
F.write(e)
sys.exit(0)

4 changes: 4 additions & 0 deletions lib/python/moa/plugin/system/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@moa.args.argument('filter', nargs='?', help='show only directories that match this filter')
@moa.args.addFlag('-a', '--all')
@moa.args.doNotLog
@moa.args.command
def tree(job, args):
"""
Expand Down Expand Up @@ -102,6 +103,7 @@ def tree(job, args):
# ("%%s %%-%ds | %%s" % maxTemplateLen) % (s,t,p), f='jinja')

@moa.args.needsJob
@moa.args.doNotLog
@moa.args.command
def out(job, args):
"""
Expand All @@ -114,6 +116,7 @@ def out(job, args):
print out

@moa.args.needsJob
@moa.args.doNotLog
@moa.args.command
def err(job, args):
"""
Expand All @@ -125,6 +128,7 @@ def err(job, args):
else:
print err

@moa.args.doNotLog
@moa.args.command
def version(job, args):
"""
Expand Down
57 changes: 57 additions & 0 deletions lib/python/moa/template/local_templates/autohagfish.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
### prepare

if [[ ! -f "db.1.ebwt" ]]
then
echo "Building index for {{ fasta }}"
bowtie-build {{ fasta }} db
else
echo "Skip bowtie build - files exists"
fi

### run

DEBUG=""

mkdir -p touch
[[ -f "{{ outbase }}.unsorted" ]] || (
echo "Running bowtie for"
echo " forward: {{ fw_fq }}"
echo " reverse: {{ rev_fq }}"
if [[ $DEBUG == 'echo' ]]
then
echo bowtie -I 1 -X 10000 -p {{ threads }} --fr -S \
db -1 {{ fw_fq }} -2 {{ rev_fq }} \
\| samtools view -f 2 -bS - \> {{ outbase }}.unsorted
else
bowtie -I 1 -X 10000 -p {{ threads }} --fr -S \
db -1 {{ fw_fq }} -2 {{ rev_fq }} \
| samtools view -f 2 -bS - > {{ outbase }}.unsorted
fi
)

[[ -f "{{ outbase }}.bam" ]] || (
echo "Sorting {{ outbase }}.bam"
$DEBUG samtools sort {{ outbase }}.unsorted {{ outbase }}
)

[[ -f "{{ outbase }}.bai" ]] || (
echo "Indexing {{ outbase }}"
$DEBUG samtools index {{ outbase }}.bam
)

[[ -d "readpairs/{{ outbase }}" ]] || (
echo "running hagfish_extract for {{ outbase }}"
$DEBUG hagfish_extract -v {{ outbase }}.bam
)

### finish

hagfish_gapfinder -v -f {{ fasta }}
hagfish_coverage_combine -v
hagfish_report -v

### clean

rm -rf `dirname {{ output }}`
rm -rf bins combined coverage readpairs report seqInfo stats

62 changes: 62 additions & 0 deletions lib/python/moa/template/local_templates/autohagfish.moa
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
author: Mark Fiers
backend: ruff
commands:
run:
help: 'Run hagfish'
mode: map
clean:
mode: simple
help: remove all Hagfish files
finish:
help: finish up - find gaps - combine plots - create a report
mode: simple
creation_date: Tue Mar 29 16:34:19 2011
description: Run the preparatory steps for hagfish
filesets:
fasta:
category: prerequisite
help: fasta sequence of the reference
type: single
optional: false
fw_fq:
category: input
help: 'forward fq input'
optional: false
pattern: '*/*1.fq'
type: set
rev_fq:
category: input
help: 'reverse fq input'
optional: true
pattern: '*/*2.fq'
type: map
source: fw_fq
outbase:
category: output
help: 'basename for output files'
optional: true
pattern: './*'
type: map
source: fw_fq
parameters:
threads:
default: 8
help: 'no threads to use'
optional: true
type: integer
min_ok:
default: 0
help: Minimal acceptable insert size for an aligned pair. If omitted,
hagfish will make an estimate
optional: true
type: int
max_ok:
default: 0
help: Maximal acceptable insert size for an aligned pair. If omitted,
hagfish will make an estimate
optional: true
type: int
moa_id: autohagfish
modification_date: Thu, 19 May 2011 20:49:04 +1200
name: autohagfish
title: Automatically run bowtie & hagfish combined

0 comments on commit 0abfe76

Please sign in to comment.