diff --git a/core/pymod/core/pm3argparse.py b/core/pymod/core/pm3argparse.py index 8233e2893bc566196825b7768beb9f6491912058..a606c81f10bc99671110aebd83a4131087d85c3f 100644 --- a/core/pymod/core/pm3argparse.py +++ b/core/pymod/core/pm3argparse.py @@ -213,6 +213,24 @@ class PM3OptionsNamespace(object): if 'ALIGNMENT' in activated: 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): #pylint: disable=no-member #pylint: disable=attribute-defined-outside-init @@ -223,16 +241,7 @@ class PM3OptionsNamespace(object): self.alignments = seq.AlignmentList() if self.fasta: for src in self.fasta: - if src[0].startswith('trg:'): - 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) + trgname, seqfile = self._FetchAlnFromFastaOpt(src) if not len(trgname): helper.MsgErrorAndExit("'--fasta' requires argument "+ "'trg:' defining the "+ diff --git a/core/tests/test_pm3argparse.py b/core/tests/test_pm3argparse.py index cc2f4aed3cc328725c723ad572741c78e5d3aaa9..10ad2777660410d48370132ab598bd7d716faee1 100644 --- a/core/tests/test_pm3argparse.py +++ b/core/tests/test_pm3argparse.py @@ -87,7 +87,7 @@ class PM3ArgParseTests(unittest.TestCase): parser.Parse(['--fasta', 'foo', 'bar']) self.assertEqual(ecd.exception.code, 11) self.assertEqual(self.log.messages['ERROR'][0], - "'--fasta' requires one "+ + "'--fasta foo bar' requires one "+ "argument prefixed with 'trg:' marking the target "+ "sequence name")