<commit_before>package org.broad.igv.sam;

import java.awt.Color;

import org.broad.igv.sam.AlignmentTrack.BisulfiteContext;

/**
 * @author benb
 *         <NAME>, University of Southern California
 *         <p/>
 *         Note that this is only currently supporting a single bisulfite protocol with the following assumptions:
 *         - The first end of paired end reads have C->T variants, while the second ends have G->A
 *         - Bisulfite only affects one strand.  So for the first end, you don't see G->A and for the
 *         second end you don't see C->T.  This allows us to detect true C->T genomic changes by examining
 *         the strand opposite the bisulfite event (we use the DEAMINATION_COLOR for these variants).
 *         <p/>
 *         This is the Illumina protocol published by Joe Ecker lab (Lister et al. 2009, Lister et al. 2011)
 *         and our lab (Berman et al. 2011)
 */
public class BisulfiteBaseInfo {


    public enum DisplayStatus {
        NOTHING, COLOR, CHARACTER
    }

    // Constants
    public static Color CYTOSINE_MISMATCH_COLOR = Color.orange; //Color.black;
    public static Color NONCYTOSINE_MISMATCH_COLOR = Color.orange;
    public static Color DEAMINATION_COLOR = new Color(139, 94, 60);
    public static Color METHYLATED_COLOR = Color.red;
    public static Color UNMETHYLATED_COLOR = Color.blue;


    // Private vars
    private DisplayStatus[] displayStatus = null;
    private byte[] displayChars = null;
    private Color[] displayColors = null;
    private BisulfiteContext myContext = null;
    private boolean flipRead;


    /**
     * We require loading this once for the entire alignment so that we don't have to calculate reverse complements
     * more than once.
     *
     * @param inReference
     * @param block
     * @param bisulfiteContext
     */
    public BisulfiteBaseInfo(byte[] inReference, AlignmentBlock block, BisulfiteContext bisulfiteContext) {
        super();

        myContext = bisulfiteContext;
        byte[] inRead = block.getBases();
        int alignmentLen = inRead.length;

//		System.err.printf("Block=%s, alignment=%s\n", block, block.getBaseAlignment());
        final Alignment baseAlignment = block.getBaseAlignment();

        // We will only need reverse complement if the strand and paired end status don't match (2nd ends are G->A)
        if (baseAlignment.isPaired()) {
            flipRead = (baseAlignment.isPaired() && (baseAlignment.isNegativeStrand() ^ baseAlignment.isSecondOfPair()));
        } else {
            flipRead = baseAlignment.isNegativeStrand();
        }
        byte[] read = (flipRead) ? AlignmentUtils.reverseComplementCopy(inRead) : inRead;
        byte[] reference = (flipRead) ? AlignmentUtils.reverseComplementCopy(inReference) : inReference;


        displayChars = new byte[alignmentLen];
        displayStatus = new DisplayStatus[alignmentLen];
        displayColors = new Color[alignmentLen];

        final int idxEnd = alignmentLen - 1;
        for (int idxFw = 0; idxFw < alignmentLen; idxFw++) {

            //// Everything comes in relative to the positive strand.
            int idx = flipRead ? (idxEnd - idxFw) : idxFw;
<commit_msg>Add null check for reference to BisulfiteBaseInfo.  Reference can be null for various reasons, e.g. soft clip reads that hang over the edge of a chromosome.<commit_after>package org.broad.igv.sam;

import java.awt.Color;

import org.broad.igv.sam.AlignmentTrack.BisulfiteContext;

/**
 * @author benb
 *         <NAME>, University of Southern California
 *         <p/>
 *         Note that this is only currently supporting a single bisulfite protocol with the following assumptions:
 *         - The first end of paired end reads have C->T variants, while the second ends have G->A
 *         - Bisulfite only affects one strand.  So for the first end, you don't see G->A and for the
 *         second end you don't see C->T.  This allows us to detect true C->T genomic changes by examining
 *         the strand opposite the bisulfite event (we use the DEAMINATION_COLOR for these variants).
 *         <p/>
 *         This is the Illumina protocol published by <NAME>cker lab (Lister et al. 2009, Lister et al. 2011)
 *         and our lab (Berman et al. 2011)
 */
public class BisulfiteBaseInfo {


    public enum DisplayStatus {
        NOTHING, COLOR, CHARACTER
    }

    // Constants
    public static Color CYTOSINE_MISMATCH_COLOR = Color.orange; //Color.black;
    public static Color NONCYTOSINE_MISMATCH_COLOR = Color.orange;
    public static Color DEAMINATION_COLOR = new Color(139, 94, 60);
    public static Color METHYLATED_COLOR = Color.red;
    public static Color UNMETHYLATED_COLOR = Color.blue;


    // Private vars
    private DisplayStatus[] displayStatus = null;
    private byte[] displayChars = null;
    private Color[] displayColors = null;
    private BisulfiteContext myContext = null;
    private boolean flipRead;


    /**
     * We require loading this once for the entire alignment so that we don't have to calculate reverse complements
     * more than once.
     *
     * @param inReference
     * @param block
     * @param bisulfiteContext
     */
    public BisulfiteBaseInfo(byte[] inReference, AlignmentBlock block, BisulfiteContext bisulfiteContext) {
        super();

        myContext = bisulfiteContext;
        byte[] inRead = block.getBases();
        int alignmentLen = inRead.length;

//		System.err.printf("Block=%s, alignment=%s\n", block, block.getBaseAlignment());
        final Alignment baseAlignment = block.getBaseAlignment();

        // We will only need reverse complement if the strand and paired end status don't match (2nd ends are G->A)
        if (baseAlignment.isPaired()) {
            flipRead = (baseAlignment.isPaired() && (baseAlignment.isNegativeStrand() ^ baseAlignment.isSecondOfPair()));
        } else {
            flipRead = baseAlignment.isNegativeStrand();
        }
        byte[] read = (flipRead) ? AlignmentUtils.reverseComplementCopy(inRead) : inRead;
        byte[] reference = (flipRead && inReference != null) ? AlignmentUtils.reverseComplementCopy(inReference) : inReference;


        displayChars = new byte[alignmentLen];
        displayStatus = new DisplayStatus[alignmentLen];
        displayColors = new Color[alignmentLen];

        final int idxEnd = alignmentLen - 1;
        for (int idxFw = 0; idxFw < alignmentLen; idxFw++) {

            //// Everything comes in relative to the positive strand.
            int idx = flipRead ? (idxEnd - idxFw) : idxFw;

{'fraction_non_alphanumeric': 0.0864461045891142, 'fraction_numerical': 0.006708339685927733, 'mean_word_length': 2.8497652582159625, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6637136', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1771, 'n_words': 630}