Esempio n. 1
0
def register_metadata(metadata_file, config):
    """Read an SRA project file and register metadata in sml_config. Will
    issue a warning if file does not exists.

    Args: 
      metadata - file name
      config - configuration to update
    """
    metadata_list = []
    import sys
    if metadata_file in sys.argv:
        return metadata_list
    try:
        with open(metadata_file, "r") as fh:
            reader = csv.DictReader(fh.readlines())
        metadata_list = [row for row in reader]
        run2sample = {row["Run"]:row["SampleName"] for row in metadata_list}
        config = update_snakemake_config(config, {
            'bio.ngs.settings' : {'sampleinfo' : metadata_file},
            'bio.ngs.tools.sratools': {'_datadir': os.path.dirname(metadata_file),
                                       '_run2sample' : run2sample,
                                       '_metadata' : metadata_list}})
    except Exception:
        raise Exception("""

        no metadata file '{metadata}' found

        please initiate analysis by running 'snakemake {metadata}'

        """.format(metadata=metadata_file))

    return config
Esempio n. 2
0
 def test_update_sml_config_with_cfg_nested_missing_base_config(self):
     """Test updating sml config where value for section is string in custom config and BaseConfig in default"""
     cfg = BaseConfig({
         'bar' : BaseConfig({
             'bar' : 'test'
             })
         })
     cfg = update_snakemake_config(cfg, self.default_nested)
Esempio n. 3
0
    def test_update_sml_config_with_default(self):
        """Test updating a configuration object skipping values that are
        already in use. Overriding dict.update will not do as its original
        intedend behaviour is needed.

        What is the desired behaviour?

        1. In Snakefile user modifies a custom configuration object
        2. Relevant include files are loaded with default settings.

        3. Default settings need to be updated with custom config at
           once so that custom changes are reflected in rules (is this
           true?)
        """
        cfg = update_snakemake_config(self.cfg, self.default)
        self.assertDictEqual(cfg, {'bar': {'bar': 'foo', 'foo': 'customfoo'}, 'foo': 'bar'})
Esempio n. 4
0
 def test_update_sml_config_with_function(self):
     """Test setting an sml_config object with a function that requires a parameter"""
     cfg = BaseConfig(self.cfg)
     cfg = update_snakemake_config(cfg, {'foo':lambda x: x})
     self.assertEqual(str(type(dict(cfg)['foo'])), "<class 'function'>")
Esempio n. 5
0
 def test_get_sml_config_section(self):
     """Test getting a config section section"""
     cfg = BaseConfig(self.cfg_nested)
     cfg = update_snakemake_config(cfg, self.default_nested)
     self.assertDictEqual(cfg['bar'], {'bar': {'bar': 'customfoo', 'foo': 'bar'}, 'foo': 'foobar'})
Esempio n. 6
0
 def test_update_sml_config_with_string(self):
     cfg = "foo"
     update_snakemake_config(cfg, {})
Esempio n. 7
0
 def test_update_sml_config_with_both_nested(self):
     """Test updating a configuration object where both are nested. Note that in this example  self.cfg_nested has a key (section) not defined in default so a warning should be raised. In other words, at a given level, if default is a BaseConfig, the keys in config should be a subset of keys in default."""
     cfg = update_snakemake_config(self.cfg_nested, self.default_nested)
     self.assertDictEqual(cfg, {'foo': 'bar', 'bar': {'foo': 'foobar', 'bar': {'foo': 'bar', 'bar': 'customfoo'}}})
Esempio n. 8
0
 def test_update_sml_config_with_default_nested(self):
     cfg = update_snakemake_config(self.cfg, self.default_nested)
     self.assertDictEqual(cfg, {'foo': 'bar', 'bar': {'foo': 'customfoo', 'bar': {'foo': 'bar'}}})
Esempio n. 9
0
 def test_update_sml_config_from_init(self):
     """Test initializing the sml config object from an init"""
     cfg = BaseConfig(self.cfg)
     cfg = update_snakemake_config(cfg, self.cfg_nested)
     self.assertDictEqual(cfg, {'bar': {'bar': {'bar': 'customfoo'}, 'foo': 'customfoo'}})