def get_isa_json(self, study_id, api_key, study_location=None):
        """
        Get an ISA-API Investigation object reading directly from the ISA-Tab files
        :param study_id: MTBLS study identifier
        :param api_key: User API key for accession check
        :param study_location: The filesystem location of the study
        :return: an ISA-API Investigation object
        """
        start = time.time()

        if study_location is None:
            logger.info("Study location is not set, will have load study from filesystem")
            path = self.wsc.get_study_location(study_id, api_key)
        else:
            logger.info("Study location is: " + study_location)
            path = study_location

        # try the new parser first
        isa_json = None
        try:
            isa_json = isatab2json.convert(path, validate_first=False, use_new_parser=True)
        except Exception:  # on failure, use the old one
            try:
                isa_json = isatab2json.convert(path, validate_first=False, use_new_parser=False)
            except Exception:
                # if it fails too
                if isa_json is None:
                    abort(500)
            else:
                logger.info('... get_isa_json() processing (I): %s sec.', time.time() - start)
                return isa_json
        else:
            logger.info('... get_isa_json() processing (II): %s sec.', time.time() - start)
            return isa_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)
     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))
Example #3
0
 def test_isatab2json_convert_sample_pool_with_error(self):
     test_case = 'TEST-ISA-sample-pool-with-error'
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir, test_case),
                                       validate_first=False,
                                       use_new_parser=True)
     json.dump(actual_json, open(os.path.join(self._tmp_dir, 'isa.json'), 'w'))
     with open(os.path.join(self._tmp_dir, 'isa.json')) as actual_json:
         report = isajson.validate(actual_json)
         self.assertEqual(len(report['errors']), 0)
Example #4
0
 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))
Example #5
0
 def test_isatab2json_convert_mtbls3(self):
     test_case = 'MTBLS3'
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir, test_case),
                                       validate_first=False,
                                       use_new_parser=True)
     json.dump(actual_json, open(os.path.join(self._tmp_dir, 'isa.json'), 'w'))
     with open(os.path.join(self._tmp_dir, 'isa.json')) as actual_json:
         report = isajson.validate(actual_json)
         self.assertEqual(len(report['errors']), 0)
 def test_isatab2json_convert_bii_s_3(self):
     test_case = 'BII-S-3'
     actual_json = isatab2json.convert(
         os.path.join(self._tab_data_dir, test_case), self.identifier_type)
     expected_json = json.load(
         open(
             os.path.join(self._json_data_dir, test_case,
                          test_case + '.json')))
     self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
Example #7
0
 def test_isatab2json_convert_sample_pool(self):
     test_case = 'TEST-ISA-sample-pool'
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir,
                                                    test_case),
                                       validate_first=False)
     with open(os.path.join(self._json_data_dir,
                            test_case + '.json')) as expected_file:
         expected_json = json.load(expected_file)
         self.assertTrue(utils.assert_json_equal(expected_json,
                                                 actual_json))
Example #8
0
 def test_isatab2json_convert_source_split_with_error(self):
     test_case = 'TEST-ISA-source-split-with-error'
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir,
                                                    test_case),
                                       validate_first=False)
     with open(os.path.join(self._json_data_dir,
                            test_case + '.json')) as expected_file:
         expected_json = json.load(expected_file)
         self.assertTrue(utils.assert_json_equal(expected_json,
                                                 actual_json))
Example #9
0
 def test_isatab2json_convert_charac_param_factor(self):
     test_case = 'TEST-ISA-charac-param-factor'
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir,
                                                    test_case),
                                       validate_first=False)
     with open(os.path.join(self._json_data_dir,
                            test_case + '.json')) as expected_file:
         expected_json = json.load(expected_file)
         self.assertTrue(utils.assert_json_equal(expected_json,
                                                 actual_json))
Example #10
0
 def test_isatab2json_convert_repeated_measure(self):
     test_case = 'TEST-ISA-repeated-measure'
     actual_json = isatab2json.convert(
         os.path.join(self._tab_data_dir, test_case), validate_first=False,
         use_new_parser=True)
     with open(os.path.join(self._tmp_dir, 'isa.json'), 'w') as out_fp:
         json.dump(actual_json, out_fp)
     with open(os.path.join(self._tmp_dir, 'isa.json')) as actual_json:
         report = isajson.validate(actual_json)
         self.assertEqual(len(report['errors']), 0)
Example #11
0
    def get_isa_json(self, study_id, api_key, study_location=None):
        """
        Get an ISA-API Investigation object reading directly from the ISA-Tab files
        :param study_id: MTBLS study identifier
        :param api_key: User API key for accession check
        :param study_location: The filesystem location of the study
        :return: an ISA-API Investigation object
        """
        start = time.time()

        if study_location is None:
            logger.info(
                "Study location is not set, will have load study from filesystem"
            )
            path = self.wsc.get_study_location(study_id, api_key)
        else:
            logger.info("Study location is: " + study_location)
            path = study_location

        # try the new parser first
        isa_json = None
        try:
            isa_json = isatab2json.convert(path,
                                           validate_first=False,
                                           use_new_parser=True)
        except Exception:  # on failure, use the old one
            try:
                isa_json = isatab2json.convert(path,
                                               validate_first=False,
                                               use_new_parser=False)
            except Exception:
                # if it fails too
                if isa_json is None:
                    abort(500)
            else:
                logger.info('... get_isa_json() processing (I): %s sec.',
                            time.time() - start)
                return isa_json
        else:
            logger.info('... get_isa_json() processing (II): %s sec.',
                        time.time() - start)
            return isa_json
Example #12
0
 def test_isatab2json_convert_bii_s_7(self):
     test_case = 'BII-S-7'
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir,
                                                    test_case),
                                       validate_first=False)
     with open(
             os.path.join(self._json_data_dir, test_case,
                          test_case + '.json')) as expected_file:
         expected_json = json.load(expected_file)
         self.assertTrue(utils.assert_json_equal(expected_json,
                                                 actual_json))
Example #13
0
 def post(self):
     response = Response(status=415)
     if request.mimetype == "application/zip":
         tmp_dir = None
         tmp_file = None
         combined_json = None
         try:
             # Write request data to file
             tmp_file = str(uuid.uuid4()) + ".zip"
             file_path = _write_request_data(request, config.UPLOAD_FOLDER, tmp_file)
             if file_path is None:
                 return Response(500)
             # Extract ISArchive files
             with zipfile.ZipFile(file_path, 'r') as z:
                 # Create temporary directory
                 tmp_dir = _create_temp_dir()
                 if tmp_dir is None:
                     return Response(500)
                 z.extractall(tmp_dir)
                 # Convert
                 src_dir = os.path.normpath(os.path.join(tmp_dir, z.filelist[0].filename))
                 isatab2json.convert(src_dir, src_dir)
                 # return just the combined JSON
                 files = [f for f in os.listdir(src_dir) if f.endswith('.json')]
                 if len(files) == 1:  # current assumption is that only one JSON should exist to know what to return
                     combined_json_file = os.path.join(src_dir, files[0])
                     combined_json = json.load(open(combined_json_file))
                 else:
                     raise IOError("More than one .json was output - cannot disambiguate what to return")
         except Exception as e:
             print(e)
             return Response(status=500)
         finally:
             # cleanup generated directories
             try:
                 shutil.rmtree(tmp_dir, ignore_errors=True)
                 os.remove(os.path.join(config.UPLOAD_FOLDER, tmp_file))
             except:
                 pass
         response = jsonify(combined_json)
     return response
Example #14
0
 def test_isatab2json_convert_mtbls1(self):
     test_case = 'MTBLS1'
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir,
                                                    test_case),
                                       self.identifier_type,
                                       validate_first=False)
     with open(
             os.path.join(self._json_data_dir, test_case,
                          test_case + '.json')) as expected_file:
         expected_json = json.load(expected_file)
         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))
Example #16
0
    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))
Example #17
0
def getj(mtbls_study_id):
    """
    This function downloads the specified MetaboLights study and returns an ISA JSON representation of it

    :param mtbls_study_id: Study identifier for MetaboLights study to get, as a str (e.g. MTBLS1)
    :return: ISA JSON representation of the MetaboLights study

    Example usage:
        isa_json = MTBLS.load('MTBLS1')
    """
    tmp_dir = get(mtbls_study_id)
    if tmp_dir is None:
        raise IOError("There was a problem retrieving the study ", mtbls_study_id)
    isa_json = isatab2json.convert(tmp_dir, identifier_type=isatab2json.IdentifierType.name, validate_first=False)
    shutil.rmtree(tmp_dir)
    return isa_json
Example #18
0
def getj(mtbls_study_id):
    """
    This function downloads the specified MetaboLights study and returns an ISA JSON representation of it

    :param mtbls_study_id: Study identifier for MetaboLights study to get, as a str (e.g. MTBLS1)
    :return: ISA JSON representation of the MetaboLights study

    Example usage:
        isa_json = MTBLS.load('MTBLS1')
    """
    tmp_dir = get(mtbls_study_id)
    if tmp_dir is None:
        raise IOError("There was a problem retrieving the study ", mtbls_study_id)
    isa_json = isatab2json.convert(tmp_dir, identifier_type=isatab2json.IdentifierType.name,
                                   validate_first=False,
                                   use_new_parser=True)
    shutil.rmtree(tmp_dir)
    return isa_json
Example #19
0
def convert(source_path, dest_path, sra_settings=None, validate_first=True):
    from isatools.convert import isatab2json, json2sra
    isa_json = isatab2json.convert(source_path, validate_first=validate_first)
    isa_json_fp = StringIO(json.dumps(isa_json))
    isa_json_fp.name = "BII-S-3.json"
    json2sra.convert2(isa_json_fp, dest_path, sra_settings=sra_settings, validate_first=False)
    logging.info("Conversion complete...")
    buffer = BytesIO()
    if os.path.isdir(dest_path):
        with ZipFile(buffer, 'w') as zip_file:
            # use relative dir_name to avoid absolute path on file names
            zipdir(dest_path, zip_file)
            print(zip_file.namelist())

            # clean up the target directory after the ZIP file has been closed
            # rmtree(sra_dir)

        buffer.seek(0)
        return buffer
Example #20
0
def convert(source_path, dest_path, sra_settings=None, validate_first=True):
    log.info("Converting ISA-Tab to JSON for %s", source_path)
    isa_json = isatab2json.convert(source_path, validate_first=validate_first)
    log.debug("Writing JSON to memory file")
    isa_json_fp = StringIO(json.dumps(isa_json))
    isa_json_fp.name = "BII-S-3.json"
    log.info("Converting JSON to SRA, writing to %s", dest_path)
    log.info("Using SRA settings %s", sra_settings)
    json2sra.convert(isa_json_fp, dest_path, sra_settings=sra_settings, validate_first=False)
    log.info("Conversion from ISA-Tab to SRA complete")
    buffer = BytesIO()
    if os.path.isdir(dest_path):
        log.info("Zipping SRA files")
        with ZipFile(buffer, 'w') as zip_file:
            zipdir(dest_path, zip_file)
            log.debug("Zipped %s", zip_file.namelist())
        buffer.seek(0)
        log.info("Returning zipped files as memory file")
        return buffer
Example #21
0
def convert(source_path, dest_path, sra_settings=None, validate_first=True):
    isa_json = isatab2json.convert(source_path, validate_first=validate_first)
    isa_json_fp = StringIO(json.dumps(isa_json))
    isa_json_fp.name = "BII-S-3.json"
    json2sra.convert(isa_json_fp,
                     dest_path,
                     sra_settings=sra_settings,
                     validate_first=False)
    logging.info("Conversion complete...")
    buffer = BytesIO()
    if os.path.isdir(dest_path):
        with ZipFile(buffer, 'w') as zip_file:
            # use relative dir_name to avoid absolute path on file names
            zipdir(dest_path, zip_file)
            print(zip_file.namelist())

            # clean up the target directory after the ZIP file has been closed
            # rmtree(sra_dir)

        buffer.seek(0)
        return buffer
Example #22
0
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)
Example #23
0
#!/usr/bin/env python3

import json
import sys

input_path = sys.argv[1]
output_file_path = sys.argv[2]

try:
    from isatools.convert import isatab2json
except ImportError as e:
    raise RuntimeError('Could not import isatools package')

isatab_dir = input_path
my_json = isatab2json.convert(work_dir=isatab_dir,
                              validate_first=False,
                              use_new_parser=True)
with open(output_file_path, 'w') as out_fp:
    json.dump(my_json, out_fp, indent=4)
Example #24
0
import sys
import os
src_dir = sys.argv[1]
target_dir = sys.argv[2]
try:
    from isatools.convert import isatab2json
except ImportError as e:
    raise RuntimeError("Could not import isatools package")
isatab2json.convert(src_dir, target_dir)
Example #25
0
    def test_bii_i_1_conversion(self):
        isatab2json.convert(os.path.join(self._dir, "./data/BII-I-1/"), self._tmp)
        isa_json = json.load(open("../isatools/sampledata/BII-I-1.json"))
        self.assertEqual(isa_json["identifier"], "BII-I-1")
        self.assertEqual(isa_json["title"], "Growth control of the eukaryote cell: a systems biology study in yeast")
        self.assertEqual(
            isa_json["description"],
            "Background Cell growth underlies many key cellular and "
            "developmental processes, yet a limited number of studies have been "
            "carried out on cell-growth regulation. Comprehensive studies at "
            "the transcriptional, proteomic and metabolic levels under defined "
            "controlled conditions are currently lacking. Results Metabolic "
            "control analysis is being exploited in a systems biology study of "
            "the eukaryotic cell. Using chemostat culture, we have measured the "
            "impact of changes in flux (growth rate) on the transcriptome, "
            "proteome, endometabolome and exometabolome of the yeast "
            "Saccharomyces cerevisiae. Each functional genomic level shows clear "
            "growth-rate-associated trends and discriminates between "
            "carbon-sufficient and carbon-limited conditions. Genes consistently "
            "and significantly upregulated with increasing growth rate are "
            "frequently essential and encode evolutionarily conserved proteins "
            "of known function that participate in many protein-protein "
            "interactions. In contrast, more unknown, and fewer essential, genes "
            "are downregulated with increasing growth rate; their protein "
            "products rarely interact with one another. A large proportion of "
            "yeast genes under positive growth-rate control share orthologs with "
            "other eukaryotes, including humans. Significantly, transcription of "
            "genes encoding components of the TOR complex (a major controller of "
            "eukaryotic cell growth) is not subject to growth-rate regulation. "
            "Moreover, integrative studies reveal the extent and importance of "
            "post-transcriptional control, patterns of control of metabolic "
            "fluxes at the level of enzyme synthesis, and the relevance of "
            "specific enzymatic reactions in the control of metabolic fluxes "
            "during cell growth. Conclusion This work constitutes a first "
            "comprehensive systems biology study on growth-rate control in the "
            "eukaryotic cell. The results have direct implications for advanced "
            "studies on cell growth, in vivo regulation of metabolic fluxes for "
            "comprehensive metabolic engineering, and for the design of "
            "genome-scale systems biology models of the eukaryotic cell.",
        )
        self.assertEqual(isa_json["submissionDate"], "2007-04-30")
        self.assertEqual(isa_json["publicReleaseDate"], "2009-03-10")
        self.assertEqual(isa_json["commentCreatedWithConfiguration"]["name"], "Created With Configuration")
        self.assertEqual(isa_json["commentCreatedWithConfiguration"]["value"], "")
        self.assertEqual(isa_json["commentLastOpenedWithConfiguration"]["name"], "Last Opened With Configuration")
        self.assertEqual(isa_json["commentLastOpenedWithConfiguration"]["value"], "isaconfig-default_v2013-02-13")
        self.assertEqual(len(isa_json["ontologySourceReferences"]), 7)
        self.assertEqual(len(isa_json["publications"]), 1)
        self.assertEqual(isa_json["publications"][0]["pubMedID"], "17439666")
        self.assertEqual(isa_json["publications"][0]["doi"], "doi:10.1186/jbiol54")
        self.assertEqual(
            isa_json["publications"][0]["authorList"],
            "Castrillo JI, Zeef LA, Hoyle DC, Zhang N, Hayes "
            "A, Gardner DC, Cornell MJ, Petty J, Hakes L, "
            "Wardleworth L, Rash B, Brown M, Dunn WB, "
            "Broadhurst D, O'Donoghue K, Hester SS, Dunkley "
            "TP, Hart SR, Swainston N, Li P, Gaskell SJ, Paton "
            "NW, Lilley KS, Kell DB, Oliver SG.",
        )
        self.assertEqual(
            isa_json["publications"][0]["title"],
            "Growth control of the eukaryote cell: a systems " "biology study in yeast.",
        )
        self.assertEqual(isa_json["publications"][0]["status"]["name"], "indexed in Pubmed")

        self.assertEqual(len(isa_json["people"]), 3)
        self.assertEqual(isa_json["people"][0]["firstName"], "Oliver")
        self.assertEqual(isa_json["people"][1]["firstName"], "Juan")
        self.assertEqual(isa_json["people"][2]["firstName"], "Leo")
        self.assertEqual(isa_json["people"][0]["lastName"], "Stephen")
        self.assertEqual(isa_json["people"][1]["lastName"], "Castrillo")
        self.assertEqual(isa_json["people"][2]["lastName"], "Zeef")
        self.assertEqual(isa_json["people"][0]["midInitials"], "G")
        self.assertEqual(isa_json["people"][1]["midInitials"], "I")
        self.assertEqual(isa_json["people"][2]["midInitials"], "A")
        self.assertEqual(isa_json["people"][0]["address"], "Oxford Road, Manchester M13 9PT, UK")
        self.assertEqual(isa_json["people"][1]["address"], "Oxford Road, Manchester M13 9PT, UK")
        self.assertEqual(isa_json["people"][2]["address"], "Oxford Road, Manchester M13 9PT, UK")
        self.assertEqual(
            isa_json["people"][0]["affiliation"],
            "Faculty of Life Sciences, Michael Smith Building, " "University of Manchester",
        )
        self.assertEqual(
            isa_json["people"][1]["affiliation"],
            "Faculty of Life Sciences, Michael Smith Building, " "University of Manchester",
        )
        self.assertEqual(
            isa_json["people"][2]["affiliation"],
            "Faculty of Life Sciences, Michael Smith Building, " "University of Manchester",
        )

        self.assertEqual(len(isa_json["studies"]), 2)
        self.assertEqual(isa_json["studies"][0]["identifier"], "BII-S-1")
        self.assertEqual(isa_json["studies"][1]["identifier"], "BII-S-2")

        self.assertEqual(len(isa_json["studies"][0]["factors"]), 2)
        self.assertEqual(isa_json["studies"][0]["factors"][0]["factorName"], "limiting nutrient")
        self.assertEqual(isa_json["studies"][0]["factors"][1]["factorName"], "rate")
        self.assertEqual(isa_json["studies"][0]["factors"][0]["factorType"]["name"], "chemical compound")
        self.assertEqual(isa_json["studies"][0]["factors"][1]["factorType"]["name"], "rate")

        self.assertEqual(len(isa_json["studies"][0]["sources"]), 18)
        self.assertEqual(len(isa_json["studies"][0]["samples"]), 163)
        self.assertEqual(len(isa_json["studies"][1]["sources"]), 1)
        self.assertEqual(len(isa_json["studies"][1]["samples"]), 2)
Example #26
0
 def test_isatab2json_convert_charac_param_factor(self):
     test_case = "TEST-ISA-charac-param-factor"
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir, test_case), self.identifier_type)
     expected_json = json.load(open(os.path.join(self._json_data_dir, test_case + ".json")))
     self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
Example #27
0
#parser.add_argument("-o", "--out", dest="outfile",
#                    help="output json ISA file, no extension", metavar="ISAjson")
#parser.add_argument("-q", "--quiet",
#                    action="store_false", dest="verbose", default=True,
#                    help="don't print status messages to stdout")

args = parser.parse_args()

print(args.indir)
#print (args.outfile)

output_file = args.indir + ".json"
output_path = "./jsondir/"
input_path = "./isatabs/" + args.indir

if not os.path.exists(output_path):
    os.makedirs(output_path)
#print(output_path)

print("ISA json built in " + output_path + output_file + "\n")

# isa_json = isatab2json.convert('./isatabs/'args.indir, use_new_parser=True)
#isa_json = isatab2json.convert(join('./isatabs/'args.indir), use_new_parser=True)
isa_json = isatab2json.convert(input_path, use_new_parser=True)

try:
    with open(join(output_path, output_file), 'w') as out_fp:
        json.dump(isa_json, out_fp, indent=4)
except IOError as e:
    print("something went wrong:", e)
import json
import requests

from isatools import isatab
from isatools.convert import isatab2json

directory_1 = '/Users/Philippe/Documents/Dropbox-Backup/Eurovis 2015 - Chronoglyph/ISATAB-datasets/BII-S-8_FP001RO-isatab-TEST'
inv_name_1 = 'i_fp001ro-investigation.txt'
isa_config_1 = '/Users/Philippe/Documents/git/Configuration-Files/isaconfig-default_v2014-01-16/'

directory_2 = '/Users/Philippe/Documents/git/ISAdatasets/tab/MTBLS404/'
inv_name_2 = 'i_sacurine.txt'
# isa_config_2 = '/Users/Philippe/Documents/git/Configuration-Files/isaconfig-seq_v2016-11-17-SRA1.5-august2014mod/'

try:
    # my_isa_read = isatab.load(open(os.path.join('/Users/Philippe/Downloads/ISAcreator-1.7.11-all/isatab files/SRA_assembly_test', 'i_investigation.txt')))
    my_isa_read = isatab.load(open(os.path.join(directory_1, inv_name_1)))
    print("reading in:", my_isa_read.studies)

    # my_json_report = isatab.validate(open(os.path.join('/Users/Philippe/Downloads/ISAcreator-1.7.11-all/isatab files/SRA_assembly_test', 'i_investigation.txt')), '/Users/Philippe/Documents/git/Configuration-Files/isaconfig-seq_v2016-11-17-SRA1.5-august2014mod/')

    # my_json_report = isatab.validate(open(os.path.join(directory_1,inv_name_1)), isa_config_1)
    # print(my_json_report)

    try:
        isa_json = isatab2json.convert(directory_2)
    except Exception as excep:
        print(excep)

except IOError as e:
    print(e)
Example #29
0
 def test_isatab2json_convert_source_split_with_error(self):
     test_case = "TEST-ISA-source-split-with-error"
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir, test_case), self.identifier_type)
     expected_json = json.load(open(os.path.join(self._json_data_dir, test_case + ".json")))
     self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
Example #30
0
 def test_isatab2json_convert_sample_pool(self):
     test_case = "TEST-ISA-sample-pool"
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir, test_case), self.identifier_type)
     expected_json = json.load(open(os.path.join(self._json_data_dir, test_case + ".json")))
     self.assertTrue(utils.assert_json_equal(expected_json, actual_json))
 def test_isa_source_split_with_error_conversion(self):
     isatab2json.convert(os.path.join(self._dir, './data/TEST-ISA-source-split-with-error/'), self._dir, isatab2json.IdentifierType.name)
 def test_isa_sample_pool_with_error_conversion(self):
     isatab2json.convert(os.path.join(self._dir, './data/TEST-ISA-sample-pool-with-error/'), self._dir, isatab2json.IdentifierType.name)
 def test_isa_repeated_measure_conversion(self):
     isatab2json.convert(os.path.join(self._dir, './data/TEST-ISA-repeated-measure/'), self._dir, isatab2json.IdentifierType.name)
 def test_isa_charac_param_factor(self):
     isatab2json.convert(os.path.join(self._dir, './data/TEST-ISA-charax-param-factor/'), self._dir, isatab2json.IdentifierType.name)
     isa_json = json.load(open(os.path.join(self._dir, 'TEST-ISA-charac-param-factor.json')))
     self.assertEqual(isa_json["identifier"], "TEST-ISA-charac-param-factor")
Example #35
0
 def test_isatab2json_convert_mtbls1(self):
     test_case = "MTBLS1"
     actual_json = isatab2json.convert(os.path.join(self._tab_data_dir, test_case), self.identifier_type)
     expected_json = json.load(open(os.path.join(self._json_data_dir, test_case, test_case + ".json")))
     self.assertTrue(utils.assert_json_equal(expected_json, actual_json))