예제 #1
0
 def perform_needle_comparison(self, seq_a, seq_b):
     protDB = db_handling.ProteinDatabase()
     tempfile = MemoryTempfile(preferred_paths=['/mnt/tmp'])
     f1 = tempfile.NamedTemporaryFile(delete=False)
     f1.write(seq_a[1].encode('utf-8'))
     f1.close()
     f2 = tempfile.NamedTemporaryFile(delete=False)
     f2.write(seq_b[1].encode('utf-8'))
     f2.close()
     f3 = tempfile.NamedTemporaryFile(delete=False)
     subprocess.run([
         'needle --asequence ' + f1.name + ' --bsequence ' + f2.name +
         ' --gapopen 10.0 --gapextend 0.5 --stdout ' + f3.name +
         ' < enter_param > /dev/null 2>&1'
     ],
                    stdout=subprocess.PIPE,
                    shell=True)
     lines = [line.decode('utf-8') for line in f3.readlines()]
     f3.close()
     values = self.get_values_from_needle_align(lines)
     values.insert(0, seq_a[0])
     values.insert(0, seq_b[0])
     if values[2] == 0 and values[3] == 0 and values[4] == 0 and values[
             5] == 0 and values[6] == 0.0:
         os.unlink(f1.name)
         os.unlink(f2.name)
         os.unlink(f3.name)
         self.perform_needle_comparison(seq_a, seq_b)
         return
     protDB.insert_needle_alignment(values)
     os.unlink(f1.name)
     os.unlink(f2.name)
     os.unlink(f3.name)
예제 #2
0
def example1():
    from memory_tempfile import MemoryTempfile

    tempfile = MemoryTempfile()
    print(tempfile.fallback)

    with tempfile.NamedTemporaryFile(suffix='.jpg', delete=False) as td:
        print(td.name)
        pass
예제 #3
0
def example2():
    # We now do not want to use /dev/shm or /run/shm and no ramfs paths
    # If /run/user/{uid} is available, we prefer it to /tmp
    # And we want to try /var/run as a last resort
    # If all fails, fallback to platform's tmp dir
    
    from memory_tempfile import MemoryTempfile
    
    # By the way, all paths with string {uid} will have it replaced with the user id
    tempfile = MemoryTempfile(preferred_paths=['/run/user/{uid}'], remove_paths=['/dev/shm', '/run/shm'],
                              additional_paths=['/var/run'], filesystem_types=['tmpfs'], fallback=True)
    
    if tempfile.found_mem_tempdir():
        print('We could use any of the followig paths: {}'.format(tempfile.get_usable_mem_tempdir_paths()))
        print('And we are using now: {}'.format(tempfile.gettempdir()))
    
    with tempfile.NamedTemporaryFile() as ntf:
        # use it as usual...
        pass
#! /usr/bin/python3

# -*- coding: utf-8 -*-

import dill
import gzip
import os

from memory_tempfile import MemoryTempfile
tempfile = MemoryTempfile()

PATH_ROOT_DIR = os.path.dirname(os.path.abspath(__file__)).replace("\\",
                                                                   "/") + "/"

f = tempfile.NamedTemporaryFile(prefix="Test", suffix=".txt")
TEMP_DIR = f.name[:f.name.rfind("/")] + "/"

TEMP_DIR_OBJS = TEMP_DIR + f"python_objects/"
if not os.path.exists(TEMP_DIR_OBJS):
    os.makedirs(TEMP_DIR_OBJS)


def save_dict_object(d, file_name_prefix):
    with gzip.open(TEMP_DIR_OBJS + file_name_prefix + '.pkl.gz', 'wb') as f:
        dill.dump(d, f)


def load_dict_object(file_name_prefix):
    with gzip.open(TEMP_DIR_OBJS + file_name_prefix + '.pkl.gz', 'rb') as f:
        d = dill.load(f)
    return d
예제 #5
0
# We now do not want to use /dev/shm or /run/shm and no ramfs paths
# If /run/user/{uid} is available, we prefer it to /tmp
# And we want to try /var/run as a last resort
# If all fails, fallback to platform's tmp dir

from memory_tempfile import MemoryTempfile
import memory_tempfile

# By the way, all paths with string {uid} will have it replaced with the user id
tempfile = MemoryTempfile(fallback=False)

if tempfile.found_mem_tempdir():
    print('We could use any of the followig paths: {}'.format(
        tempfile.get_usable_mem_tempdir_paths()))
    print('And we are using now: {}'.format(tempfile.gettempdir()))

with tempfile.NamedTemporaryFile() as ntf:
    # use it as usual...
    pass