def get_isatab(arrayexpress_id, target_dir=None): """ This function downloads MAGE-TAB content as ISA-Tab from the ArrayExpress FTP site. :param ax_experiment_id: Experiment identifier for ArrayExpress study to get, as a str (e.g. E-GEOD-59671) :param target_dir: Path to write ISA-Tab files to. If None, writes to temporary directory (generated on the fly) :return: Path where the files were written to Example usage: from isatools.io import ax as AX AX.get_isatab('E-GEOD-59671', '/tmp/ax') """ tmp_dir = tempfile.mkdtemp() try: get(arrayexpress_id=arrayexpress_id, target_dir=tmp_dir) if target_dir is None: target_dir = tempfile.mkdtemp() log.info("Using directory '{}'".format(target_dir)) magetab2isatab.convert(os.path.join( tmp_dir, "{}.idf.txt".format(arrayexpress_id)), output_path=target_dir) except Exception as e: log.fatal("Something went wrong: {}".format(e)) finally: shutil.rmtree(tmp_dir) return target_dir
def convert(idf_file_path): tmp = tempfile.mkdtemp() ISA = None try: magetab2isatab.convert(idf_file_path, output_path=tmp) with open(os.path.join(tmp, "i_investigation.txt")) as isa_inv_fp: ISA = isatab.load(isa_inv_fp) finally: shutil.rmtree(tmp) if ISA is not None: return json.loads(json.dumps(ISA, cls=ISAJSONEncoder))
def test_magetab2isatab_convert_e_geod_59671(self): magetab2isatab.convert( os.path.join(self._magetab_data_dir, 'E-GEOD-59671.idf.txt'), self._tmp_dir) self.assertTrue( os.path.isfile(os.path.join(self._tmp_dir, 'i_investigation.txt'))) self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 's_E-GEOD-59671_study.txt'))) self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 'a_E-GEOD-59671_assay-RNA-Seq.txt'))) with open(os.path.join(self._tmp_dir, 'i_investigation.txt')) as i_fp: isatab.validate(i_fp)
def test_magetab2isatab_convert_e_mexp_31(self): magetab2isatab.convert( os.path.join(self._magetab_data_dir, 'E-MEXP-31.idf.txt'), self._tmp_dir) self.assertTrue( os.path.isfile(os.path.join(self._tmp_dir, 'i_investigation.txt'))) self.assertTrue( os.path.isfile(os.path.join(self._tmp_dir, 's_E-MEXP-31_study.txt'))) self.assertTrue( os.path.isfile( os.path.join( self._tmp_dir, 'a_E-MEXP-31_assay-transcription profiling by array.txt'))) with open(os.path.join(self._tmp_dir, 'i_investigation.txt')) as i_fp: isatab.validate(i_fp)
def test_magetab2isatab_convert_e_geod_59671(self): with open(os.path.join(self._magetab_data_dir, 'E-GEOD-59671.idf.txt')) as idf_fp: magetab2isatab.convert(idf_fp, self._tmp_dir) self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 'i_investigation.txt'))) self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 's_E-GEOD-59671.sdrf.txt'))) self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 'a_E-GEOD-59671.sdrf.txt'))) from isatools import isatab with open(os.path.join(self._tmp_dir, 'i_investigation.txt')) as i_fp: isatab.validate(i_fp)
def test_magetab2isatab_convert_e_mexp_31(self): with open(os.path.join(self._magetab_data_dir, 'E-MEXP-31.idf.txt')) as idf_fp: magetab2isatab.convert(idf_fp, self._tmp_dir, 'protein microarray', 'protein expression profiling') self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 'i_investigation.txt'))) self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 's_E-MEXP-31.sdrf.txt'))) self.assertTrue( os.path.isfile( os.path.join(self._tmp_dir, 'a_E-MEXP-31.sdrf.txt'))) from isatools import isatab with open(os.path.join(self._tmp_dir, 'i_investigation.txt')) as i_fp: isatab.validate(i_fp)