Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Laros
barcode
Commits
1fa761af
Commit
1fa761af
authored
May 17, 2013
by
Laros
Browse files
Added a test function which tests a list of barcodes.
Fixed a dependency. Renamed the makebc command to make.
parent
82e8f875
Changes
3
Hide whitespace changes
Inline
Side-by-side
barcode/__init__.py
View file @
1fa761af
...
...
@@ -22,7 +22,7 @@ Licensed under the MIT license, see the LICENSE file.
RELEASE
=
False
__version_info__
=
(
'0'
,
'
1
'
,
'dev'
)
__version_info__
=
(
'0'
,
'
3
'
,
'dev'
)
__version__
=
'.'
.
join
(
__version_info__
)
...
...
barcode/barcode.py
View file @
1fa761af
...
...
@@ -137,6 +137,21 @@ def barcode(length, max_stretch, min_dist):
min_dist
)
#barcode
def
testBarcodes
(
barcodes
,
min_dist
):
"""
Test a set of barcodes.
@arg barcodes: List of barcodes.
@type barcodes: list[str]
@arg min_dist: Minimum distance between the barcodes.
@type min_dist: int
@returns: The number of barcodes that violate the distance constraint.
@rtype: int
"""
return
len
(
barcodes
)
-
len
(
filterDistance
(
barcodes
,
min_dist
))
#testBarcodes
def
main
():
"""
Main entry point.
...
...
@@ -144,6 +159,12 @@ def main():
output_parser
=
argparse
.
ArgumentParser
(
add_help
=
False
)
output_parser
.
add_argument
(
"OUTPUT"
,
type
=
argparse
.
FileType
(
'w'
),
help
=
"output file"
)
input_parser
=
argparse
.
ArgumentParser
(
add_help
=
False
)
input_parser
.
add_argument
(
"INPUT"
,
type
=
argparse
.
FileType
(
'r'
),
help
=
"input file"
)
distance_parser
=
argparse
.
ArgumentParser
(
add_help
=
False
)
distance_parser
.
add_argument
(
"-d"
,
dest
=
"distance"
,
type
=
int
,
default
=
3
,
help
=
"minimum distance between the barcodes"
)
usage
=
__doc__
.
split
(
"
\n\n\n
"
)
parser
=
argparse
.
ArgumentParser
(
...
...
@@ -151,20 +172,25 @@ def main():
description
=
usage
[
0
],
epilog
=
usage
[
1
])
subparsers
=
parser
.
add_subparsers
(
dest
=
"subcommand"
)
parser_make
bc
=
subparsers
.
add_parser
(
"make
bc"
,
parents
=
[
output
_parser
],
description
=
docSplit
(
barcode
))
parser_make
bc
.
add_argument
(
"-l"
,
dest
=
"length"
,
type
=
int
,
default
=
8
,
parser_make
=
subparsers
.
add_parser
(
"make
"
,
parents
=
[
output_parser
,
distance
_parser
],
description
=
docSplit
(
barcode
))
parser_make
.
add_argument
(
"-l"
,
dest
=
"length"
,
type
=
int
,
default
=
8
,
help
=
"lenght of the barcodes"
)
parser_make
bc
.
add_argument
(
"-s"
,
dest
=
"stretch"
,
type
=
int
,
default
=
2
,
parser_make
.
add_argument
(
"-s"
,
dest
=
"stretch"
,
type
=
int
,
default
=
2
,
help
=
"maximum mononucleotide stretch length"
)
parser_makebc
.
add_argument
(
"-d"
,
dest
=
"distance"
,
type
=
int
,
default
=
3
,
help
=
"minimum distance between the barcodes"
)
parser_test
=
subparsers
.
add_parser
(
"test"
,
parents
=
[
input_parser
,
distance_parser
],
description
=
docSplit
(
testBarcodes
))
args
=
parser
.
parse_args
()
if
args
.
subcommand
==
"make
bc
"
:
if
args
.
subcommand
==
"make"
:
args
.
OUTPUT
.
write
(
"
\n
"
.
join
(
barcode
(
args
.
length
,
args
.
stretch
,
args
.
distance
)))
if
args
.
subcommand
==
"test"
:
print
"%s barcodes violate the distance contraint."
%
testBarcodes
(
map
(
lambda
x
:
x
.
strip
(),
args
.
INPUT
.
readlines
()),
args
.
distance
)
#main
if
__name__
==
"__main__"
:
...
...
setup.py
View file @
1fa761af
...
...
@@ -5,7 +5,7 @@ if sys.version_info < (2, 6):
raise
Exception
(
'barcode requires Python 2.6 or higher.'
)
# Todo: How does this play with pip freeze requirement files?
requires
=
[
'Levenshtein'
]
requires
=
[
'
python-
Levenshtein'
]
# Python 2.6 does not include the argparse module.
try
:
...
...
Write
Preview
Supports
Markdown
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