public static void convertQuality ( Text quality , BaseQualityEncoding current , BaseQualityEncoding target ) { if ( current == target ) throw new IllegalArgumentException ( "current and target quality encodinds are the same (" + current + ")" ) ; byte [ ] bytes = quality . getBytes ( ) ; final int len = quality . getLength ( ) ; final int illuminaSangerDistance = FormatConstants . ILLUMINA_OFFSET - FormatConstants . SANGER_OFFSET ; if ( current == BaseQualityEncoding . Illumina && target == BaseQualityEncoding . Sanger ) { for ( int i = 0 ; i < len ; ++ i ) { if ( bytes [ i ] < FormatConstants . ILLUMINA_OFFSET || bytes [ i ] > ( FormatConstants . ILLUMINA_OFFSET + FormatConstants . ILLUMINA_MAX ) ) { throw new FormatException ( "base quality score out of range for Illumina Phred+64 format (found " + ( bytes [ i ] - FormatConstants . ILLUMINA_OFFSET ) + " but acceptable range is [0," + FormatConstants . ILLUMINA_MAX + "]).\n" + "Maybe qualities are encoded in Sanger format?\n" ) ; } bytes [ i ] -= illuminaSangerDistance ; } } else if ( current == BaseQualityEncoding . Sanger && target == BaseQualityEncoding . Illumina ) { for ( int i = 0 ; i < len ; ++ i ) { if ( bytes [ i ] < FormatConstants . SANGER_OFFSET || bytes [ i ] > ( FormatConstants . SANGER_OFFSET + FormatConstants . SANGER_MAX ) ) { throw new FormatException ( "base quality score out of range for Sanger Phred+64 format (found " + ( bytes [ i ] - FormatConstants . SANGER_OFFSET ) + " but acceptable range is [0," + FormatConstants . SANGER_MAX + "]).\n" + "Maybe qualities are encoded in Illumina format?\n" ) ; } bytes [ i ] += illuminaSangerDistance ; } } else throw new IllegalArgumentException ( "unsupported BaseQualityEncoding transformation from " + current + " to " + target ) ; }
Convert quality scores in - place .