/** * Returns the uppercased version of the bases * * @param bases the bases * @return the upper cased version */ static public void convertToUpperCase(final byte[] bases) { StringUtil.toUpperCase(bases); }
/** * Convert bases in place into canonical form, upper case, and with no-call represented as N. * * @param bases byte array of bases to "normalize", in place. */ static void normalizeBases(final byte[] bases) { for (int i = 0; i < bases.length; ++i) { bases[i] = StringUtil.toUpperCase(bases[i]); if (bases[i] == '.') { bases[i] = 'N'; } } }
/** * Convert bases in place into canonical form, upper case, and with no-call represented as N. * * @param bases byte array of bases to "normalize", in place. */ static void normalizeBases(final byte[] bases) { for (int i = 0; i < bases.length; ++i) { bases[i] = StringUtil.toUpperCase(bases[i]); if (bases[i] == '.') { bases[i] = 'N'; } } }
/** * Convert bases in place into canonical form, upper case, and with no-call represented as N. * * @param bases byte array of bases to "normalize", in place. */ static void normalizeBases(final byte[] bases) { for (int i = 0; i < bases.length; ++i) { bases[i] = StringUtil.toUpperCase(bases[i]); if (bases[i] == '.') { bases[i] = 'N'; } } }
/** * @return true if this is a valid base, i.e. one of [ACGTacgt] */ public static boolean isValidBase(final byte base) { switch(StringUtil.toUpperCase(base)) { case 'A': case 'C': case 'G': case 'T': return true; default: return false; } }
/** * Convert bases in place into canonical form, upper case, and with no-call represented as N. * @param bases */ static void normalizeBases(final byte[] bases) { for (int i = 0; i < bases.length; ++i) { bases[i] = StringUtil.toUpperCase(bases[i]); if (bases[i] == '.') { bases[i] = 'N'; } } }
/** * @return true if this is a valid base, i.e. one of [ACGTacgt] */ public static boolean isValidBase(final byte base) { switch(StringUtil.toUpperCase(base)) { case 'A': case 'C': case 'G': case 'T': return true; default: return false; } }
private byte[] addToCache(final String sequenceName, final byte[] bases) { // Normalize to upper case only. We can't use the cram normalization utility Utils.normalizeBases, since // we don't want to normalize ambiguity codes, we can't use SamUtils.normalizeBases, since we don't want // to normalize no-call ('.') bases. for (int i = 0; i < bases.length; i++) { bases[i] = StringUtil.toUpperCase(bases[i]); } cacheW.put(sequenceName, new WeakReference<>(bases)); return bases; }
private byte[] addToCache(final String sequenceName, final byte[] bases) { // Normalize to upper case only. We can't use the cram normalization utility Utils.normalizeBases, since // we don't want to normalize ambiguity codes, we can't use SamUtils.normalizeBases, since we don't want // to normalize no-call ('.') bases. for (int i = 0; i < bases.length; i++) { bases[i] = StringUtil.toUpperCase(bases[i]); } cacheW.put(sequenceName, new WeakReference<>(bases)); return bases; }
/** Converts a pair of bases into a DiploidGenotype regardless of base order or case */ public static DiploidGenotype fromBases(final byte base1, final byte base2) { final byte first = StringUtil.toUpperCase(base1); final byte second = StringUtil.toUpperCase(base2); final DiploidGenotype genotype = genotypes.get(first + second); if (genotype == null) { throw new IllegalArgumentException("Unknown genotype string [" + StringUtil.bytesToString(new byte[] {base1, base2}) + "], any pair of ACTG case insensitive is acceptable"); } return genotype; }
/** Converts a pair of bases into a DiploidGenotype regardless of base order or case */ public static DiploidGenotype fromBases(final byte base1, final byte base2) { final byte first = StringUtil.toUpperCase(base1); final byte second = StringUtil.toUpperCase(base2); final DiploidGenotype genotype = genotypes.get(first + second); if (genotype == null) { throw new IllegalArgumentException("Unknown genotype string [" + StringUtil.bytesToString(new byte[] {base1, base2}) + "], any pair of ACTG case insensitive is acceptable"); } return genotype; }
/** * Convert the given reference sequence into a form suitable for building into * on-the-fly sequences. * @param referenceSequence The reference sequence to normalize. * @throws org.broadinstitute.gatk.utils.exceptions.ReviewedGATKException if normalized sequence cannot be generated. */ private static void normalizeReferenceSequence(byte[] referenceSequence) { StringUtil.toUpperCase(referenceSequence); for(byte base: referenceSequence) { if(base != 'A' && base != 'C' && base != 'G' && base != 'T') throw new ReviewedGATKException(String.format("Base type %c is not supported when building references on-the-fly",(char)base)); } } }
public Snp(final String name, final String chrom, final int pos, final byte allele1, final byte allele2, final double maf, final List<String> fingerprintPanels) { this.name = name; this.chrom = chrom; this.pos = pos; this.allele1 = StringUtil.toUpperCase(allele1); this.allele2 = StringUtil.toUpperCase(allele2); this.maf = maf; this.fingerprintPanels = fingerprintPanels == null ? new ArrayList<String>() : fingerprintPanels; // Construct the genotypes for ease of comparison this.genotypes[0] = DiploidGenotype.fromBases(allele1, allele1); this.genotypes[1] = DiploidGenotype.fromBases(allele1, allele2); this.genotypes[2] = DiploidGenotype.fromBases(allele2, allele2); }
public Snp(final String name, final String chrom, final int pos, final byte allele1, final byte allele2, final double maf, final List<String> fingerprintPanels) { this.name = name; this.chrom = chrom; this.pos = pos; this.allele1 = StringUtil.toUpperCase(allele1); this.allele2 = StringUtil.toUpperCase(allele2); this.maf = maf; this.fingerprintPanels = fingerprintPanels == null ? new ArrayList<String>() : fingerprintPanels; // Construct the genotypes for ease of comparison this.genotypes[0] = DiploidGenotype.fromBases(allele1, allele1); this.genotypes[1] = DiploidGenotype.fromBases(allele1, allele2); this.genotypes[2] = DiploidGenotype.fromBases(allele2, allele2); }
protected Allele(final byte[] bases, final boolean isRef) { // null alleles are no longer allowed if ( wouldBeNullAllele(bases) ) { throw new IllegalArgumentException("Null alleles are not supported"); } // no-calls are represented as no bases if ( wouldBeNoCallAllele(bases) ) { this.bases = EMPTY_ALLELE_BASES; isNoCall = true; if ( isRef ) throw new IllegalArgumentException("Cannot tag a NoCall allele as the reference allele"); return; } if ( wouldBeSymbolicAllele(bases) ) { isSymbolic = true; if ( isRef ) throw new IllegalArgumentException("Cannot tag a symbolic allele as the reference allele"); } else { StringUtil.toUpperCase(bases); } this.isRef = isRef; this.bases = bases; if ( ! acceptableAlleleBases(bases, isRef) ) throw new IllegalArgumentException("Unexpected base in allele bases \'" + new String(bases)+"\'"); }
protected Allele(final byte[] bases, final boolean isRef) { // null alleles are no longer allowed if ( wouldBeNullAllele(bases) ) { throw new IllegalArgumentException("Null alleles are not supported"); } // no-calls are represented as no bases if ( wouldBeNoCallAllele(bases) ) { this.bases = EMPTY_ALLELE_BASES; isNoCall = true; if ( isRef ) throw new IllegalArgumentException("Cannot tag a NoCall allele as the reference allele"); return; } if ( wouldBeSymbolicAllele(bases) ) { isSymbolic = true; if ( isRef ) throw new IllegalArgumentException("Cannot tag a symbolic allele as the reference allele"); } else { StringUtil.toUpperCase(bases); } this.isRef = isRef; this.bases = bases; if ( ! acceptableAlleleBases(bases, isRef) ) throw new IllegalArgumentException("Unexpected base in allele bases \'" + new String(bases)+"\'"); }
public static int[] calculateRefWindowsByGc(final int windows, final File referenceSequence, final int windowSize) { final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceSequence); ReferenceSequence ref; final int [] windowsByGc = new int [windows]; while ((ref = refFile.nextSequence()) != null) { final byte[] refBases = ref.getBases(); StringUtil.toUpperCase(refBases); final int refLength = refBases.length; final int lastWindowStart = refLength - windowSize; final CalculateGcState state = new GcBiasUtils().new CalculateGcState(); for (int i = 1; i < lastWindowStart; ++i) { final int windowEnd = i + windowSize; final int gcBin = calculateGc(refBases, i, windowEnd, state); if (gcBin != -1) windowsByGc[gcBin]++; } } return windowsByGc; }
public static int[] calculateRefWindowsByGc(final int windows, final File referenceSequence, final int windowSize) { final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceSequence); ReferenceSequence ref; final int [] windowsByGc = new int [windows]; while ((ref = refFile.nextSequence()) != null) { final byte[] refBases = ref.getBases(); StringUtil.toUpperCase(refBases); final int refLength = refBases.length; final int lastWindowStart = refLength - windowSize; final CalculateGcState state = new GcBiasUtils().new CalculateGcState(); for (int i = 1; i < lastWindowStart; ++i) { final int windowEnd = i + windowSize; final int gcBin = calculateGc(refBases, i, windowEnd, state); if (gcBin != -1) windowsByGc[gcBin]++; } } return windowsByGc; }
/** * Create one SAMSequenceRecord from a single fasta sequence */ private SAMSequenceRecord makeSequenceRecord(final ReferenceSequence refSeq) { final SAMSequenceRecord ret = new SAMSequenceRecord(refSeq.getName(), refSeq.length()); // Compute MD5 of upcased bases final byte[] bases = refSeq.getBases(); for (int i = 0; i < bases.length; ++i) { bases[i] = StringUtil.toUpperCase(bases[i]); } ret.setAttribute(SAMSequenceRecord.MD5_TAG, md5Hash(bases)); if (GENOME_ASSEMBLY != null) { ret.setAttribute(SAMSequenceRecord.ASSEMBLY_TAG, GENOME_ASSEMBLY); } ret.setAttribute(SAMSequenceRecord.URI_TAG, URI); if (SPECIES != null) { ret.setAttribute(SAMSequenceRecord.SPECIES_TAG, SPECIES); } return ret; }
/** * Create one SAMSequenceRecord from a single fasta sequence */ private SAMSequenceRecord makeSequenceRecord(final ReferenceSequence refSeq) { final SAMSequenceRecord ret = new SAMSequenceRecord(refSeq.getName(), refSeq.length()); // Compute MD5 of upcased bases final byte[] bases = refSeq.getBases(); for (int i = 0; i < bases.length; ++i) { bases[i] = StringUtil.toUpperCase(bases[i]); } ret.setAttribute(SAMSequenceRecord.MD5_TAG, md5Hash(bases)); if (GENOME_ASSEMBLY != null) { ret.setAttribute(SAMSequenceRecord.ASSEMBLY_TAG, GENOME_ASSEMBLY); } ret.setAttribute(SAMSequenceRecord.URI_TAG, URI); if (SPECIES != null) { ret.setAttribute(SAMSequenceRecord.SPECIES_TAG, SPECIES); } return ret; }