In a Java application files are created where the filename is a UUID generated from a protein sequence (e.g. TTCCPSIVARSNFNVCRLPGTPEAICATYTGCIIIPGATCPGDYAN) created using the function UUID.nameUUIDFromBytes
. This results in the UUID c6a0deb5-0c4f-3961-9d19-3f0fde0517c2
.
UUID.namedUUIDFromBytes
doesn't take a namespace as a parameter, whereas in python uuid.uuid3
does. According to What namespace does the JDK use to generate a UUID with nameUUIDFromBytes?, the namespace should have been passed as part of the name, but it's no longer possible to change the java code.
Is there a way to create a custom namespace in the python code such that it will produce the same UUID's as the Java code?
The fromString() method of UUID class in Java is used for the creation of UUID from the standard string representation of the same. Parameters: The method takes one parameter UUID_name which is the string representation of the UUID. Return Value: The method returns the actual UUID created from the specified string.
This module provides immutable UUID objects (the UUID class) and the functions uuid1() , uuid3() , uuid4() , uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122. If all you want is a unique ID, you should probably call uuid1() or uuid4() .
UUID, Universal Unique Identifier, is a python library which helps in generating random objects of 128 bits as ids. It provides the uniqueness as it generates ids on the basis of time, Computer hardware (MAC etc.).
nameUUIDFromBytes
only takes one parameter, which is supposed to be the concatenation of the namespace and name just like you say. The namespace parameter is supposed to be a UUID
, and as far as I know, they don't have a null
value defined.
A "null
uuid" can be passed to Python's uuid3
like this. This should work as long as the namespace has a bytes
attribute (tested with Python 2 and 3):
class NULL_NAMESPACE:
bytes = b''
uuid.uuid3(NULL_NAMESPACE, 'TTCCPSIVARSNFNVCRLPGTPEAICATYTGCIIIPGATCPGDYAN')
# returns: UUID('c6a0deb5-0c4f-3961-9d19-3f0fde0517c2')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With