示例#1
0
    private void PrepareDataForVisualisation()
    {
        DataManager.DataStruct data = DataManager.getInstance().GetData();

        genomeSize = gameObject.GetComponent <LogicManager>().GetGenomeSize();

        int totalCutPositionsInFullDigest = 0;

        for (int i = 0; i < data._enzymes.Length; i++)
        {
            totalCutPositionsInFullDigest += data._enzymes[i].cutPositions.Length;
        }

        finalDataForVisualisation = new DataManager.CutPosition[totalCutPositionsInFullDigest];

        int arrayIndex = 0;

        for (int i = 0; i < data._enzymes.Length; i++)
        {
            for (int y = 0; y < data._enzymes[i].cutPositions.Length; y++)
            {
                finalDataForVisualisation[arrayIndex].position      = data._enzymes[i].cutPositions[y];
                finalDataForVisualisation[arrayIndex].enzymeIndexID = data._enzymes[i].indexID;
                arrayIndex++;
            }
        }

        //Order the array based on cut position
        Array.Sort(finalDataForVisualisation, (x, y) => x.position.CompareTo(y.position));

        isDataPrepared = true;
    }
    private void PopulateTextFields()
    {
        DataManager.DataStruct data = DataManager.getInstance().GetData();
        UIManager.getInstance().numberOfEnzymesTextField.text = "Number of Enzymes = " + data._enzymes.Length;
        for (int i = 0; i < data._enzymes.Length; i++)
        {
            UIManager.getInstance().enzymeTextFields[i].text = data._enzymes[i].name + ": ";
            for (int x = 0; x < data._enzymes[i].numberOfFragments; x++)
            {
                UIManager.getInstance().enzymeTextFields[i].text += data._enzymes[i].fragmentSizes[x] + ", ";
            }
        }

        UIManager.getInstance().numberOfMultiDigestsTextField.text = "Number of MultiDigests = " + data._digests.Length;

        for (int i = 0; i < data._digests.Length; i++)
        {
            string s = "";
            for (int y = 0; y < data._digests[i].enzymesInDigest.Length; y++)
            {
                s += DataManager.getInstance().GetEnzymeName(data._digests[i].enzymesInDigest[y]);
                if (y < data._digests[i].enzymesInDigest.Length - 1)
                {
                    s += " & ";
                }
            }
            UIManager.getInstance().multiDigestTextFields[i].text = s + ":  ";             //+ multiDigestTextFields[i].text;

            for (int x = 0; x < data._digests[i].numberOfFragments; x++)
            {
                UIManager.getInstance().multiDigestTextFields[i].text += data._digests[i].fragmentSizes[x] + ", ";
            }
        }
    }
    public void DataReview()
    {
        string textToShow  = "";
        string enzymeNames = "Enzymes:";

        DataManager.DataStruct data = DataManager.getInstance().GetData();
        for (int i = 0; i < data._enzymes.Length; i++)
        {
            enzymeNames += data._enzymes[i].name;
            textToShow  += data._enzymes[i].name + ": ";
            for (int x = 0; x < data._enzymes[i].fragmentSizes.Length; x++)
            {
                textToShow += data._enzymes[i].fragmentSizes[x];
                if (x < data._enzymes[i].fragmentSizes.Length - 1)
                {
                    textToShow += ", ";
                }
            }
            if (i < data._enzymes.Length - 1)
            {
                enzymeNames += ", ";
            }
            textToShow += "\n";
        }

        textToShow = "Review Data:\n\n" + enzymeNames + "\n\nSingle-enzyme digest fragments:\n" + textToShow + "\nMulti-enzyme Digests:\n";
        for (int i = 0; i < data._digests.Length; i++)
        {
            textToShow += data._digests[i].name + ": ";
            for (int x = 0; x < data._digests[i].fragmentSizes.Length; x++)
            {
                textToShow += data._digests[i].fragmentSizes[x];
                if (x < data._digests[i].fragmentSizes.Length - 1)
                {
                    textToShow += ", ";
                }
            }
            textToShow += "\n";
        }
        reviewDataParent.transform.Find("Text").GetComponent <Text>().text = textToShow;
    }
    public void DisplayFullData()
    {
        DataManager.DataStruct data = DataManager.getInstance().GetData();
        arrayLengthsText.text = "Data\nEnzymes Array Length = " + data._enzymes.Length + "\nDigests Array Length = " + data._digests.Length;

        for (int i = 0; i < data._enzymes.Length; i++)
        {
            int    arrayIndex        = i;
            string enzymeName        = data._enzymes[i].name;
            int    enzymeIndex       = data._enzymes[i].indexID;
            int    numberOfFragments = data._enzymes[i].numberOfFragments;
            string fragmentSizes     = "";
            for (int x = 0; x < data._enzymes[i].numberOfFragments; x++)
            {
                fragmentSizes += data._enzymes[i].fragmentSizes[x] + ", ";
            }
            string cutPositions = "";
            if (data._enzymes[i].cutPositions != null)
            {
                for (int x = 0; x < data._enzymes[i].cutPositions.Length; x++)
                {
                    cutPositions += data._enzymes[i].cutPositions[x] + ", ";
                }
            }
            string originalCutPositions = "";
            if (data._enzymes[i].originalCutPositions != null)
            {
                for (int x = 0; x < data._enzymes[i].originalCutPositions.Length; x++)
                {
                    originalCutPositions += data._enzymes[i].originalCutPositions[x] + ", ";
                }
            }

            enzymesText[i].text = "Enzymes [" + arrayIndex + "]\nName: " + enzymeName + "\nIndexID: " + enzymeIndex + "\nNumber of fragments: " + numberOfFragments + "\nFragment Sizes: " + fragmentSizes + "\nCut Positions: " + cutPositions + "\nOriginal Cut Positions: " + originalCutPositions;
        }
    }
示例#5
0
    private bool CalculationAlgorithm()
    {
        //Initialise DataSet
        //DataManager.DataStruct loadedData = DataManager.getInstance().GetData();
        loadedData   = DataManager.getInstance().GetData();
        enzymes      = loadedData._enzymes;
        multiDigests = loadedData._digests;
        genomeSize   = CalculateGenomeSize(enzymes[0].fragmentSizes);

        //Check data for errors
        for (int i = 0; i < enzymes.Length; i++)
        {
            if (enzymes[i].fragmentSizes.Length == 0)
            {
                errorMessage = "Enzyme " + enzymes[i].name + " digest has no fragments. Calculation aborted.";
                return(false);
            }
        }

        for (int i = 0; i < enzymes.Length; i++)
        {
            enzymes[i].cutPositions         = CreateCutPositions(enzymes[i].fragmentSizes);
            enzymes[i].originalCutPositions = new int[enzymes[i].cutPositions.Length];
            enzymes[i].cutPositions.CopyTo(enzymes[i].originalCutPositions, 0);
        }

        for (int i = 0; i < multiDigests.Length; i++)
        {
            multiDigests[i].digestCutPositions = new DataManager.CutPosition[multiDigests[i].numberOfFragments];
        }


        #region DEBUGGING!!!

        //Enzymes
        for (int i = 0; i < enzymes.Length; i++)
        {
            Debug.Log("_____");
            Debug.Log("Enzyme " + i + " | Name = " + enzymes[i].name);
            Debug.Log("Enzyme " + i + " | indexID = " + enzymes[i].indexID);
            Debug.Log("Enzyme " + i + " | Number Of Fragments = " + enzymes[i].numberOfFragments);

            string fragmentSizes = "{ ";
            for (int x = 0; x < enzymes[i].fragmentSizes.Length - 1; x++)
            {
                fragmentSizes += enzymes[i].fragmentSizes[x] + ", ";
            }
            fragmentSizes += enzymes[i].fragmentSizes[enzymes[i].fragmentSizes.Length - 1] + " }";
            Debug.Log("Enzyme " + i + " | Fragment Sizes = " + fragmentSizes);

            string cutPositions = "{ ";
            for (int x = 0; x < enzymes[i].cutPositions.Length - 1; x++)
            {
                fragmentSizes += enzymes[i].cutPositions[x] + ", ";
            }
            cutPositions += enzymes[i].cutPositions[enzymes[i].cutPositions.Length - 1] + " }";
            Debug.Log("Enzyme " + i + " | Cut Positions = " + cutPositions);
            Debug.Log("Enzyme " + i + " | Cut positions length = " + enzymes[i].cutPositions.Length);
        }

        //Multi Digests
        for (int i = 0; i < multiDigests.Length; i++)
        {
            Debug.Log("_____");
            Debug.Log("MultiDigest " + i + " | Name = " + multiDigests[i].name);
            Debug.Log("MultiDigest " + i + " | Number Of Fragments = " + multiDigests[i].numberOfFragments);

            string fragmentSizes = "{ ";
            for (int x = 0; x < multiDigests[i].fragmentSizes.Length - 1; x++)
            {
                fragmentSizes += multiDigests[i].fragmentSizes[x] + ", ";
            }
            fragmentSizes += multiDigests[i].fragmentSizes[multiDigests[i].fragmentSizes.Length - 1] + " }";
            Debug.Log("MultiDigest " + i + " | Fragment Sizes = " + fragmentSizes);

            string enzymesInDigest = "{ ";
            for (int x = 0; x < multiDigests[i].enzymesInDigest.Length - 1; x++)
            {
                enzymesInDigest += multiDigests[i].enzymesInDigest[x] + ", ";
            }
            enzymesInDigest += multiDigests[i].enzymesInDigest[multiDigests[i].enzymesInDigest.Length - 1] + " }";
            Debug.Log("MultiDigest " + i + " | Enzymes In Digest = " + enzymesInDigest);
        }

        #endregion



        //Complete all multidigests
        #region Instructions
        for (int i = 0; i < multiDigests.Length; i++)
        {
            bool isSuccessful  = false;
            int  attemptNumber = 1;
            if (MultiDigestCutPositionsFromSingleDigests(i))
            {
                isSuccessful  = true;
                attemptNumber = 1;
            }
            else
            {
                FlipEnzymeCutPositions(enzymes[multiDigests[i].enzymesInDigest[1]].cutPositions).CopyTo(enzymes[multiDigests[i].enzymesInDigest[1]].cutPositions, 0);
                ResetCutPositions(multiDigests[i].enzymesInDigest[0]);
                if (MultiDigestCutPositionsFromSingleDigests(i))
                {
                    isSuccessful  = true;
                    attemptNumber = 2;
                }
            }

            if (isSuccessful)
            {
                Debug.Log("Success " + i + " Attempt " + attemptNumber);
                for (int x = 0; x < multiDigests[i].enzymesInDigest.Length; x++)
                {
                    PrintArray(enzymes[multiDigests[i].enzymesInDigest[x]].name + ": ", enzymes[multiDigests[i].enzymesInDigest[x]].cutPositions);
                }
            }
            else
            {
                errorMessage = "Multidigest " + i + " failed to solve";
                return(false);
            }
        }
        #endregion

        //Final Solve

        if (!RandomAlignmentToSolve())
        {
            //Calculations have failed.
            HelperMethods.WriteToFile("Critical Failure");
            UIManager.getInstance().ErrorMessage("Critical Failure");
            Debug.Log("Critical Failure");
            MainManager.getInstance().CalculationsComplete(false);
            return(false);
        }

        return(true);
    }