Skip to content

Instantly share code, notes, and snippets.

@goraj
Created March 2, 2018 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goraj/7ba1e9b0a556ae070caf540dd455c211 to your computer and use it in GitHub Desktop.
Save goraj/7ba1e9b0a556ae070caf540dd455c211 to your computer and use it in GitHub Desktop.
def offset_version_detection(quality_string = ''):
"""Tries to detect phred score offset automatically.
Args:
quality_string used to estimate format version and offset
Returns:
Phred offset
Raises:
ValueError: Cannot evaluate empty quality string
ValueError: Cannot evaluate phred offset
"""
pass
sanger_offset = 33
illumina_offset = 64
if len(quality_string) == 0:
raise ValueError('Cannot evaluate empty quality string')
minimum_value = min([ord(x) for x in quality_string])
#minimum value needs to be at least 64 for versions [1.3, 1.8)
if minimum_value-illumina_offset >= 0:
return illumina_offset
#minimum value needs to be at least 33 for sanger
elif minimum_value-sanger_offset >= 0:
return sanger_offset
raise ValueError('Cannot evaluate phred offset')
def phred_score(character, offset):
return ord(character)-offset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment