Exemplo n.º 1
0
def convert(path):

    headerList = []  # used to generate one csv file for folder

    tmpPath, enclosingFolder = os.path.split(path)

    with javabridge.vm(run_headless=True, class_path=bioformats.JARS):

        # turn off logging, see:
        # ./bStack_env/lib/python3.7/site-packages/bioformats/log4j.py
        log4j = javabridge.JClassWrapper("loci.common.Log4jTools")
        log4j.enableLogging()
        log4j.setRootLevel("WARN")

        # build a list of oir header dictionaries
        for file in sorted(os.listdir(path)):
            if file.startswith('.'):
                continue
            if file.endswith('.oir'):

                filePath = os.path.join(path, file)

                myStack = bStack(filePath)
                myStack.loadHeader()
                myStack.header.prettyPrint()  # print to command line
                headerList.append(myStack.header.header
                                  )  # used to generate one csv file for folder

                # save the .txt file
                baseFileName = os.path.basename(file)
                baseFileName, ext = baseFileName.split('.')
                textFilePath = os.path.join(path, baseFileName + '.txt')
                with open(textFilePath, 'w') as textFile:
                    textFile.write(myStack.header.getMetaData())
        #
        # generate one file with one row for each oir header
        if len(headerList) > 0:
            outFilePath = os.path.join(path, enclosingFolder + '.csv')
            with open(outFilePath, 'w') as outFile:
                print('saving file:', outFilePath)
                for idx, header in enumerate(headerList):
                    if idx == 0:
                        columnNames = ''
                        for k, v in header.items():
                            columnNames += k + ','
                        outFile.write(columnNames + '\n')
                    for k, v in header.items():
                        outFile.write(str(v) + ',')
                    outFile.write('\n')
Exemplo n.º 2
0
def main():

    sys.modules["javabridge"]           = importlib.import_module("jt.javabridge")
    sys.modules["javabridge.__about__"] = importlib.import_module("jt.javabridge.__about__")
    sys.modules["javabridge.jutil"]     = importlib.import_module("jt.javabridge.jutil")
    sys.modules["javabridge.locate"]    = importlib.import_module("jt.javabridge.locate")
    sys.modules["javabridge.wrappers"]  = importlib.import_module("jt.javabridge.wrappers")

    print("Running testsuite", "\n", file=sys.stderr)

    import javabridge as jb

    with jb.vm(class_path=[os.path.join(test_java, "classes")] + jb.JARS,
               max_heap_size="512M"):
        tests = test_suite(sys.argv[1:] or None)
        result = unittest.TextTestRunner(verbosity=2).run(tests)

    sys.exit(0 if result.wasSuccessful() else 1)
Exemplo n.º 3
0
import os
import javabridge

with javabridge.vm(run_headless=True):
    print(
        javabridge.run_script(
            'java.lang.String.format("Hello, %s!", greetee);',
            dict(greetee='world')))
#!/usr/bin/env python

"""demo_nogui.py - show how to start the Javabridge without a GUI

python-javabridge is licensed under the BSD license.  See the
accompanying file LICENSE for details.

Copyright (c) 2003-2009 Massachusetts Institute of Technology
Copyright (c) 2009-2013 Broad Institute
All rights reserved.

"""

import os
import javabridge

with javabridge.vm(run_headless=True):
    print javabridge.run_script('java.lang.String.format("Hello, %s!", greetee);', dict(greetee="world"))
Exemplo n.º 5
0
import bioformats

print('bioformats.JARS:', bioformats.JARS)

#from bimpy import bStack
import bimpy

if __name__ == '__main__':

	startSeconds = time.time()

	path = sys.argv[1]
	print('bConvertOir', path)

	with javabridge.vm(
			run_headless=True,
			class_path=bioformats.JARS
			):

		log4j = javabridge.JClassWrapper("loci.common.Log4jTools")
		log4j.enableLogging()
		log4j.setRootLevel("WARN")

		myStack = bimpy.bStack.bStack(path)

		savePath = myStack.convert_getSaveFile(channelNumber=1)

		if os.path.isfile(savePath):
			print('bConvertOir did not convert, destination file exists', savePath)
		else:
			myStack.convert()