Exemple #1
0
 protected void OnRankSplitProcess(object sender, EventArgs e)
 {
     try{
         ParameterizedThreadStart prams = new ParameterizedThreadStart(RankSplit.ProcessRequest);
         Thread        o   = new Thread(prams);
         RankSplitInfo rsi = GatherRankSplitInfo(true);
         o.Start((object)rsi);
     }
     catch (Exception ex)
     {
         MainData.ShowMessageWindow(ex.Message, false);
     }
 }
Exemple #2
0
 protected void OnRankSplitSaveGo(object sender, EventArgs e)
 {
     try{
         ParameterizedThreadStart prams = new ParameterizedThreadStart(RankSplit.ProcessRequest);
         Thread        o   = new Thread(prams);
         RankSplitInfo rsi = GatherRankSplitInfo(false);
         if (RankSplit.PickFileName(out RankSplit.LastFileName))
         {
             o.Start((object)rsi);
         }
     }
     catch (Exception ex)
     {
         MainData.ShowMessageWindow(ex.Message, false);
     }
 }
Exemple #3
0
        private static Dictionary <string, List <T> > ProcessRSplitContainer <T>(RSplitContainer <T> rspc, RankSplitInfo rsi,
                                                                                 Dictionary <string, double> rDict, Dictionary <string, T> outDict, bool seqMatch)
        {
            if (rsi.doSubSet && rsi.SubSetType == SubSetMethod.Previous)
            {
                rspc.AddIDFilterList(rsi.oldIDlist);
            }

            rspc.MergeDictosToList(rDict, outDict, false, seqMatch);

            if (rsi.doSubSet && rsi.SubSetType == SubSetMethod.Current)
            {
                return(rspc.GetDivisionDict(rsi.SplitCount, rsi.subCurMainRank, rsi.subCurSplitCount));
            }
            else
            {
                return(rspc.GetDivisionDict(rsi.SplitCount));
            }
        }
Exemple #4
0
        public static void ProcessRequest(object TheInfo)
        {
            try
            {
                RankSplitInfo info      = TheInfo as RankSplitInfo;
                string        fName     = LastFileName;
                bool          keepGoing = true;
                bool          seqMatch  = false;

                RankMethodSubSequence   = info.SeqDiv;
                OutputMethodSubSequence = info.SeqDivOut;

                if (RankMethodSubSequence == SubSequenceDivision.Normalised)
                {
                    RankStartDiv = info.divStart;
                    RankEndDiv   = info.divEnd;
                }
                if (OutputMethodSubSequence == SubSequenceDivision.Normalised)
                {
                    OutputStartDiv = info.divStartOut;
                    OutputEndDiv   = info.divEndOut;
                }
                if (RankMethodSubSequence == SubSequenceDivision.AbsoluteBases)
                {
                    RankBaseCount = info.baseCount;
                    RankFromStart = info.fromStart;
                }
                if (OutputMethodSubSequence == SubSequenceDivision.AbsoluteBases)
                {
                    OutputFromStart = info.fromStartOut;
                    OutputBaseCount = info.baseCountOut;
                }

                if (info.GraphingType == GraphType.Image && OutputMethodSubSequence != SubSequenceDivision.AbsoluteBases)
                {
                    OutputMethodSubSequence = SubSequenceDivision.AbsoluteBases;
                    OutputFromStart         = !AppSettings.Output.DEFAULT_IMG_FROMEND.Item;
                    OutputBaseCount         = AppSettings.Output.DEFAULT_IMG_BASES.Item;
                }

                if (info.sample != "All")
                {
                    SampleToUse = info.sample;
                    UseSample   = true;
                }
                else
                {
                    UseSample = false;
                }

                if (info.SeqFeature == info.SeqFeature2)
                {
                    seqMatch = true;
                }
                else
                {
                    seqMatch = false;
                }

                if (keepGoing)
                {
                    RSplitContainer <string>         rspcString     = new RSplitContainer <string> ("none", false);
                    RSplitContainer <double>         rspcDouble     = new RSplitContainer <double> (0, false);
                    RSplitContainer <List <double> > rspcListDouble = new RSplitContainer <List <double> > (null, true);

                    Dictionary <string, double> rankDict = Methods [info.RMethod].Invoke(info.SeqFeature);

                    Dictionary <string, string>         baseDict;
                    Dictionary <string, double>         singleDict;
                    Dictionary <string, List <double> > listDict;

                    if (info.doGraph == false)
                    {
                        switch (info.Text)
                        {
                        case OutputMethText.BlastID:
                            baseDict = MainData.Genome.RSPOUTBlastHitID(info.SeqFeature);
                            rspcString.MergeDictosToList(rankDict, baseDict, true, seqMatch);
                            ProcessingClass.WriteDataFile(fName, rspcString.GetData(false));
                            break;

                        case OutputMethText.BaseSeq:
                            baseDict = MainData.Genome.RSPOUTBaseSeq(info.SeqFeature);
                            rspcString.MergeDictosToList(rankDict, baseDict, false, seqMatch);
                            ProcessingClass.WriteDataFile(fName, rspcString.GetData(false));
                            break;

                        case OutputMethText.FastaBase:
                            baseDict = MainData.Genome.RSPOUTBaseSeq(info.SeqFeature);
                            rspcString.MergeDictosToList(rankDict, baseDict, false, seqMatch);
                            rspcString.WriteFastaFile(fName);
                            break;

                        case OutputMethText.SeqNames:
                            baseDict = MainData.Genome.RSPOUTReadName(info.SeqFeature);
                            rspcString.MergeDictosToList(rankDict, baseDict, false, seqMatch);
                            ProcessingClass.WriteDataFile(fName, rspcString.GetData(false));
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        string yLab; string xLab;
                        SetLabels(info.Graph, info.GraphingType, out xLab, out yLab);
                        string title = info.SeqFeature + " ";

                        if (info.doSubSeq)
                        {
                            title += "from ";
                            if (info.SeqDiv == SubSequenceDivision.AbsoluteBases)
                            {
                                title += info.baseCount + " ";
                                if (info.fromStart)
                                {
                                    title += "from start ";
                                }
                                else
                                {
                                    title += "to end ";
                                }
                            }
                            else
                            {
                                title += "division " + info.divStart + "/20 to " + info.divEnd + "/20 ";
                            }
                        }
                        title += "ranked by " + MethodDesc [info.RMethod] + " and split into " + info.SplitCount + " groups";
                        Dictionary <string, List <double> >         procCont;
                        Dictionary <string, List <List <double> > > procContList;

                        switch (info.Graph)
                        {
                        case OutputMethGraph.Expr:
                            singleDict = MainData.Genome.RSPOUTExprValue(info.SeqFeature2);
                            procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                            if (info.GraphingType == GraphType.Histo)
                            {
                                MainData.MakeMultiHistoRankGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else
                            {
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            break;

                        case OutputMethGraph.ExprNorm:
                            singleDict = MainData.Genome.RSPOUTExprNorm(info.SeqFeature2);
                            procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                            if (info.GraphingType == GraphType.Histo)
                            {
                                MainData.MakeMultiHistoRankGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else
                            {
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            break;

                        case OutputMethGraph.ExprVar:
                            singleDict = MainData.Genome.RSPOUTExprRange(info.SeqFeature2);
                            procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                            if (info.GraphingType == GraphType.Histo)
                            {
                                MainData.MakeMultiHistoRankGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else
                            {
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            break;

                        case OutputMethGraph.MethyCov:
                            if (info.GraphingType == GraphType.Spatial)
                            {
                                listDict     = MainData.Genome.RSPOUTMethylCoverageDivision(info.SeqFeature2);
                                procContList = ProcessRSplitContainer <List <double> > (rspcListDouble, info, rankDict, listDict, seqMatch);
                                if (info.SeqDivOut != SubSequenceDivision.AbsoluteBases)
                                {
                                    MainData.MakeMultiBayesRankGraph(procContList, GraphWindow.Global, xLab, yLab, title, rspcListDouble, info.MergeGraphs);
                                }
                                else
                                {
                                    MainData.MakeMultiBayesBaseRankGraph(procContList, GraphWindow.Global, xLab, yLab, title, info.fromStartOut, rspcListDouble, info.MergeGraphs);
                                }
                            }
                            else if (info.GraphingType == GraphType.Means)
                            {
                                singleDict = MainData.Genome.RSPOUTQuantMethyCov(info.SeqFeature2);
                                procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else if (info.GraphingType == GraphType.Image)
                            {
                                //TODO: Make the image!
                            }
                            break;

                        case OutputMethGraph.MethyDepthCov:
                            if (info.GraphingType == GraphType.Spatial)
                            {
                                listDict     = MainData.Genome.RSPOUTMethylCoverageDepthDivision(info.SeqFeature2);
                                procContList = ProcessRSplitContainer <List <double> > (rspcListDouble, info, rankDict, listDict, seqMatch);
                                if (info.SeqDivOut != SubSequenceDivision.AbsoluteBases)
                                {
                                    MainData.MakeMultiBayesRankGraph(procContList, GraphWindow.Global, xLab, yLab, title, rspcListDouble, info.MergeGraphs);
                                }
                                else
                                {
                                    MainData.MakeMultiBayesBaseRankGraph(procContList, GraphWindow.Global, xLab, yLab, title, info.fromStartOut, rspcListDouble, info.MergeGraphs);
                                }
                            }
                            else if (info.GraphingType == GraphType.Means)
                            {
                                singleDict = MainData.Genome.RSPOUTQuantMethyDepthCov(info.SeqFeature2);
                                procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else if (info.GraphingType == GraphType.Histo)
                            {
                                singleDict = MainData.Genome.RSPOUTMethylDepthTotal(info.SeqFeature2);
                                procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                                MainData.MakeMultiHistoRankGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else if (info.GraphingType == GraphType.Image)
                            {
                                listDict     = MainData.Genome.RSPOUTMethylCoverageDepthDivision(info.SeqFeature2);
                                procContList = ProcessRSplitContainer <List <double> > (rspcListDouble, info, rankDict, listDict, seqMatch);
                                MainData.MakeRegionChangeMap(procContList, rspcListDouble, info.MergeGraphs);
                            }
                            break;

                        case OutputMethGraph.BlastE:
                            singleDict = MainData.Genome.RSPBlastEValue(info.SeqFeature2);
                            procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                            if (info.GraphingType == GraphType.Means)
                            {
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else
                            {
                                MainData.MakeMultiHistoRankGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            break;

                        case OutputMethGraph.BlastID:
                            singleDict = MainData.Genome.RSPBlastPercID(info.SeqFeature2);
                            procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                            if (info.GraphingType == GraphType.Means)
                            {
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else
                            {
                                MainData.MakeMultiHistoRankGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            break;

                        case OutputMethGraph.Variant:
                            singleDict = MainData.Genome.RSPOUTQuantVar(info.SeqFeature2);
                            procCont   = ProcessRSplitContainer <double> (rspcDouble, info, rankDict, singleDict, seqMatch);
                            if (info.GraphingType == GraphType.Means)
                            {
                                MainData.MakeRankLineGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            else
                            {
                                MainData.MakeMultiHistoRankGraph(procCont, GraphWindow.Global, xLab, yLab, title, rspcDouble, info.MergeGraphs);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MainData.ShowMessageWindow(e.Message, true);
            }
        }
Exemple #5
0
        protected RankSplitInfo GatherRankSplitInfo(bool isGraph)
        {
            RankMethod      m;
            OutputMethGraph omg;
            OutputMethText  omt;
            GraphType       gt;

            string feature;
            string feature2;

            try{
                m   = RankSplitMethods [rspMethodCombo.ActiveText];
                omg = OutputMethGraph.Expr;
                omt = OutputMethText.BaseSeq;
                gt  = RankSplitGraphDesc[rspGraphTypeCombo.ActiveText];

                if (isGraph)
                {
                    omg = RankSplitGraphOut [rspGraphicalOutputCombo.ActiveText];
                }
                else
                {
                    omt = RankSplitTextOut [rspTextOutputCombo.ActiveText];
                }
            }
            catch (Exception e) {
                throw new Exception("You need to select an option from the combo menu!");
            }

            feature  = rspSequenceCombo.ActiveText;
            feature2 = rspSequenceForCombo.ActiveText;
            bool seqFeaturePass  = false;
            bool seqFeature2Pass = false;

            foreach (string st in RankSplit.GetRelevantFeatures())
            {
                if (st == feature)
                {
                    seqFeaturePass = true;
                }

                if (st == feature2)
                {
                    seqFeature2Pass = true;
                }
            }

            if (!seqFeaturePass || !seqFeature2Pass)
            {
                throw new Exception("You need to choose two features to look at\n they can be the same!");
            }

            RankSplitInfo rsi;

            if (!rspSubDivideCheck.Active)
            {
                if (isGraph)
                {
                    rsi = new RankSplitInfo(m, omg, feature);
                }
                else
                {
                    rsi = new RankSplitInfo(m, omt, feature);
                }
            }
            else
            {
                if (rspBaseCountRadio.Active)
                {
                    int bases;
                    if (!int.TryParse(rspNoBaseEntry.Text, out bases))
                    {
                        throw new Exception("Input -> Unable To Parse Base Count!");
                    }
                    if (bases > 5000)
                    {
                        throw new Exception("Input -> Maximum Number of bases is 5000!");
                    }
                    bool doStart = true;
                    if (rspToEndRadio.Active)
                    {
                        doStart = false;
                    }

                    if (isGraph)
                    {
                        rsi = new RankSplitInfo(m, omg, feature, bases, doStart);
                    }
                    else
                    {
                        rsi = new RankSplitInfo(m, omt, feature, bases, doStart);
                    }
                }
                else
                {
                    int stDiv; int edDiv;

                    if (!int.TryParse(rspStartDivEntry.Text, out stDiv))
                    {
                        throw new Exception("Input -> Unable to Parse Start Division!");
                    }
                    if (!int.TryParse(rspEndDivEntry.Text, out edDiv))
                    {
                        throw new Exception("Input -> Unable to Parse End Division!");
                    }

                    if (stDiv >= edDiv)
                    {
                        throw new Exception("Input -> Start division must be smaller than end!");
                    }
                    if (stDiv > 20 || edDiv > 20)
                    {
                        throw new Exception("Input -> Division limit is 20.");
                    }

                    if (isGraph)
                    {
                        rsi = new RankSplitInfo(m, omg, feature, stDiv, edDiv);
                    }
                    else
                    {
                        rsi = new RankSplitInfo(m, omt, feature, stDiv, edDiv);
                    }
                }
            }

            rsi.SeqFeature2  = feature2;
            rsi.GraphingType = gt;

            if (rspSubDivideCheck2.Active)
            {
                rsi.doSubSeqOut = true;

                if (rspPickNormaliseRadio2.Active)
                {
                    rsi.SeqDivOut = SubSequenceDivision.Normalised;

                    int stDiv2;
                    int edDiv2;

                    if (!int.TryParse(rspStartDivEntry2.Text, out stDiv2))
                    {
                        throw new Exception("Output -> Unable to Parse Start Division!");
                    }
                    if (!int.TryParse(rspEndDivEntry2.Text, out edDiv2))
                    {
                        throw new Exception("Output -> Unable to Parse End Division!");
                    }

                    if (stDiv2 >= edDiv2)
                    {
                        throw new Exception("Output -> Start division must be smaller than end!");
                    }
                    if (stDiv2 > 20 || edDiv2 > 20)
                    {
                        throw new Exception("Output -> Division limit is 20.");
                    }

                    rsi.divStartOut = stDiv2;
                    rsi.divEndOut   = edDiv2;
                }
                else
                {
                    rsi.SeqDivOut = SubSequenceDivision.AbsoluteBases;

                    int bases2;
                    if (!int.TryParse(rspNoBaseEntry2.Text, out bases2))
                    {
                        throw new Exception("Output -> Unable To Parse Base Count!");
                    }
                    if (bases2 > 5000)
                    {
                        throw new Exception("Output -> Maximum Number of bases is 5000!");
                    }
                    bool doStart2 = true;
                    if (rspToEndRadio2.Active)
                    {
                        doStart2 = false;
                    }

                    rsi.baseCountOut = bases2;
                    rsi.fromStartOut = doStart2;
                }
            }
            int splitInt;

            if (!int.TryParse(rspRankDivEntry.Text, out splitInt))
            {
                throw new Exception("Rank Division - please enter a positive integer.");
            }
            rsi.SplitCount = splitInt;

            if (rspDoSubDivCheck.Active)
            {
                rsi.doSubSet = true;
                if (rspSubDivNextRadio.Active)
                {
                    rsi.SubSetType = SubSetMethod.Current;
                    int mainRank; int splitRank;

                    if (!int.TryParse(rspSubTakeGroupEntry.Text, out mainRank))
                    {
                        throw new Exception("Unable to parse Sub-Set 'take group' entry, please enter a positive integer.");
                    }
                    if (!int.TryParse(rspSubAndSplitEntry.Text, out splitRank))
                    {
                        throw new Exception("Unable to parse Sub-Set 'and split' entry, please enter a positive integer.");
                    }
                    if (mainRank > rsi.SplitCount)
                    {
                        throw new Exception("'Take Group' value must be lower than or equal to the split count.");
                    }
                    else if (mainRank < 1)
                    {
                        throw new Exception("'Take Group' value too low, please enter a positive integer.");
                    }
                    if (splitRank < 1)
                    {
                        throw new Exception("'And Split' value too low, please enter a positive integer.");
                    }
                    rsi.subCurMainRank   = mainRank;
                    rsi.subCurSplitCount = splitRank;
                }
                else
                {
                    rsi.SubSetType = SubSetMethod.Previous;
                    int fromGroup; int toGroup;

                    if (!int.TryParse(rspSubFromGroupEntry.Text, out fromGroup))
                    {
                        throw new Exception("Unable to parse Sub-Set 'from group' entry, please enter a positive integer.");
                    }
                    if (!int.TryParse(rspSubToGroupEntry.Text, out toGroup))
                    {
                        throw new Exception("Unable to parse Sub-Set 'to group' entry, please enter a positive integer.");
                    }
                    if (fromGroup > OldRSPSize)
                    {
                        throw new Exception("'From Group' must be lower than or equal to the previous Split-Count");
                    }
                    if (toGroup > OldRSPSize)
                    {
                        throw new Exception("'To Group' must be lower than or equal to the previous Split-Count");
                    }
                    if (toGroup < fromGroup)
                    {
                        throw new Exception("'To Group' should be higher than or equal to 'From Group'");
                    }
                    rsi.subOldEndRank   = toGroup;
                    rsi.subOldStartRank = fromGroup;

                    rsi.oldIDlist = RSPGetOldIDList(fromGroup, toGroup);
                }
            }
            else
            {
                rsi.doSubSet   = false;
                rsi.SubSetType = SubSetMethod.None;
            }

            if (rspMergeGraphCheck.Active)
            {
                rsi.MergeGraphs = true;
            }
            else
            {
                rsi.MergeGraphs = false;
            }

            try {
                rsi.sample = rspSampleCombo.ActiveText;
            }
            catch (Exception e) {
                throw new Exception("You need to select one or all samples from the drop-down menu!");
            }

            OldRSPSize = rsi.SplitCount;
            rspMergeGraphCheck.Active = false;
            return(rsi);
        }