Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Apr 1, 2011
1 parent 37cb540 commit 426d801
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
17 changes: 11 additions & 6 deletions bin/moa_prompt
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#!/bin/bash

function _moa_prompt {
[[ -d '.moa' ]] || return 0
[[ -f '.moa/template' ]] || return 0

#save history to a .moa/history
# based on:
#Get the last command
#based on:
#http://stackoverflow.com/questions/945288/...
# ...saving-current-directory-to-bash-history
#
local lc=$(history 1)
lc="${lc# *[0-9]* }"

#save the last command to a user specific location
echo $lc > ~/.moa.last.command

[[ -d '.moa' ]] || return 0
#and add it to the local history if this is a mob job
echo $lc >> .moa/history

#prepare for visualization
#if there is no template, there is not much we can do
[[ -f '.moa/template' ]] || return 0

#prepare for visualization
local blue="\033[34m"
local black="\033[30m"
local bright="\033[1m"
Expand Down
64 changes: 63 additions & 1 deletion lib/python/moa/plugin/adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def defineCommands(data):
'usage' : 'moa map -t "title" -- echo "do something"',
'unittest' : MAPTEST
}
data['commands']['!'] = {
'desc' : 'Moa-fy the last (bash) command issued',
'call' : exclamate,
'needsJob' : False,
'usage' : 'moa !'
}

def defineOptions(data):
parserN = optparse.OptionGroup(data['parser'], "Moa adhoc, simple & map")
Expand Down Expand Up @@ -105,6 +111,62 @@ def createSimple(data):
parameters=params)



def exclamateNoJob(data):
"""
Create a "simple" job & set the last command
to the 'process' parameter
"""
options = data['options']

title = options.title
if not options.title:
moa.ui.warn("Do not forget to set a title")
histFile = os.path.join(os.path.expanduser('~'), '.moa.last.command')
if not os.path.exists(histFile):
moa.ui.exitError(
("This needs to be used in conjunction with the " +
"moa_prompt code. Please read the manual") )

with open(histFile) as F:
last = F.read().strip()


job = moa.job.newJob(
wd = data.wd, template='simple',
title = title,
parameters = [('process', last)])

def exclamateInJob(data):
"""
Reuse the last issued command: set it as the 'process' parameters
in the current job
"""
job = data.job
histFile = os.path.join(job.confDir, 'history')
if not os.path.exists(histFile):
moa.ui.exitError(
("This needs to be used in conjunction with the " +
"moa_prompt code. Please read the manual") )

with open(histFile) as F:
last = F.readlines()[-1].strip()
moa.ui.fprint("{{bold}}Using command:{{reset}}", f='jinja')
moa.ui.fprint(last)
job.conf.process=last
job.conf.save()

def exclamate(data):
"""
Set the 'process' parameter to the last issued command. If no moa
job exists, create a 'simple'job.
"""
job = data.job
if job.isMoa():
exclamateInJob(data)
else:
exclamateNoJob(data)

def createMap(data):
"""
Create a 'map' adhoc job.
Expand Down Expand Up @@ -148,7 +210,7 @@ def createMap(data):
params = []
if not command and not options.noprompt:
command=moa.ui.askUser('process:\n> ', '')
params[('process', command)]
params.append(('process', command))

if not options.noprompt:
input=moa.ui.askUser('input:\n> ', '')
Expand Down
2 changes: 1 addition & 1 deletion template2/ncbi.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ncbi: $(ncbi_sequence_name).fasta
$(ncbi_sequence_name).fasta: webEnv=$(shell xml_grep --cond "WebEnv" query.xml --text_only)
$(ncbi_sequence_name).fasta: queryKey=$(shell xml_grep --cond "QueryKey" query.xml --text_only)
$(ncbi_sequence_name).fasta: query.xml
wget "http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=$(ncbi_db)&WebEnv=$(webEnv)&query_key=$(queryKey)&report=fasta" -O $(ncbi_sequence_name).tmp
wget "http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=$(ncbi_db)&WebEnv=$(webEnv)&query_key=$(queryKey)&report=fasta" -O $(ncbi_sequence_name).fasta

#query.xml contains the IDs of the sequences to download
query.xml:
Expand Down

0 comments on commit 426d801

Please sign in to comment.