Skip to content
Snippets Groups Projects
Commit 46805eb0 authored by Bienchen's avatar Bienchen
Browse files

Simplifying handling fasta

parent 0fe4afca
No related branches found
No related tags found
No related merge requests found
...@@ -213,6 +213,24 @@ class PM3OptionsNamespace(object): ...@@ -213,6 +213,24 @@ class PM3OptionsNamespace(object):
if 'ALIGNMENT' in activated: if 'ALIGNMENT' in activated:
self._PostProcessAlignment() self._PostProcessAlignment()
def _FetchAlnFromFastaOpt(self, argstr):
"""
Dissasemble an argument to '--fasta' into an alignment and return.
"""
# get which element of the argument list is the target identifier and
# which one is the filename
if argstr[0].startswith('trg:'):
trgname = argstr[0][4:]
seqfile = argstr[1]
elif argstr[1].startswith('trg:'):
trgname = argstr[1][4:]
seqfile = argstr[0]
else:
helper.MsgErrorAndExit("'--fasta %s' requires " % ' '.join(argstr)+
"one argument prefixed with 'trg:' marking "+
"the target sequence name", 11)
return trgname, seqfile
def _PostProcessAlignment(self): def _PostProcessAlignment(self):
#pylint: disable=no-member #pylint: disable=no-member
#pylint: disable=attribute-defined-outside-init #pylint: disable=attribute-defined-outside-init
...@@ -223,16 +241,7 @@ class PM3OptionsNamespace(object): ...@@ -223,16 +241,7 @@ class PM3OptionsNamespace(object):
self.alignments = seq.AlignmentList() self.alignments = seq.AlignmentList()
if self.fasta: if self.fasta:
for src in self.fasta: for src in self.fasta:
if src[0].startswith('trg:'): trgname, seqfile = self._FetchAlnFromFastaOpt(src)
trgname = src[0][4:]
seqfile = src[1]
elif src[1].startswith('trg:'):
trgname = src[1][4:]
seqfile = src[0]
else:
helper.MsgErrorAndExit("'--fasta' requires one argument "+
"prefixed with 'trg:' marking the "+
"target sequence name", 11)
if not len(trgname): if not len(trgname):
helper.MsgErrorAndExit("'--fasta' requires argument "+ helper.MsgErrorAndExit("'--fasta' requires argument "+
"'trg:' defining the "+ "'trg:' defining the "+
......
...@@ -87,7 +87,7 @@ class PM3ArgParseTests(unittest.TestCase): ...@@ -87,7 +87,7 @@ class PM3ArgParseTests(unittest.TestCase):
parser.Parse(['--fasta', 'foo', 'bar']) parser.Parse(['--fasta', 'foo', 'bar'])
self.assertEqual(ecd.exception.code, 11) self.assertEqual(ecd.exception.code, 11)
self.assertEqual(self.log.messages['ERROR'][0], self.assertEqual(self.log.messages['ERROR'][0],
"'--fasta' requires one "+ "'--fasta foo bar' requires one "+
"argument prefixed with 'trg:' marking the target "+ "argument prefixed with 'trg:' marking the target "+
"sequence name") "sequence name")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment