def test_sniffer(self): output = romanesco.convert( "table", { "format": "csv", "url": "file://" + os.path.join("data", "test.csv") }, {"format": "rows"} ) self.assertEqual(len(output["data"]["fields"]), 32) self.assertEqual(output["data"]["fields"][:3], [ "FACILITY", "ADDRESS", "DATE OF INSPECTION" ]) self.assertEqual(len(output["data"]["rows"]), 14) flu = romanesco.load(os.path.join( self.analysis_path, "xdata", "flu.json")) output = romanesco.run( flu, inputs={}, outputs={"data": {"type": "table", "format": "rows"}} ) self.assertEqual(output["data"]["data"]["fields"][:3], [ "Date", "United States", "Alabama" ])
def test_pgls(self): pgls = romanesco.load(os.path.join(self.arbor_path, "pgls.json")) tree_file = os.path.join("data", "anolis.phy") table_file = os.path.join("data", "anolisDataAppended.csv") romanesco.run( pgls, { "tree": { "format": "newick", "url": "file://" + tree_file }, "table": { "format": "csv", "url": "file://" + table_file }, "correlation": { "format": "text", "data": "BM" }, "ind_variable": { "format": "text", "data": "SVL" }, "dep_variable": { "format": "text", "data": "PCI_limbs" } })
def package_analyses(search_paths, output_dir): if not os.path.exists(output_dir): os.mkdir(output_dir) for path in search_paths: for filename in glob.glob(os.path.join(path, "*.json")): analysis = romanesco.load(filename) with open(os.path.join(output_dir, os.path.basename(filename)), 'w') as f: json.dump(analysis, f)
def test_pgls(self): pgls = romanesco.load(os.path.join(self.arbor_path, "pgls.json")) tree_file = os.path.join("data", "anolis.phy") table_file = os.path.join("data", "anolisDataAppended.csv") romanesco.run( pgls, { "tree": {"format": "newick", "url": "file://" + tree_file}, "table": {"format": "csv", "url": "file://" + table_file}, "correlation": {"format": "text", "data": "BM"}, "ind_variable": {"format": "text", "data": "SVL"}, "dep_variable": {"format": "text", "data": "PCI_limbs"} } )
def test_cont2disc(self): cont2disc = romanesco.load( os.path.join(self.arbor_path, "continuous_to_discrete.json")) table_file = os.path.join("data", "anolisDataAppended.csv") romanesco.run( cont2disc, { "table": {"format": "csv", "url": "file://" + table_file}, "column": {"format": "text", "data": "SVL"}, "thresh": {"format": "number", "data": 3.5} }, { "newtable": {"format": "rows"} } )
def import_analyses(client, analyses_path): # First get the minerva analysis folder minerva_analyses_folder = client.get('/minerva_analysis/folder') if not minerva_analyses_folder['folder']: minerva_analyses_folder = client.post('/minerva_analysis/folder') minerva_analyses_folder = minerva_analyses_folder['folder'] # Note: this will clobber any analyses that have the same name items = {v['name']: v for v in client.listItem(minerva_analyses_folder['_id'])} # look for specific analysis subfolders # e.g. analyses/bsve for analysis_subfolder in os.listdir(analyses_path): analysis_path = os.path.join(analyses_path, analysis_subfolder) # If there is an analysis.json, it is a Romanesco analysis romanesco_analysis = os.path.join(analysis_path, 'analysis.json') metadata = {} minerva_metadata = {} if os.path.exists(romanesco_analysis): analysis = romanesco.load(romanesco_analysis) analysis_name = analysis['name'] metadata['analysis'] = analysis # set the analysis_type based on folder name minerva_metadata['analysis_type'] = analysis_path.split('/')[-1] minerva_metadata['analysis_name'] = analysis_name else: # look for a minerva.json minerva_metadata_path = os.path.join(analysis_path, 'minerva.json') with open(minerva_metadata_path) as minerva_metadata_file: minerva_metadata = json.load(minerva_metadata_file) analysis_name = minerva_metadata['analysis_name'] if analysis_name not in items.keys(): items[analysis_name] = client.createItem(minerva_analyses_folder['_id'], analysis_name, analysis_name) analysis_item = items[analysis_name] # Set the minerva metadata # add the item_id as the analysis_id minerva_metadata['analysis_id'] = analysis_item['_id'] metadata['minerva'] = minerva_metadata client.addMetadataToItem(analysis_item['_id'], metadata)
def import_analyses(client, analyses_path): # First get the minerva analysis folder minerva_analyses_folder = client.get('/minerva_analysis/folder') if not minerva_analyses_folder['folder']: minerva_analyses_folder = client.post('/minerva_analysis/folder') minerva_analyses_folder = minerva_analyses_folder['folder'] # look for specific analysis subfolders # e.g. analyses/bsve for analysis_subfolder in os.listdir(analyses_path): analysis_path = os.path.join(analyses_path, analysis_subfolder) # If there is an analysis.json, it is a Romanesco analysis romanesco_analysis = os.path.join(analysis_path, 'analysis.json') metadata = {} minerva_metadata = {} if os.path.exists(romanesco_analysis): analysis = romanesco.load(romanesco_analysis) analysis_name = analysis['name'] metadata['analysis'] = analysis # set the analysis_type based on folder name minerva_metadata['analysis_type'] = analysis_path.split('/')[-1] minerva_metadata['analysis_name'] = analysis_name else: # look for a minerva.json minerva_metadata_path = os.path.join(analysis_path, 'minerva.json') with open(minerva_metadata_path) as minerva_metadata_file: minerva_metadata = json.load(minerva_metadata_file) analysis_name = minerva_metadata['analysis_name'] # See if we already have an analysis with that name items = client.listItem(minerva_analyses_folder['_id'], analysis_name) if len(items) == 0: analysis_item = client.createItem(minerva_analyses_folder['_id'], analysis_name, analysis_name) elif len(items) > 1: raise Exception('More than one item found with name: %s' % analysis_name) else: analysis_item = items[0] # Set the minerva metadata # add the item_id as the analysis_id minerva_metadata['analysis_id'] = analysis_item['_id'] metadata['minerva'] = minerva_metadata client.addMetadataToItem(analysis_item['_id'], metadata)
def test_mammal_tree(self): mammal = romanesco.load( os.path.join("data", "Mammal tree extraction.json")) romanesco.run( mammal, { "table": { "format": "csv", "url": "file://" + os.path.join("data", "mammal_lnMass_tiny.csv") }, "outRowCount": {"format": "number", "data": 19} }, { "tree": {"format": "nested"} } )
def test_mammal_tree(self): mammal = romanesco.load( os.path.join("data", "Mammal tree extraction.json")) romanesco.run( mammal, { "table": { "format": "csv", "url": "file://" + os.path.join("data", "mammal_lnMass_tiny.csv") }, "outRowCount": { "format": "number", "data": 19 } }, {"tree": { "format": "nested" }})
def test_cont2disc(self): cont2disc = romanesco.load( os.path.join(self.arbor_path, "continuous_to_discrete.json")) table_file = os.path.join("data", "anolisDataAppended.csv") romanesco.run( cont2disc, { "table": { "format": "csv", "url": "file://" + table_file }, "column": { "format": "text", "data": "SVL" }, "thresh": { "format": "number", "data": 3.5 } }, {"newtable": { "format": "rows" }})
def test_sniffer(self): output = romanesco.convert( "table", { "format": "csv", "url": "file://" + os.path.join("data", "test.csv") }, {"format": "rows"}) self.assertEqual(len(output["data"]["fields"]), 32) self.assertEqual(output["data"]["fields"][:3], ["FACILITY", "ADDRESS", "DATE OF INSPECTION"]) self.assertEqual(len(output["data"]["rows"]), 14) flu = romanesco.load( os.path.join(self.analysis_path, "xdata", "flu.json")) output = romanesco.run( flu, inputs={}, outputs={"data": { "type": "table", "format": "rows" }}) self.assertEqual(output["data"]["data"]["fields"][:3], ["Date", "United States", "Alabama"])