def test_parse_config_with_minimum_elements(self):
     with tempfile.NamedTemporaryFile(mode="w") as config:
         config.write(
             '<?xml version="1.0" encoding="UTF-8"?>'
             "<NaspInputData>"
             "  <Options>"
             "    <Reference></Reference>"
             "    <Filters></Filters>"
             "  </Options>"
             "  <Files></Files>"
             "  <ExternalApplications>"
             "      <Samtools></Samtools>"
             "      <MatrixGenerator></MatrixGenerator>"
             "  </ExternalApplications>"
             "</NaspInputData>"
         )
         config.seek(0)
         expected = {
             "run_name": None,
             "output_folder": None,
             "reads": [],
             "vcfs": [],
             "matrix_generator": ("MatrixGenerator", None, "", {}),
             "aligners": [],
             "reference": (None, None),
             "snpcallers": [],
             "job_submitter": None,
             "alignments": [],
             "samtools": ("Samtools", None, "", {}),
             "assemblies": [],
             "find_dups": None,
         }
         self.assertDictEqual(expected, configuration_parser.parse_config(config.name))
Example #2
0
 def test_parse_config_with_minimum_elements(self):
     with tempfile.NamedTemporaryFile(mode="w") as config:
         config.write('<?xml version="1.0" encoding="UTF-8"?>'
                      '<NaspInputData>'
                      '  <Options>'
                      '    <Reference></Reference>'
                      '    <Filters></Filters>'
                      '  </Options>'
                      '  <Files></Files>'
                      '  <ExternalApplications>'
                      '      <Samtools></Samtools>'
                      '      <MatrixGenerator></MatrixGenerator>'
                      '  </ExternalApplications>'
                      '</NaspInputData>')
         config.seek(0)
         expected = {
             'run_name': None,
             'output_folder': None,
             'reads': [],
             'vcfs': [],
             'matrix_generator': ('MatrixGenerator', None, '', {}),
             'aligners': [],
             'reference': (None, None),
             'snpcallers': [],
             'job_submitter': None,
             'alignments': [],
             'samtools': ('Samtools', None, '', {}),
             'assemblies': [],
             'find_dups': None
         }
         self.assertDictEqual(expected, configuration_parser.parse_config(config.name))
def test_it_reads_the_same_data_it_writes(self):
    with TemporaryDirectory(suffix="fjdksnfsdk") as tmpdir:
        self.expected["output_folder"] = tmpdir

        configuration_parser.write_config(self.expected)

        observed = configuration_parser.parse_config(os.path.join(tmpdir, "test_run_name-config.xml"))

        self.assertDictEqual(self.expected, observed)
Example #4
0
def test_it_reads_the_same_data_it_writes(self):
    with TemporaryDirectory(suffix='fjdksnfsdk') as tmpdir:
        self.expected['output_folder'] = tmpdir

        configuration_parser.write_config(self.expected)

        observed = configuration_parser.parse_config(os.path.join(tmpdir, 'test_run_name-config.xml'))

        self.assertDictEqual(self.expected, observed)
def test_it_stores_vcfs(self):
    with TemporaryDirectory() as tmpdir:
        self.expected["output_folder"] = tmpdir

        self.expected["vcfs"] = [("foo", "bar")]

        configuration_parser.write_config(self.expected)

        observed = configuration_parser.parse_config(os.path.join(tmpdir, "test_run_name-config.xml"))

        self.assertDictEqual(self.expected, observed)
def test_it_should_warn_when_the_read_element_does_not_contain_read_files(self):
    with TemporaryDirectory() as tmpdir:
        self.expected["output_folder"] = tmpdir

        self.expected["reads"] = [("not_a_valid_read_file", "", "")]

        configuration_parser.write_config(self.expected)

        observed = configuration_parser.parse_config(os.path.join(tmpdir, "test_run_name-config.xml"))

        self.assertDictEqual(self.expected, observed)
Example #7
0
def test_it_stores_vcfs(self):
    with TemporaryDirectory() as tmpdir:
        self.expected['output_folder'] = tmpdir

        self.expected['vcfs'] = [
            ('foo', 'bar')
        ]

        configuration_parser.write_config(self.expected)

        observed = configuration_parser.parse_config(os.path.join(tmpdir, 'test_run_name-config.xml'))

        self.assertDictEqual(self.expected, observed)
Example #8
0
def test_it_should_warn_when_the_read_element_does_not_contain_read_files(self):
    with TemporaryDirectory() as tmpdir:
        self.expected['output_folder'] = tmpdir

        self.expected['reads'] = [
            ('not_a_valid_read_file', '', '')
        ]

        configuration_parser.write_config(self.expected)

        observed = configuration_parser.parse_config(os.path.join(tmpdir, 'test_run_name-config.xml'))

        self.assertDictEqual(self.expected, observed)
Example #9
0
def main():
    import sys
    import nasp.dispatcher as dispatcher
    import nasp.configuration_parser as configuration_parser

    # This is hack to forward commands to gonasp
    if len(sys.argv) > 1 and sys.argv[1] in [
            'help', 'duplicates', 'frankenfasta', 'matrix', 'export'
    ]:
        if sys.argv[1] == 'help' or any(
                arg in ['-h', '-help', '--help']
                for arg in sys.argv) or len(sys.argv) < 3:
            print(
                "Requesting nasp internal command usage message. Enter 'nasp --help' for the nasp pipeline usage message."
            )
            print(
                "Unlike the nasp pipeline, these commands will not be automatically submitted to your job manager"
            )
        import subprocess
        subprocess.call([gonasp_path()] + sys.argv[1:])
        return

    commandline_args = _parse_args()
    if commandline_args.config:
        configuration = configuration_parser.parse_config(
            commandline_args.config)
        output_folder = configuration["output_folder"]
        if os.path.exists(output_folder):
            response = input(
                "\nOutput folder %s already exists!\nFiles in it may be overwritten!\nShould we continue anyway [N]? "
                % output_folder)
            if not re.match('^[Yy]', response):
                print("Operation cancelled!")
                quit()
        else:
            os.makedirs(output_folder)
        logfile = os.path.join(output_folder, "runlog.txt")
        logging.basicConfig(level=logging.DEBUG,
                            format='%(asctime)s %(levelname)-8s %(message)s',
                            datefmt='%m/%d/%Y %H:%M:%S',
                            filename=logfile,
                            filemode='w')
    else:
        configuration = _get_user_input(commandline_args.reference_fasta,
                                        commandline_args.output_folder)
    configuration_parser.write_config(configuration)
    dispatcher.begin(configuration)
Example #10
0
def main():
    import sys
    import nasp.dispatcher as dispatcher
    import nasp.configuration_parser as configuration_parser

    # This is hack to forward commands to gonasp
    if len(sys.argv) > 1 and sys.argv[1] in ['help', 'duplicates', 'frankenfasta', 'matrix', 'export']:
        if sys.argv[1] == 'help' or any(arg in ['-h', '-help', '--help'] for arg in sys.argv) or len(sys.argv) < 3:
            print("Requesting nasp internal command usage message. Enter 'nasp --help' for the nasp pipeline usage message.")
            print("Unlike the nasp pipeline, these commands will not be automatically submitted to your job manager")
        import subprocess
        subprocess.call([gonasp_path()] + sys.argv[1:])
        return

    commandline_args = _parse_args()
    if commandline_args.config:
        configuration = configuration_parser.parse_config(commandline_args.config)
        output_folder = configuration["output_folder"]
        if os.path.exists(output_folder):
            response = input(
                "\nOutput folder %s already exists!\nFiles in it may be overwritten!\nShould we continue anyway [N]? " % output_folder)
            if not re.match('^[Yy]', response):
                print("Operation cancelled!")
                quit()
        else:
            os.makedirs(output_folder)
        logfile = os.path.join(output_folder, "runlog.txt")
        logging.basicConfig(level=logging.DEBUG,
                            format='%(asctime)s %(levelname)-8s %(message)s',
                            datefmt='%m/%d/%Y %H:%M:%S',
                            filename=logfile,
                            filemode='w')
    else:
        configuration = _get_user_input(commandline_args.reference_fasta, commandline_args.output_folder)
    configuration_parser.write_config(configuration)
    dispatcher.begin(configuration)
Example #11
0
def main():
    import nasp.configuration_parser as configuration_parser

    commandline_args = _parse_args()
    configuration = configuration_parser.parse_config(commandline_args.config)
    begin(configuration)
Example #12
0
def main():
    import nasp.configuration_parser as configuration_parser

    commandline_args = _parse_args()
    configuration = configuration_parser.parse_config(commandline_args.config)
    begin(configuration)