Пример #1
0
def SequenceLoader(raw_file):
    sequence_data = None
    sequence_hydrophobicity = None
    invalid = False

    if raw_file is not None:

        try:
            decoded = decode_raw_file(raw_file)
        except UnicodeDecodeError:
            return None, None, True

        fasta = SeqIO.parse(StringIO(decoded), "fasta")
        records = [record for record in fasta]

        if records is not None and any(records):
            data_raw = list(records[0].seq._data)
            if any([residue not in protein.letters
                    for residue in data_raw]) or len(data_raw) == 0:
                invalid = True
            else:
                sequence_hydrophobicity = compress_data(
                    get_hydrophobicity(data_raw))
                sequence_data = compress_data(data_raw)
        else:
            invalid = True

    return sequence_data, sequence_hydrophobicity, invalid
Пример #2
0
    def test_1(self):
        test_input = {
            b'dummy_key_1': compress_data(['dummy_value_1', 'dummy_value_2']),
            b'dummy_key_2': compress_data(['dummy_value_3', 'dummy_value_4'])
        }
        expected_output = {
            b'dummy_key_1': ['dummy_value_1', 'dummy_value_2'],
            b'dummy_key_2': ['dummy_value_3', 'dummy_value_4']
        }

        self.assertDictEqual(expected_output,
                             session_utils.decompress_session(test_input))
Пример #3
0
def upload_sequence(fname, fcontent, session_id, cache, logger):
    logger.info('Session {} sequence upload triggered'.format(session_id))

    if cache.hexists(session_id, fname):
        logger.info('Session {} filename {} already exists'.format(
            session_id, fname))
        return no_update, None, components.RepeatedInputModal(fname)
    if cache.hexists(session_id, cache_utils.CacheKeys.SEQUENCE.value):
        logger.info(
            'Session {} sequence dataset already uploaded'.format(session_id))
        return no_update, None, components.SequenceAlreadyUploadedModal()

    sequence_data, seq_hydrophobicity, invalid = loaders.SequenceLoader(
        fcontent)

    if invalid:
        logger.info('Session {} file {} is invalid sequence file'.format(
            session_id, fname))
        return no_update, None, components.InvalidFormatModal()

    mismatched = check_sequence_mismatch(session_id, cache,
                                         len(decompress_data(sequence_data)))
    if any(mismatched):
        logger.info('Session {} mismatch {} sequence file detected'.format(
            session_id, fname))
        return no_update, None, components.MismatchSequenceModal(*mismatched)

    logger.info('Session {} uploads {} - sequence'.format(session_id, fname))
    cache.hset(session_id, fname, sequence_data)
    cache.hset(session_id, cache_utils.CacheKeys.SEQUENCE_HYDROPHOBICITY.value,
               seq_hydrophobicity)
    cache.hset(session_id, cache_utils.CacheKeys.SEQUENCE.value,
               compress_data(fname))
    return components.FilenameAlert(
        fname, loaders.DatasetReference.SEQUENCE.value), None, None
Пример #4
0
    def test_1(self):
        dummy_raw_file = 'data:application/octet-stream;base64,PnRyfFc5RFkyOHxXOURZMjhfTUVUVEkgUHV0YXRpdmUgbWVtYnJhbmU'\
                         'gcHJvdGVpbiBPUz1NZXRoYW5vbG9idXMgdGluZGFyaXVzIERTTSAyMjc4IE9YPTEwOTAzMjIgR049TWV0dGlEUkFGVF8'\
                         'yMDU1IFBFPTQgU1Y9MQpNU0xFQVRWTERMTFNTRlBIV0xBVE1WSUdBTVBJRkVMUkdBSVBJQUxHSVlETVNQVlNBRklGQVZ'\
                         'MR05NSVBWVlBMTExGTERQVlNUWUxSUkZBSUZES0ZGU1dMRkdSVEhSTkhTRVJGRUtZR1RMQUxUTEZWQVZQTFBWVEdBV1R'\
                         'HQ0FBQUZWRkdJS0ZSSEFGUEFJTEFHVkxJQUdJSVZTU1ZUTEdHSUdMVkRMRlMKCg=='

        expected_data = compress_data([
            'M', 'S', 'L', 'E', 'A', 'T', 'V', 'L', 'D', 'L', 'L', 'S', 'S',
            'F', 'P', 'H', 'W', 'L', 'A', 'T', 'M', 'V', 'I', 'G', 'A', 'M',
            'P', 'I', 'F', 'E', 'L', 'R', 'G', 'A', 'I', 'P', 'I', 'A', 'L',
            'G', 'I', 'Y', 'D', 'M', 'S', 'P', 'V', 'S', 'A', 'F', 'I', 'F',
            'A', 'V', 'L', 'G', 'N', 'M', 'I', 'P', 'V', 'V', 'P', 'L', 'L',
            'L', 'F', 'L', 'D', 'P', 'V', 'S', 'T', 'Y', 'L', 'R', 'R', 'F',
            'A', 'I', 'F', 'D', 'K', 'F', 'F', 'S', 'W', 'L', 'F', 'G', 'R',
            'T', 'H', 'R', 'N', 'H', 'S', 'E', 'R', 'F', 'E', 'K', 'Y', 'G',
            'T', 'L', 'A', 'L', 'T', 'L', 'F', 'V', 'A', 'V', 'P', 'L', 'P',
            'V', 'T', 'G', 'A', 'W', 'T', 'G', 'C', 'A', 'A', 'A', 'F', 'V',
            'F', 'G', 'I', 'K', 'F', 'R', 'H', 'A', 'F', 'P', 'A', 'I', 'L',
            'A', 'G', 'V', 'L', 'I', 'A', 'G', 'I', 'I', 'V', 'S', 'S', 'V',
            'T', 'L', 'G', 'G', 'I', 'G', 'L', 'V', 'D', 'L', 'F', 'S',
            'dummy_fname'
        ])

        data, invalid = SequenceLoader(dummy_raw_file, 'dummy_fname')
        self.assertFalse(invalid)
        self.assertEqual(data, expected_data)
Пример #5
0
def initiate_session(cache, logger, expire_time=3600):
    session_id = str(uuid.uuid4())
    logger.info('New session initiated {}'.format(session_id))
    cache.hset(session_id, cache_utils.CacheKeys.ID.value,
               compress_data(session_id))
    cache.expire(session_id, expire_time)
    return session_id
Пример #6
0
def user_login(username, password, session_id, cache, logger):
    if postgres_utils.userlogin(username, password):
        logger.info('Session {} login user {}'.format(session_id, username))
        cache.hset(session_id, cache_utils.CacheKeys.USER.value,
                   compress_data(username))
        return False, components.SuccessLoginAlert(
            username), components.UserPortalCardBody(username)
    else:
        return True, None, no_update
Пример #7
0
def prepare_session_storage(session):
    for key in (b'id', b'user', b'session_pkid'):
        if key in session:
            del session[key]

    key_list = list(session.keys())
    for key in key_list:
        session[key.decode()] = decompress_data(session[key])
        del session[key]

    return compress_data(session)
Пример #8
0
def create_user(username, password, email, session_id, cache, logger):
    if any([True for x in (username, password, email)
            if x is None or x == '']):
        return True, None, no_update, no_update, no_update, no_update
    try:
        postgres_utils.create_user(username, password, email)
        logger.info('Session {} created user {} - {}'.format(
            session_id, username, email))
        cache.hset(session_id, cache_utils.CacheKeys.USER.value,
                   compress_data(username))
        return False, components.SuccessCreateUserModal(
            username), None, None, None, no_update
    except (UserExists, EmailAlreadyUsed, IntegrityError) as e:
        return True, None, no_update, no_update, no_update, no_update
Пример #9
0
    def test_3(self):
        dummy_raw_file = 'data:application/octet-stream;base64,NTAgWCA1OCBYIDAgMC45OTk5MDg5CjUxIFggNTggWCAwIDAuOTk5ODk' \
                         '3ODQKMTQzIFggMTg1IFggMCAwLjk5OTg5NDMKMTQwIFggMTUyIFggMCAwLjk5OTg3Nzc1CjE0OCBYIDE5MCBYIDAgMC4' \
                         '5OTk4NzU0CjUwIFggMTUzIFggMCAwLjk5OTg2MjIKMTQ1IFggMTE3IFggMCAwLjk5OTg1NTY0CjEzOSBYIDEwMSBYIDA' \
                         'gMC45OTk4Mjc1CjE0MSBYIDE5MyBYIDAgMC45OTk4MjIzCgo='

        expected_data = compress_data([[58, 50, 0.9999089],
                                       [58, 51, 0.99989784],
                                       [185, 143, 0.9998943],
                                       [152, 140, 0.99987775],
                                       [190, 148, 0.9998754],
                                       [153, 50, 0.9998622],
                                       [145, 117, 0.99985564],
                                       [139, 101, 0.9998275],
                                       [193, 141, 0.9998223]])

        data, invalid = Loader(dummy_raw_file, 'EVFOLD')
        self.assertFalse(invalid)
        self.assertEqual(data, expected_data)
Пример #10
0
def Loader(raw_file, input_format):
    data = None
    invalid = False

    if raw_file is not None:
        try:
            if input_format != ContactInformationFormats.trROSETTA_NPZ.name:
                decoded = decode_raw_file(raw_file)
                data_raw = ParserFormats.__dict__[input_format](decoded,
                                                                input_format)
            else:
                data_raw = ParserFormats.__dict__[input_format](raw_file,
                                                                input_format)
            data = compress_data(data_raw)
        except (InvalidFormat, UnicodeDecodeError) as e:
            data = None
            invalid = True

    return data, invalid
Пример #11
0
def retrieve_session(session_pkid):
    session = None
    username = None
    session_name = None
    session_data = perform_query(SqlQueries.RETRIEVE_SESSION.value, args=(session_pkid,), fetch=True)

    if session_data:
        perform_query(SqlQueries.UPDATE_LAST_ACCESS.value,
                      args=(datetime.datetime.now().strftime("%Y-%m-%d"), session_pkid), commit=True)
        session_data = session_data[0]
        now = datetime.datetime.now().strftime("%Y-%m-%d")
        perform_query(SqlQueries.UPDATE_SESSION_DATE.value, args=(now, session_pkid), commit=False)
        username = session_data[0]
        session_name = session_data[1]
        session = decompress_data(session_data[2])
        for key in session.keys():
            session[key] = compress_data(session[key])

    return username, session_name, session
Пример #12
0
    def test_1(self):
        dummy_raw_file = 'data:application/octet-stream;base64,TEVOIDE2OAoxIDEwIDEKMTAgMTUgMgo0MCA' \
                         '1NSA3CjU1IDg1IDgKODUgOTkgOQoxMDAgMTYwIDEwCg=='
        expected_data = compress_data([
            1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 'NAN', 'NAN', 'NAN',
            'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN',
            'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN', 'NAN',
            'NAN', 'NAN', 'NAN', 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
            8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
            8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
            9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
            10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
            10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
            10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 'NAN', 'NAN', 'NAN',
            'NAN', 'NAN', 'NAN', 'NAN', 'NAN'
        ])

        data, invalid = Loader(dummy_raw_file, 'CUSTOM')
        self.assertFalse(invalid)
        self.assertEqual(data, expected_data)
Пример #13
0
def SequenceLoader(raw_file, fname):
    data = None
    invalid = False

    if raw_file is not None:

        decoded = decode_raw_file(raw_file)
        fasta = SeqIO.parse(StringIO(decoded), "fasta")
        records = [record for record in fasta]

        if records is not None and any(records):
            data_raw = list(records[0].seq._data)
            if any([residue not in protein.letters
                    for residue in data_raw]) or len(data_raw) == 0:
                invalid = True
            else:
                data_raw.append(fname)
                data = compress_data(data_raw)
        else:
            invalid = True

    return data, invalid
Пример #14
0
fpaths = glob('./a3d/a3d/*a3d')
ratio = 8
n_layers = 30
ifplot = False
output_dir = './outputs2'

if os.path.exists(output_dir):
    pass
else:
    os.mkdir(output_dir)

for fpath in fpaths:
    fname = utils.get_name(fpath)
    data_ = utils.read_data(fpath)
    data = utils.compress_data(data_, ratio)
    bita, _ = utils.ostu3d(data)  # binary data
    layers = np.hstack([
        np.linspace(0, bita.shape[2] // 2, n_layers // 3, dtype=np.int16),
        np.linspace(bita.shape[2] // 2 + 1,
                    bita.shape[2] - 1,
                    n_layers // 3 * 2,
                    dtype=np.int16)
    ])
    x, y, z, b, d, flags = pose.frame_gen(bita,
                                          layers,
                                          ratio=ratio,
                                          penalty=1,
                                          min_thresh=15,
                                          verbose=False,
                                          if_plot_frame=False)