Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
61576331
Commit
61576331
authored
Mar 08, 2016
by
Eric Coissac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prototype for the obi unix command and the count sub command
parent
a08def47
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
264 additions
and
0 deletions
+264
-0
python/obi.py
python/obi.py
+228
-0
python/obitools3/command/__init__.py
python/obitools3/command/__init__.py
+0
-0
python/obitools3/command/count.py
python/obitools3/command/count.py
+36
-0
No files found.
python/obi.py
0 → 100644
View file @
61576331
#!/usr/local/bin/python3.4
'''
obi -- shortdesc
obi is a description
It defines classes_and_methods
@author: user_name
@copyright: 2014 organization_name. All rights reserved.
@license: license
@contact: user_email
@deffield updated: Updated
'''
import
sys
import
pkgutil
import
argparse
import
logging
import
json
default_config
=
{
'obi'
:
{
'log'
:
True
,
'loglevel'
:
'INFO'
,
'version'
:
False
,
'progress'
:
True
}
}
from
obitools3
import
command
from
obitools3.version
import
version
__all__
=
[]
__version__
=
version
__date__
=
'2014-09-28'
__updated__
=
'2014-09-28'
DEBUG
=
1
TESTRUN
=
0
PROFILE
=
0
def
loadCommand
(
name
,
loader
):
'''
Load a command module from its name and an ImpLoader
This function is for internal use
@param name: name of the module
@type name: str
@param loader: the module loader
@type loader: ImpLoader
@return the loaded module
@rtype: module
'''
module
=
loader
.
find_module
(
name
).
load_module
(
name
)
return
module
def
getCommandsList
():
'''
Returns the list of sub-commands available to the main `obi` command
@return: a dict instance with key corresponding to each command and
value corresponding to the module
@rtype: dict
'''
cmds
=
dict
((
x
[
1
],
loadCommand
(
x
[
1
],
x
[
0
]))
for
x
in
pkgutil
.
iter_modules
(
command
.
__path__
)
if
not
x
[
2
])
return
cmds
def
getLogger
(
config
):
'''
Returns the logger as defined by the command line option
or by the config file
:param config:
'''
output
=
config
[
'obi'
][
'outputfilename'
]
level
=
config
[
'obi'
][
'loglevel'
]
logfile
=
config
[
'obi'
][
'log'
]
rootlogger
=
logging
.
getLogger
()
logFormatter
=
logging
.
Formatter
(
"%(asctime)s [%(levelname)-5.5s] %(message)s"
)
stderrHandler
=
logging
.
StreamHandler
(
sys
.
stderr
)
stderrHandler
.
setFormatter
(
logFormatter
)
rootlogger
.
addHandler
(
stderrHandler
)
if
logfile
:
fileHandler
=
logging
.
FileHandler
(
"%s.log"
%
output
)
fileHandler
.
setFormatter
(
logFormatter
)
rootlogger
.
addHandler
(
fileHandler
)
try
:
loglevel
=
getattr
(
logging
,
level
)
except
:
loglevel
=
logging
.
INFO
rootlogger
.
setLevel
(
loglevel
)
config
[
'obi'
][
'logger'
]
=
rootlogger
return
rootlogger
class
ObiParser
(
argparse
.
ArgumentParser
):
def
error
(
self
,
message
):
sys
.
stderr
.
write
(
'error: %s
\n
'
%
message
)
self
.
print_help
()
sys
.
exit
(
2
)
def
buildArgumentParser
():
parser
=
ObiParser
()
parser
.
add_argument
(
'--version'
,
dest
=
'obi:version'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Print the version of the OBITools'
)
parser
.
add_argument
(
'--no-log'
,
dest
=
'obi:log'
,
action
=
'store_false'
,
default
=
None
,
help
=
'Do not create a logfile for the data analyze'
)
parser
.
add_argument
(
'--no-progress'
,
dest
=
'obi:progress'
,
action
=
'store_false'
,
default
=
None
,
help
=
'Do not print the progress bar during analyzes'
)
subparsers
=
parser
.
add_subparsers
(
title
=
'subcommands'
,
description
=
'valid subcommands'
,
help
=
'additional help'
)
commands
=
getCommandsList
()
for
c
in
commands
:
module
=
commands
[
c
]
if
hasattr
(
module
,
"run"
):
if
hasattr
(
module
,
"__title__"
):
sub
=
subparsers
.
add_parser
(
c
,
help
=
module
.
__title__
)
else
:
sub
=
subparsers
.
add_parser
(
c
)
if
hasattr
(
module
,
"addOptions"
):
module
.
addOptions
(
sub
)
sub
.
set_defaults
(
**
{
'obi:module'
:
module
})
return
parser
def
buildDefaultConfiguration
():
global
default_config
commands
=
getCommandsList
()
for
c
in
commands
:
module
=
commands
[
c
]
assert
hasattr
(
module
,
"run"
)
if
hasattr
(
module
,
'default_config'
):
default_config
[
c
]
=
module
.
default_config
else
:
default_config
[
c
]
=
{}
return
default_config
def
getConfiguration
():
global
default_config
if
'__done__'
in
default_config
:
return
default_config
parser
=
buildArgumentParser
()
options
=
vars
(
parser
.
parse_args
())
config
=
buildDefaultConfiguration
()
for
k
in
options
:
section
,
key
=
k
.
split
(
':'
)
s
=
config
[
section
]
if
options
[
k
]
is
not
None
:
s
[
key
]
=
options
[
k
]
if
config
[
'obi'
][
'version'
]:
print
(
"The OBITools - Version %s"
%
__version__
)
sys
.
exit
(
0
)
if
not
'module'
in
config
[
'obi'
]:
print
(
'
\n
Error: No obi command specified'
,
file
=
sys
.
stderr
)
parser
.
print_help
()
sys
.
exit
(
2
)
if
config
[
'obi'
][
'outputfilename'
]
is
None
:
config
[
'obi'
][
'outputfilename'
]
=
config
[
'obi'
][
'indexfilename'
]
getLogger
(
config
)
config
[
'__done__'
]
=
True
return
config
if
__name__
==
"__main__"
:
config
=
getConfiguration
()
config
[
'obi'
][
'module'
].
run
(
config
)
\ No newline at end of file
python/obitools3/command/__init__.py
0 → 100644
View file @
61576331
python/obitools3/command/count.py
0 → 100644
View file @
61576331
'''
Created on 8 mars 2016
@author: coissac
'''
__title__
=
"Counts sequences in a sequence set"
default_config
=
{
'countmode'
:
None
}
def
addOptions
(
parser
):
parser
.
add_argument
(
dest
=
'obi:input'
,
metavar
=
'obi:input'
,
nargs
=
'?'
,
default
=
None
,
help
=
'input data set'
)
group
=
parser
.
add_option_group
(
'Obicount specific options'
)
group
.
add_option
(
'-s'
,
'--sequence'
,
action
=
"store_true"
,
dest
=
"count:sequence"
,
default
=
False
,
help
=
"Prints only the number of sequence records."
)
group
.
add_option
(
'-a'
,
'--all'
,
action
=
"store_true"
,
dest
=
"count:all"
,
default
=
False
,
help
=
"Prints only the total count of sequence records (if a sequence has no `count` attribute, its default count is 1) (default: False)."
)
def
run
(
config
):
# The code of my command
pass
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment