Esempio n. 1
0
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)
Esempio n. 2
0
    def post(self):
        response = Response(status=500)
        # Create temporary directory
        tmp_dir = _create_temp_dir()
        try:
            if tmp_dir is None:
                raise IOError("Could not create temporary directory " + tmp_dir)
            if not request.mimetype == "application/zip":
                raise TypeError("Incorrect media type received. Got " + request.mimetype + ", expected application/zip")
            else:
                # Write request data to file
                file_path = _write_request_data(request, tmp_dir, 'isatab.zip')
                if file_path is None:
                    raise IOError("Could not create temporary file " + file_path)

                # Setup path to configuration
                config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'isaconfig-default')

                with zipfile.ZipFile(file_path, 'r') as z:
                    # extract ISArchive files
                    z.extractall(tmp_dir)
                    src_dir = os.path.normpath(os.path.join(tmp_dir, z.filelist[0].filename))
                    # convert to SRA writes to /sra
                    isatab2sra.create_sra(src_dir, tmp_dir, config_dir)
                    memf = io.BytesIO()
                    with zipfile.ZipFile(memf, 'w') as zf:
                        for file in os.listdir(tmp_dir + '/sra/' + z.filelist[0].filename):
                            zf.write(os.path.join(tmp_dir + '/sra/' + z.filelist[0].filename, file), file)
                    memf.seek(0)
                    response = send_file(memf, mimetype='application/zip')
        except TypeError:
            response = Response(status=415)
        except Exception:
            response = Response(status=500)
        finally:
            shutil.rmtree(tmp_dir, ignore_errors=True)
            return response
Esempio n. 3
0
    def test_isatab_to_sra(self):
        from isatools.convert import isatab2sra

        isatab2sra.create_sra(self._work_dir, self._sra_dir, self._config_dir)
        assert (os.path.exists(os.path.join(self._sra_dir, "/sra")), True)