def test_json2isatab_convert_sample_pool_assay_table(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'TEST-ISA-sample-pool.json')), self._tmp_dir, validate_first=False) self.assertTrue(assert_tab_content_equal( open(os.path.join(self._tmp_dir, 'a_test-template3-splitting_transcription_profiling_DNA_microarray.txt')), open(os.path.join(self._tab_data_dir, 'TEST-ISA-sample-pool', 'a_test-template3-splitting_transcription_profiling_DNA_microarray.txt'))))
def test_json2isatab_convert_source_split_study_table(self): with open(os.path.join(self._json_data_dir, 'TEST-ISA-source-split.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir, validate_first=False) with open(os.path.join(self._tmp_dir, 's_TEST-Template1-Splitting.txt')) as out_fp: with open(os.path.join(self._tab_data_dir, 'TEST-ISA-source-split', 's_TEST-Template1-Splitting.txt')) \ as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_isatab2json_2way_convert_sample_pool(self): test_case = 'TEST-ISA-sample-pool' test_json = open(os.path.join(self._json_data_dir, test_case + '.json')) json2isatab.convert(test_json, self._tmp_dir) test_json.seek(0) # reset pointer expected_json = json.load(test_json) actual_json = isatab2json.convert(self._tmp_dir) self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
def test_json2isatab_isatab2json_2way_convert_sample_pool(self): test_case = 'TEST-ISA-sample-pool' test_json = open(os.path.join(self._json_data_dir, test_case + '.json')) json2isatab.convert(test_json, self._tmp_dir, validate_first=False) test_json.seek(0) # reset pointer expected_json = json.load(test_json) actual_json = isatab2json.convert(self._tmp_dir, validate_first=False) self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
def test_json2isatab_convert_bii_i_1_study2_table(self): with open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir) with open(os.path.join(self._tmp_dir, 's_BII-S-2.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-I-1', 's_BII-S-2.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_s_3_study_table(self): with open(os.path.join(self._json_data_dir, 'BII-S-3', 'BII-S-3.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir, validate_first=False) with open(os.path.join(self._tmp_dir, 's_BII-S-3.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-S-3', 's_BII-S-3.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_s_7_assay_table_Gx(self): with open(os.path.join(self._json_data_dir, 'BII-S-7', 'BII-S-7.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir, validate_first=False) with open(os.path.join(self._tmp_dir, 'a_matteo-assay-Gx.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-S-7', 'a_matteo-assay-Gx.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_i_1_study2_table(self): json2isatab.convert( open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) self.assertTrue( assert_tab_content_equal( open(os.path.join(self._tmp_dir, 's_BII-S-2.txt')), open( os.path.join(self._tab_data_dir, 'BII-I-1', 's_BII-S-2.txt'))))
def test_json2isatab_convert_bii_i_1_assay_table_metabolome(self): with open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir) with open(os.path.join(self._tmp_dir, 'a_metabolome.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-I-1_written_by_isatab', 'a_metabolome.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_s_7_assay_table_Gx(self): json2isatab.convert(open( os.path.join(self._json_data_dir, 'BII-S-7', 'BII-S-7.json')), self._tmp_dir, validate_first=False) self.assertTrue( assert_tab_content_equal( open(os.path.join(self._tmp_dir, 'a_matteo-assay-Gx.txt')), open( os.path.join(self._tab_data_dir, 'BII-S-7', 'a_matteo-assay-Gx.txt'))))
def test_json2isatab_convert_bii_s_3_study_table(self): json2isatab.convert(open( os.path.join(self._json_data_dir, 'BII-S-3', 'BII-S-3.json')), self._tmp_dir, validate_first=False) self.assertTrue( assert_tab_content_equal( open(os.path.join(self._tmp_dir, 's_BII-S-3.txt')), open( os.path.join(self._tab_data_dir, 'BII-S-3', 's_BII-S-3.txt'))))
def test_json2isatab_convert_bii_i_1_assay_table_metabolome(self): json2isatab.convert( open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) self.assertTrue( assert_tab_content_equal( open(os.path.join(self._tmp_dir, 'a_metabolome.txt')), open( os.path.join(self._tab_data_dir, 'BII-I-1_written_by_isatab', 'a_metabolome.txt'))))
def test_json2isatab_convert_bii_i_1_investigation(self): json2isatab.convert( open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) self.assertTrue( assert_tab_content_equal( open(os.path.join(self._tmp_dir, 'i_investigation.txt')), open( os.path.join(self._tab_data_dir, 'BII-I-1_written_by_isatab', 'i_investigation.txt'))))
def convert(json_fp, path, config_dir=None): """ Converter for ISA JSON to SRA. :param json_fp: File pointer to ISA JSON input :param path: Directory for output to be written :param config_dir: path to JSON configuration """ from isatools.convert import json2isatab, isatab2sra json2isatab.convert(json_fp=json_fp, path=path, config_dir=config_dir) isatab2sra.create_sra(path, path) for f in glob(path + '/*.txt'): # remove generated isatab files os.remove(f)
def test_json2isatab_convert_bii_i_1_assay_table_proteome(self): # FIXME: Same duplication problem as above with open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir) with open(os.path.join(self._tmp_dir, 'a_proteome.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-I-1_written_by_isatab', 'a_proteome.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_i_1_assay_table_proteome( self): # FIXME: Same duplication problem as above json2isatab.convert( open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) self.assertTrue( assert_tab_content_equal( open(os.path.join(self._tmp_dir, 'a_proteome.txt')), open( os.path.join(self._tab_data_dir, 'BII-I-1_written_by_isatab', 'a_proteome.txt'))))
def test_json2isatab_convert_bii_s_3_investigation(self): with open(os.path.join(self._json_data_dir, 'BII-S-3', 'BII-S-3.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir, i_file_name='i_gilbert.txt', validate_first=False) with open(os.path.join(self._tmp_dir, 'i_gilbert.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-S-3', 'i_gilbert.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_s_3_investigation(self): json2isatab.convert(open( os.path.join(self._json_data_dir, 'BII-S-3', 'BII-S-3.json')), self._tmp_dir, i_file_name='i_gilbert.txt', validate_first=False) self.assertTrue( assert_tab_content_equal( open(os.path.join(self._tmp_dir, 'i_gilbert.txt')), open( os.path.join(self._tab_data_dir, 'BII-S-3', 'i_gilbert.txt'))))
def test_json2isatab_convert_bii_i_1_assay_table_transcriptome(self): # FIXME: Has inserted Protocol REFs but Array Design REF, Scan Name, Factor Values with open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir) with open(os.path.join(self._tmp_dir, 'a_transcriptome.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-I-1_written_by_isatab', 'a_transcriptome.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_i_1_assay_table_microarray(self): # FIXME: ArrayExpress comments come out twice (on Assay AND Derived Data File output from assay), # missing Data Transformation Name and Factor Values with open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir) with open(os.path.join(self._tmp_dir, 'a_microarray.txt')) as out_fp: with open( os.path.join(self._tab_data_dir, 'BII-I-1_written_by_isatab', 'a_microarray.txt')) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_sample_pool_study_table(self): json2isatab.convert(open( os.path.join(self._json_data_dir, 'TEST-ISA-sample-pool.json')), self._tmp_dir, validate_first=False) self.assertTrue( assert_tab_content_equal( open( os.path.join(self._tmp_dir, 's_TEST-Template3-Splitting.txt')), open( os.path.join(self._tab_data_dir, 'TEST-ISA-sample-pool', 's_TEST-Template3-Splitting.txt'))))
def test_json2isatab_isatab2json_2way_convert_source_split(self): test_case = 'TEST-ISA-source-split' test_json = open(os.path.join(self._json_data_dir, test_case + '.json')) json2isatab.convert(test_json, self._tmp_dir, validate_first=False) test_json.seek(0) # reset pointer expected_json = json.load(test_json) actual_json = isatab2json.convert(self._tmp_dir, validate_first=False) self.assertTrue(utils.assert_json_equal(expected_json, actual_json)) # def test_json2isatab_isatab2json_2way_convert_bii_i_1(self): # # FIXME: Get error in isatab2json.createUnitsCategories # # json_item.update(self.createOntologyAnnotation(value_attributes.Unit, value_attributes.Term_Source_REF, value_attributes.Term_Accession_Number)) # # AttributeError: 'Attrs' object has no attribute 'Term_Source_REF' # # Are Units always OntologyAnnotations? (i.e. Unit column alway accompanied by Term Accession and # # Term Source REF? # test_case = 'BII-I-1' # test_json = open(os.path.join(self._json_data_dir, test_case, test_case + '.json')) # json2isatab.convert(test_json, self._tmp_dir) # test_json.seek(0) # reset pointer # expected_json = json.load(test_json) # actual_json = isatab2json.convert(self._tmp_dir) # self.assertTrue(utils.assert_json_equal(expected_json, actual_json)) # # def test_json2isatab_isatab2json_2way_convert_bii_s_3(self): # # FIXME: Get error in isatab2json.createUnitsCategories # # json_item.update(self.createOntologyAnnotation(value_attributes.Unit, value_attributes.Term_Source_REF, value_attributes.Term_Accession_Number)) # # AttributeError: 'Attrs' object has no attribute 'Term_Source_REF' # # Are Units always OntologyAnnotations? (i.e. Unit column alway accompanied by Term Accession and # # Term Source REF? If so, related to below bii_s_7 error # test_case = 'BII-S-3' # test_json = open(os.path.join(self._json_data_dir, test_case, test_case + '.json')) # json2isatab.convert(test_json, self._tmp_dir) # test_json.seek(0) # reset pointer # expected_json = json.load(test_json) # actual_json = isatab2json.convert(self._tmp_dir) # self.assertTrue(utils.assert_json_equal(expected_json, actual_json)) # # def test_json2isatab_isatab2json_2way_convert_bii_s_7(self): # # FIXME: It reports a big diff because when doing json2isatab, if Term Accession and Term Source REF columns # # are empty it strips them out. When going back from isatab2json, it converts as string and not # # OntologyAnnotation since there is no extra info to be able to cast back to original # test_case = 'BII-S-7' # test_json = open(os.path.join(self._json_data_dir, test_case, test_case + '.json')) # json2isatab.convert(test_json, self._tmp_dir) # test_json.seek(0) # reset pointer # expected_json = json.load(test_json) # actual_json = isatab2json.convert(self._tmp_dir) # self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
def test_json2isatab_isatab2json_2way_convert_source_split(self): test_case = 'TEST-ISA-source-split' test_json = open(os.path.join(self._json_data_dir, test_case + '.json')) json2isatab.convert(test_json, self._tmp_dir) test_json.seek(0) # reset pointer expected_json = json.load(test_json) actual_json = isatab2json.convert(self._tmp_dir) self.assertTrue(utils.assert_json_equal(expected_json, actual_json)) # def test_json2isatab_isatab2json_2way_convert_bii_i_1(self): # # FIXME: Get error in isatab2json.createUnitsCategories # # json_item.update(self.createOntologyAnnotation(value_attributes.Unit, value_attributes.Term_Source_REF, value_attributes.Term_Accession_Number)) # # AttributeError: 'Attrs' object has no attribute 'Term_Source_REF' # # Are Units always OntologyAnnotations? (i.e. Unit column alway accompanied by Term Accession and # # Term Source REF? # test_case = 'BII-I-1' # test_json = open(os.path.join(self._json_data_dir, test_case, test_case + '.json')) # json2isatab.convert(test_json, self._tmp_dir) # test_json.seek(0) # reset pointer # expected_json = json.load(test_json) # actual_json = isatab2json.convert(self._tmp_dir) # self.assertTrue(utils.assert_json_equal(expected_json, actual_json)) # # def test_json2isatab_isatab2json_2way_convert_bii_s_3(self): # # FIXME: Get error in isatab2json.createUnitsCategories # # json_item.update(self.createOntologyAnnotation(value_attributes.Unit, value_attributes.Term_Source_REF, value_attributes.Term_Accession_Number)) # # AttributeError: 'Attrs' object has no attribute 'Term_Source_REF' # # Are Units always OntologyAnnotations? (i.e. Unit column alway accompanied by Term Accession and # # Term Source REF? If so, related to below bii_s_7 error # test_case = 'BII-S-3' # test_json = open(os.path.join(self._json_data_dir, test_case, test_case + '.json')) # json2isatab.convert(test_json, self._tmp_dir) # test_json.seek(0) # reset pointer # expected_json = json.load(test_json) # actual_json = isatab2json.convert(self._tmp_dir) # self.assertTrue(utils.assert_json_equal(expected_json, actual_json)) # # def test_json2isatab_isatab2json_2way_convert_bii_s_7(self): # # FIXME: It reports a big diff because when doing json2isatab, if Term Accession and Term Source REF columns # # are empty it strips them out. When going back from isatab2json, it converts as string and not # # OntologyAnnotation since there is no extra info to be able to cast back to original # test_case = 'BII-S-7' # test_json = open(os.path.join(self._json_data_dir, test_case, test_case + '.json')) # json2isatab.convert(test_json, self._tmp_dir) # test_json.seek(0) # reset pointer # expected_json = json.load(test_json) # actual_json = isatab2json.convert(self._tmp_dir) # self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
def test_json2isatab_convert_source_split_assay_table(self): with open( os.path.join(self._json_data_dir, 'TEST-ISA-source-split.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir, validate_first=False) with open( os.path.join( self._tmp_dir, 'a_test-template1-splitting_transcription_profiling_DNA_microarray.txt' )) as out_fp: with open( os.path.join( self._tab_data_dir, 'TEST-ISA-source-split', 'a_test-template1-splitting_transcription_profiling_DNA_microarray.txt' )) as reference_fp: self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
def test_json2isatab_convert_bii_s_7_assay_table_Gx(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-S-7', 'BII-S-7.json')), self._tmp_dir) self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'a_matteo-assay-Gx.txt')), open(os.path.join(self._tab_data_dir, 'BII-S-7', 'a_matteo-assay-Gx.txt')))) # def test_json2isatab_convert_bii_i_1_investigation(self): # json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) # self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'i_investigation.txt')), # open(os.path.join(self._tab_data_dir, 'BII-I-1', 'i_investigation.txt')))) # # def test_json2isatab_convert_bii_i_1_study_table(self): # json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) # self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 's_BII-S-1.txt')), # open(os.path.join(self._tab_data_dir, 'BII-I-1', 's_BII-S-1.txt')))) # # def test_json2isatab_convert_bii_i_1_study2_table(self): # json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) # self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 's_BII-S-2.txt')), # open(os.path.join(self._tab_data_dir, 'BII-I-1', 's_BII-S-2.txt')))) # # def test_json2isatab_convert_bii_i_1_assay_table_metabolome(self): # json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) # self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'a_metabolome.txt')), # open(os.path.join(self._tab_data_dir, 'BII-I-1', # 'a_metabolome.txt')))) # # def test_json2isatab_convert_bii_i_1_assay_table_microarray(self): # json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) # self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'a_microarray.txt')), # open(os.path.join(self._tab_data_dir, 'BII-I-1', # 'a_microarray.txt')))) # # def test_json2isatab_convert_bii_i_1_assay_table_proteome(self): # json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) # self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'a_proteome.txt')), # open(os.path.join(self._tab_data_dir, 'BII-I-1', # 'a_proteome.txt')))) # # def test_json2isatab_convert_bii_i_1_assay_table_transcriptome(self): # json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-I-1', 'BII-I-1.json')), self._tmp_dir) # self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'a_transcriptome.txt')), # open(os.path.join(self._tab_data_dir, 'BII-I-1', # 'a_transcriptome.txt'))))
def post(self): response = Response(status=415) if request.mimetype == "application/json": tmp_file = str(uuid.uuid4()) + ".json" tmp_dir = _create_temp_dir() try: # Write request data to file file_path = _write_request_data(request, tmp_dir, tmp_file) if file_path is None: return Response(500) json2isatab.convert(open(file_path), tmp_dir) os.remove(file_path) memf = io.BytesIO() with zipfile.ZipFile(memf, 'w') as zf: for file in os.listdir(tmp_dir): zf.write(os.path.join(tmp_dir, file), file) memf.seek(0) response = send_file(memf, mimetype='application/zip') finally: # cleanup generated directories shutil.rmtree(tmp_dir, ignore_errors=True) return response
import sys import os src_json = sys.argv[1] target_dir = sys.argv[2] try: from isatools.convert import json2isatab except ImportError as e: raise RuntimeError("Could not import isatools package") json2isatab.convert(open(src_json), target_dir)
#!/usr/bin/env python3 import sys import os src_json = sys.argv[1] try: from isatools.convert import json2isatab except ImportError as e: raise RuntimeError('Could not import isatools package') if not os.path.exists(src_json): print('File path to ISA-JSON file \'{}\' does not exist'.format(src_json)) sys.exit(0) with open(src_json, encoding='utf-8') as in_fp: json2isatab.convert( json_fp=in_fp, path=os.path.dirname(src_json), validate_first=False)
def test_json2isatab_validate_first(self): with open(os.path.join(self._json_data_dir, 'BII-S-7', 'BII-S-7.json')) as json_fp: json2isatab.convert(json_fp, self._tmp_dir, validate_first=True)
def test_json2isatab_convert_source_split_study_table(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'TEST-ISA-source-split.json')), self._tmp_dir) self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 's_TEST-Template1-Splitting.txt')), open(os.path.join(self._tab_data_dir, 'TEST-ISA-source-split', 's_TEST-Template1-Splitting.txt'))))
def test_json2isatab_convert_sample_pool_study_table(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'TEST-ISA-sample-pool.json')), self._tmp_dir) self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 's_TEST-Template3-Splitting.txt')), open(os.path.join(self._tab_data_dir, 'TEST-ISA-sample-pool', 's_TEST-Template3-Splitting.txt'))))
def test_json2isatab_convert_sample_pool_assay_table(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'TEST-ISA-sample-pool.json')), self._tmp_dir) self.assertTrue(assert_tab_content_equal( open(os.path.join(self._tmp_dir, 'a_test-template3-splitting_transcription_profiling_DNA_microarray.txt')), open(os.path.join(self._tab_data_dir, 'TEST-ISA-sample-pool', 'a_test-template3-splitting_transcription_profiling_DNA_microarray.txt'))))
def test_json2isatab_convert_bii_s_7_investigation(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-S-7', 'BII-S-7.json')), self._tmp_dir, i_file_name='i_matteo.txt') self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'i_matteo.txt')), open(os.path.join(self._tab_data_dir, 'BII-S-7', 'i_matteo.txt'))))
def test_json2isatab_convert_bii_s_3_assay_table_Gx(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-S-3', 'BII-S-3.json')), self._tmp_dir) self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 'a_gilbert-assay-Gx.txt')), open(os.path.join(self._tab_data_dir, 'BII-S-3', 'a_gilbert-assay-Gx.txt'))))
def main(argv=None): """Run **isatools** from the command line Arguments argv (list, optional): the list of arguments to run isatools with (if None, then sys.argv is used) [default: None] """ p = argparse.ArgumentParser( prog=__name__, formatter_class=argparse.RawDescriptionHelpFormatter, description= '''Create, convert, and manipulate ISA-formatted metadata''', usage='isatools -c COMMAND [options]', ) p.add_argument('-c', dest='cmd', help='isatools API command to run', required=True, choices=[ 'isatab2json', 'json2isatab', 'sampletab2isatab', 'sampletab2json' ]) p.add_argument('-i', dest='in_path', help='in (files or directory will be read from here)', required=True) p.add_argument( '-o', dest='out_path', help= 'out (file will be written out here or written to directory if ISA-Tab ' 'archive out)', required=True) p.add_argument('--version', action='version', version='isatools {}'.format("0.7")) p.add_argument('-v', dest='verbose', help="show more output", action='store_true', default=False) args = p.parse_args(argv or sys.argv[1:]) if args.verbose: print("{} input: {}".format(os.linesep, args.in_path)) print("output: {}".format(args.out_path)) if args.cmd == 'isatab2json': from isatools.convert import isatab2json J = isatab2json.convert(args.in_path) with open(args.out_path, 'w') as out_fp: json.dump(J, out_fp) elif args.cmd == 'json2isatab': from isatools.convert import json2isatab with open(args.in_path) as in_fp: json2isatab.convert(in_fp, args.out_path) elif args.cmd == 'sampletab2isatab': from isatools.convert import sampletab2isatab with open(args.in_path) as in_fp: sampletab2isatab.convert(in_fp, args.out_path) elif args.cmd == 'sampletab2json': from isatools.convert import sampletab2json with open(args.in_path) as in_fp: with open(args.out_path, 'w') as out_fp: sampletab2json.convert(in_fp, out_fp)
def test_json2isatab_convert_bii_s_7_study_table(self): json2isatab.convert(open(os.path.join(self._json_data_dir, 'BII-S-7', 'BII-S-7.json')), self._tmp_dir) self.assertTrue(assert_tab_content_equal(open(os.path.join(self._tmp_dir, 's_BII-S-7.txt')), open(os.path.join(self._tab_data_dir, 'BII-S-7', 's_BII-S-7.txt'))))