i know python sha1.hexdigest() give the same value of hashed.toHex()
but what i asking for how to get the same value of python sha1.digest()
Added after 6 minutes:
this is the original python method what i'm trying to port it to Qt
def seguid(seq):
"""Returns the SEGUID (string) for a sequence (string or Seq object).
Given a nucleotide or amino-acid secuence (or any string),
returns the SEGUID string (A SEquence Globally Unique IDentifier).
seq type = str.
For more information about SEGUID, see:
[url]http://bioinformatics.anl.gov/seguid/[/url]
DOI: 10.1002/pmic.200600032 """
try:
#Python 2.5 sha1 is in hashlib
import hashlib
m = hashlib.sha1()
except:
#For older versions
import sha
m = sha.new()
import base64
try:
#Assume its a Seq object
seq = seq.tostring()
except AttributeError:
#Assume its a string
pass
m.update(_as_bytes(seq.upper()))
try:
#For Python 3+
return base64.encodebytes(m.digest()).decode().replace("\n","").rstrip("=")
except AttributeError:
pass
try:
#For Python 2.5+
return base64.b64encode(m.digest()).rstrip("=")
except:
#For older versions
import os
#Note: Using os.linesep doesn't work on Windows,
#where os.linesep= "\r\n" but the encoded string
#contains "\n" but not "\r\n"
return base64.encodestring(m.digest()).replace("\n","").rstrip("=")
def seguid(seq):
"""Returns the SEGUID (string) for a sequence (string or Seq object).
Given a nucleotide or amino-acid secuence (or any string),
returns the SEGUID string (A SEquence Globally Unique IDentifier).
seq type = str.
For more information about SEGUID, see:
[url]http://bioinformatics.anl.gov/seguid/[/url]
DOI: 10.1002/pmic.200600032 """
try:
#Python 2.5 sha1 is in hashlib
import hashlib
m = hashlib.sha1()
except:
#For older versions
import sha
m = sha.new()
import base64
try:
#Assume its a Seq object
seq = seq.tostring()
except AttributeError:
#Assume its a string
pass
m.update(_as_bytes(seq.upper()))
try:
#For Python 3+
return base64.encodebytes(m.digest()).decode().replace("\n","").rstrip("=")
except AttributeError:
pass
try:
#For Python 2.5+
return base64.b64encode(m.digest()).rstrip("=")
except:
#For older versions
import os
#Note: Using os.linesep doesn't work on Windows,
#where os.linesep= "\r\n" but the encoded string
#contains "\n" but not "\r\n"
return base64.encodestring(m.digest()).replace("\n","").rstrip("=")
To copy to clipboard, switch view to plain text mode
Bookmarks