public static void ImportMasses()
 {
     AminoAcidMasses();
     NeoFindAmbiguity.ReadMassDictionary();
 }
Example #2
0
        public static void ExportCandidates(List <NeoPsm> psms, Ms2ScanWithSpecificMass[] spectra, string path, CommonParameters commonParameters)
        {
            using (StreamWriter file = new StreamWriter(path + folder + @"\" + folder + "ExportedFusionCandidatesAll.txt"))
            {
                file.WriteLine("Scan" + '\t' + "ExperimentalMass" + '\t' + "OriginalNSequence" + '\t' + "OriginalNScore" + '\t' + "OriginalCSequence" + '\t' + "OriginalCScore" + '\t' + "SampleSequence" + '\t' + "Ambiguity" + '\t' + "ProbableType" + '\t' + "MostProbableSequenceJunctions" + '\t' + "MostProbableSequence(s)" + '\t' + "MostProbableParents" + '\t' + "AllPossibleSequenceJunctions" + '\t' + "AllPossibleSequence(s)" + '\t' + "AllPossibleParent(s)" + '\t' + "NumberOfPossibleSequences" + '\t' + "PotentialFalsePositives" + '\t' + "TotalScore");

                //double progress = 0;
                Parallel.ForEach(psms, new ParallelOptions {
                    MaxDegreeOfParallelism = commonParameters.MaxThreadsToUsePerFile
                }, (psm) =>
                {
                    Ms2ScanWithSpecificMass spectrum = spectra[psm.scanNumber];
                    //printout the scan, the mass, the sequences with and without junctions, the number of potential sequences
                    string allPossibleSequences             = "";
                    string mostProbableSequences            = "";
                    int indexOfFirstProbableSequence        = -1;
                    string mostProbableParents              = "";
                    string allPossibleParents               = "";
                    FusionCandidate.FusionType probableType = psm.fusionType;
                    for (int fc = 0; fc < psm.candidates.Count(); fc++)
                    {
                        FusionCandidate fusionCandidate = psm.candidates[fc]; //need fc for indexOfFirstProbableSequence
                        char[] tempArray = fusionCandidate.seq.ToCharArray();
                        //if most probable, add to all and most
                        if (fusionCandidate.fusionType.Equals(probableType))
                        {
                            //record sequences
                            if (indexOfFirstProbableSequence < 0)
                            {
                                indexOfFirstProbableSequence = fc;
                            }
                            for (int i = 0; i < tempArray.Count(); i++)
                            {
                                mostProbableSequences += tempArray[i];
                                allPossibleSequences  += tempArray[i];
                                foreach (int junction in fusionCandidate.junctionIndexes)
                                {
                                    if (junction == i)
                                    {
                                        mostProbableSequences += "-";
                                        allPossibleSequences  += "-";
                                    }
                                }
                            }
                            mostProbableSequences += "|";
                            allPossibleSequences  += "|";

                            //record parents
                            string tempParents = "";
                            //switch (probableType)
                            //{
                            //    case FusionCandidate.FusionType.TL:
                            //        if (fusionCandidate.translatedParents.Count == 0)
                            //            throw new Exception();
                            //        tempParents += GenerateParentOutput(fusionCandidate.translatedParents, new List<CisParent>(), new List<TransParent>());
                            //        break;

                            //    case FusionCandidate.FusionType.NC:
                            //    case FusionCandidate.FusionType.RC:
                            //        if (fusionCandidate.cisParents.Count == 0)
                            //            throw new Exception();
                            //        tempParents += GenerateParentOutput(new List<TranslatedParent>(), fusionCandidate.cisParents, new List<TransParent>());
                            //        break;

                            //    default: //if trans
                            //        if (fusionCandidate.transParents.Count == 0)
                            //            throw new Exception();
                            //        tempParents += GenerateParentOutput(new List<TranslatedParent>(), new List<CisParent>(), fusionCandidate.transParents);
                            //        break;
                            //}
                            mostProbableParents += tempParents;
                            allPossibleParents  += tempParents;
                        }
                        else //not most probable, only add it to allPossibleSequences
                        {
                            //record sequences
                            for (int i = 0; i < tempArray.Count(); i++)
                            {
                                allPossibleSequences += tempArray[i];
                                if (fusionCandidate.junctionIndexes.Contains(i))
                                {
                                    allPossibleSequences += "-";
                                }
                            }
                            allPossibleSequences += "|";
                            //record parents
                            //UNCOMMENT   allPossibleParents += GenerateParentOutput(fusionCandidate.translatedParents, fusionCandidate.cisParents, fusionCandidate.transParents);
                        }

                        /*        foreach(ParentInfo PI in fusionCandidate.parentInfo)
                         *      {
                         *          parents += PI.accession + "_" + PI.parentType.ToString() + "_" + PI.seqFound + "|";
                         *      }*/
                    }

                    allPossibleSequences  = allPossibleSequences.Substring(0, allPossibleSequences.Length - 1);   //remove last "|"
                    mostProbableSequences = mostProbableSequences.Substring(0, mostProbableSequences.Length - 1); //remove last "|"

                    string ambiguity = "";
                    NeoFindAmbiguity.FindIons(psm.candidates[indexOfFirstProbableSequence], psm, spectrum); //this should be carried over, but it's not...
                                                                                                            //      mutableError_message += e;
                    bool[] foundIons = psm.candidates[indexOfFirstProbableSequence].foundIons;
                    char[] firstSeq  = psm.candidates[indexOfFirstProbableSequence].seq.ToCharArray();
                    //   if(foundIons.Count()==firstSeq.Count()) //prevent crashing if something went wrong
                    // {
                    bool ambiguous = false;
                    for (int i = 1; i < foundIons.Length; i++)
                    {
                        if (foundIons[i])                 //if found
                        {
                            ambiguity += firstSeq[i - 1]; //add aa
                            if (ambiguous)                //if it is part of an ambiguous sequence
                            {
                                ambiguity += ")";
                                ambiguous  = false; //no longer ambiguous
                            }
                        }
                        else
                        {
                            if (!ambiguous)
                            {
                                ambiguous  = true;
                                ambiguity += "(";
                            }
                            ambiguity += firstSeq[i - 1];
                        }
                    }
                    ambiguity += firstSeq[foundIons.Length - 1];
                    if (ambiguous)
                    {
                        ambiguity += ")";
                    }
                    string potentialFalsePositives = "";
                    //foreach (Variant v in psm.variants)
                    //{
                    //    potentialFalsePositives += v.id + "_" + v.start + "-" + (v.start + v.peptideLength - 1) + "(" + v.pepSeq + ")" + v.varType + "|";
                    //}
                    if (potentialFalsePositives.Length > 0)
                    {
                        potentialFalsePositives = potentialFalsePositives.Substring(0, potentialFalsePositives.Length - 1); //remove last |
                        if (potentialFalsePositives.Length > 30000)
                        {
                            potentialFalsePositives = potentialFalsePositives.Substring(0, 30000);
                        }
                    }
                    //workarounds for excel. Actual limit is 32767, but that doesn't seem to work
                    if (mostProbableParents.Length > 30000)
                    {
                        mostProbableParents = mostProbableParents.Substring(0, 30000);
                    }
                    if (allPossibleParents.Length > 30000)
                    {
                        allPossibleParents = allPossibleParents.Substring(0, 30000);
                    }
                    int score = 0;
                    foreach (bool b in psm.candidates[indexOfFirstProbableSequence].foundIons)
                    {
                        if (b)
                        {
                            score++;
                        }
                    }
                    lock (file)
                    {
                        file.WriteLine(psm.scanNumber.ToString() + '\t' + psm.expMass.ToString() + '\t' + psm.nInfo.seq + '\t' + psm.nInfo.score + '\t' + psm.cInfo.seq + '\t' + psm.cInfo.score + '\t' + psm.candidates[indexOfFirstProbableSequence].seq + '\t' + ambiguity + '\t' + psm.fusionType.ToString() + '\t' + mostProbableSequences + '\t' + mostProbableSequences.Replace("-", "") + '\t' + mostProbableParents + '\t' + allPossibleSequences + '\t' + allPossibleSequences.Replace("-", "") + '\t' + allPossibleParents + '\t' + psm.candidates.Count().ToString() + '\t' + potentialFalsePositives + '\t' + score);
                        //progress++;
                        //this.worker.ReportProgress((int)(progress / psms.Count() * 100));
                    }
                });
            }

            using (StreamWriter file = new StreamWriter(path + folder + @"\" + folder + "ExportedFusionCandidatesTL.txt"))
            {
                file.WriteLine("Scan" + '\t' + "ExperimentalMass" + '\t' + "OriginalNSequence" + '\t' + "OriginalNScore" + '\t' + "OriginalCSequence" + '\t' + "OriginalCScore" + '\t' + "SampleSequence" + '\t' + "Ambiguity" + '\t' + "ProbableType" + '\t' + "MostProbableSequenceJunctions" + '\t' + "MostProbableSequence(s)" + '\t' + "MostProbableParents" + '\t' + "AllPossibleSequenceJunctions" + '\t' + "AllPossibleSequence(s)" + '\t' + "AllPossibleParent(s)" + '\t' + "NumberOfPossibleSequences" + '\t' + "PotentialFalsePositives" + '\t' + "TotalScore");

                Parallel.ForEach(psms, new ParallelOptions {
                    MaxDegreeOfParallelism = commonParameters.MaxThreadsToUsePerFile
                }, (psm) =>
                {
                    if (psm.candidates.Any(x => x.fusionType == FusionCandidate.FusionType.TL))
                    {
                        Ms2ScanWithSpecificMass spectrum = spectra[psm.scanNumber];
                        //printout the scan, the mass, the sequences with and without junctions, the number of potential sequences
                        string allPossibleSequences             = "";
                        string mostProbableSequences            = "";
                        int indexOfFirstProbableSequence        = -1;
                        string mostProbableParents              = "";
                        string allPossibleParents               = "";
                        FusionCandidate.FusionType probableType = psm.fusionType;
                        for (int fc = 0; fc < psm.candidates.Count(); fc++)
                        {
                            FusionCandidate fusionCandidate = psm.candidates[fc]; //need fc for indexOfFirstProbableSequence
                            if (fusionCandidate.fusionType != FusionCandidate.FusionType.TL)
                            {
                                continue;
                            }
                            char[] tempArray = fusionCandidate.seq.ToCharArray();
                            //if most probable, add to all and most

                            //record sequences
                            if (indexOfFirstProbableSequence < 0)
                            {
                                indexOfFirstProbableSequence = fc;
                            }
                            for (int i = 0; i < tempArray.Count(); i++)
                            {
                                mostProbableSequences += tempArray[i];
                                allPossibleSequences  += tempArray[i];
                                foreach (int junction in fusionCandidate.junctionIndexes)
                                {
                                    if (junction == i)
                                    {
                                        mostProbableSequences += "-";
                                        allPossibleSequences  += "-";
                                    }
                                }
                            }
                            mostProbableSequences += "|";
                            allPossibleSequences  += "|";

                            //record parents
                            string tempParents = "";

                            mostProbableParents += tempParents;
                            allPossibleParents  += tempParents;
                        }

                        allPossibleSequences  = allPossibleSequences.Substring(0, allPossibleSequences.Length - 1);   //remove last "|"
                        mostProbableSequences = mostProbableSequences.Substring(0, mostProbableSequences.Length - 1); //remove last "|"

                        string ambiguity = "";
                        NeoFindAmbiguity.FindIons(psm.candidates[indexOfFirstProbableSequence], psm, spectrum); //this should be carried over, but it's not...
                                                                                                                //      mutableError_message += e;
                        bool[] foundIons = psm.candidates[indexOfFirstProbableSequence].foundIons;
                        char[] firstSeq  = psm.candidates[indexOfFirstProbableSequence].seq.ToCharArray();

                        bool ambiguous = false;
                        for (int i = 1; i < foundIons.Length; i++)
                        {
                            if (foundIons[i])                 //if found
                            {
                                ambiguity += firstSeq[i - 1]; //add aa
                                if (ambiguous)                //if it is part of an ambiguous sequence
                                {
                                    ambiguity += ")";
                                    ambiguous  = false; //no longer ambiguous
                                }
                            }
                            else
                            {
                                if (!ambiguous)
                                {
                                    ambiguous  = true;
                                    ambiguity += "(";
                                }
                                ambiguity += firstSeq[i - 1];
                            }
                        }
                        ambiguity += firstSeq[foundIons.Length - 1];
                        if (ambiguous)
                        {
                            ambiguity += ")";
                        }
                        string potentialFalsePositives = "";

                        if (potentialFalsePositives.Length > 0)
                        {
                            potentialFalsePositives = potentialFalsePositives.Substring(0, potentialFalsePositives.Length - 1); //remove last |
                            if (potentialFalsePositives.Length > 30000)
                            {
                                potentialFalsePositives = potentialFalsePositives.Substring(0, 30000);
                            }
                        }
                        //workarounds for excel. Actual limit is 32767, but that doesn't seem to work
                        if (mostProbableParents.Length > 30000)
                        {
                            mostProbableParents = mostProbableParents.Substring(0, 30000);
                        }
                        if (allPossibleParents.Length > 30000)
                        {
                            allPossibleParents = allPossibleParents.Substring(0, 30000);
                        }
                        int score = 0;
                        foreach (bool b in psm.candidates[indexOfFirstProbableSequence].foundIons)
                        {
                            if (b)
                            {
                                score++;
                            }
                        }
                        lock (file)
                        {
                            file.WriteLine(psm.scanNumber.ToString() + '\t' + psm.expMass.ToString() + '\t' + psm.nInfo.seq + '\t' + psm.nInfo.score + '\t' + psm.cInfo.seq + '\t' + psm.cInfo.score + '\t' + psm.candidates[indexOfFirstProbableSequence].seq + '\t' + ambiguity + '\t' + psm.fusionType.ToString() + '\t' + mostProbableSequences + '\t' + mostProbableSequences.Replace("-", "") + '\t' + mostProbableParents + '\t' + allPossibleSequences + '\t' + allPossibleSequences.Replace("-", "") + '\t' + allPossibleParents + '\t' + psm.candidates.Count().ToString() + '\t' + potentialFalsePositives + '\t' + score);
                            //progress++;
                            //this.worker.ReportProgress((int)(progress / psms.Count() * 100));
                        }
                    }
                });
            }

            using (StreamWriter file = new StreamWriter(path + folder + @"\" + folder + "ExportedFusionCandidatesNC.txt"))
            {
                file.WriteLine("Scan" + '\t' + "ExperimentalMass" + '\t' + "OriginalNSequence" + '\t' + "OriginalNScore" + '\t' + "OriginalCSequence" + '\t' + "OriginalCScore" + '\t' + "SampleSequence" + '\t' + "Ambiguity" + '\t' + "ProbableType" + '\t' + "MostProbableSequenceJunctions" + '\t' + "MostProbableSequence(s)" + '\t' + "MostProbableParents" + '\t' + "AllPossibleSequenceJunctions" + '\t' + "AllPossibleSequence(s)" + '\t' + "AllPossibleParent(s)" + '\t' + "NumberOfPossibleSequences" + '\t' + "PotentialFalsePositives" + '\t' + "TotalScore");

                Parallel.ForEach(psms, new ParallelOptions {
                    MaxDegreeOfParallelism = commonParameters.MaxThreadsToUsePerFile
                }, (psm) =>
                {
                    if (psm.candidates.Any(x => x.fusionType == FusionCandidate.FusionType.NC))
                    {
                        Ms2ScanWithSpecificMass spectrum = spectra[psm.scanNumber];
                        //printout the scan, the mass, the sequences with and without junctions, the number of potential sequences
                        string allPossibleSequences             = "";
                        string mostProbableSequences            = "";
                        int indexOfFirstProbableSequence        = -1;
                        string mostProbableParents              = "";
                        string allPossibleParents               = "";
                        FusionCandidate.FusionType probableType = psm.fusionType;
                        for (int fc = 0; fc < psm.candidates.Count(); fc++)
                        {
                            FusionCandidate fusionCandidate = psm.candidates[fc]; //need fc for indexOfFirstProbableSequence
                            if (fusionCandidate.fusionType != FusionCandidate.FusionType.NC)
                            {
                                continue;
                            }
                            char[] tempArray = fusionCandidate.seq.ToCharArray();
                            //if most probable, add to all and most

                            //record sequences
                            if (indexOfFirstProbableSequence < 0)
                            {
                                indexOfFirstProbableSequence = fc;
                            }
                            for (int i = 0; i < tempArray.Count(); i++)
                            {
                                mostProbableSequences += tempArray[i];
                                allPossibleSequences  += tempArray[i];
                                foreach (int junction in fusionCandidate.junctionIndexes)
                                {
                                    if (junction == i)
                                    {
                                        mostProbableSequences += "-";
                                        allPossibleSequences  += "-";
                                    }
                                }
                            }
                            mostProbableSequences += "|";
                            allPossibleSequences  += "|";

                            //record parents
                            string tempParents = "";

                            mostProbableParents += tempParents;
                            allPossibleParents  += tempParents;
                        }

                        allPossibleSequences  = allPossibleSequences.Substring(0, allPossibleSequences.Length - 1);   //remove last "|"
                        mostProbableSequences = mostProbableSequences.Substring(0, mostProbableSequences.Length - 1); //remove last "|"

                        string ambiguity = "";
                        NeoFindAmbiguity.FindIons(psm.candidates[indexOfFirstProbableSequence], psm, spectrum); //this should be carried over, but it's not...
                                                                                                                //      mutableError_message += e;
                        bool[] foundIons = psm.candidates[indexOfFirstProbableSequence].foundIons;
                        char[] firstSeq  = psm.candidates[indexOfFirstProbableSequence].seq.ToCharArray();

                        bool ambiguous = false;
                        for (int i = 1; i < foundIons.Length; i++)
                        {
                            if (foundIons[i])                 //if found
                            {
                                ambiguity += firstSeq[i - 1]; //add aa
                                if (ambiguous)                //if it is part of an ambiguous sequence
                                {
                                    ambiguity += ")";
                                    ambiguous  = false; //no longer ambiguous
                                }
                            }
                            else
                            {
                                if (!ambiguous)
                                {
                                    ambiguous  = true;
                                    ambiguity += "(";
                                }
                                ambiguity += firstSeq[i - 1];
                            }
                        }
                        ambiguity += firstSeq[foundIons.Length - 1];
                        if (ambiguous)
                        {
                            ambiguity += ")";
                        }
                        string potentialFalsePositives = "";

                        if (potentialFalsePositives.Length > 0)
                        {
                            potentialFalsePositives = potentialFalsePositives.Substring(0, potentialFalsePositives.Length - 1); //remove last |
                            if (potentialFalsePositives.Length > 30000)
                            {
                                potentialFalsePositives = potentialFalsePositives.Substring(0, 30000);
                            }
                        }
                        //workarounds for excel. Actual limit is 32767, but that doesn't seem to work
                        if (mostProbableParents.Length > 30000)
                        {
                            mostProbableParents = mostProbableParents.Substring(0, 30000);
                        }
                        if (allPossibleParents.Length > 30000)
                        {
                            allPossibleParents = allPossibleParents.Substring(0, 30000);
                        }
                        int score = 0;
                        foreach (bool b in psm.candidates[indexOfFirstProbableSequence].foundIons)
                        {
                            if (b)
                            {
                                score++;
                            }
                        }
                        lock (file)
                        {
                            file.WriteLine(psm.scanNumber.ToString() + '\t' + psm.expMass.ToString() + '\t' + psm.nInfo.seq + '\t' + psm.nInfo.score + '\t' + psm.cInfo.seq + '\t' + psm.cInfo.score + '\t' + psm.candidates[indexOfFirstProbableSequence].seq + '\t' + ambiguity + '\t' + psm.fusionType.ToString() + '\t' + mostProbableSequences + '\t' + mostProbableSequences.Replace("-", "") + '\t' + mostProbableParents + '\t' + allPossibleSequences + '\t' + allPossibleSequences.Replace("-", "") + '\t' + allPossibleParents + '\t' + psm.candidates.Count().ToString() + '\t' + potentialFalsePositives + '\t' + score);
                            //progress++;
                            //this.worker.ReportProgress((int)(progress / psms.Count() * 100));
                        }
                    }
                });
            }

            using (StreamWriter file = new StreamWriter(path + folder + @"\" + folder + "ExportedFusionCandidatesTS.txt"))
            {
                file.WriteLine("Scan" + '\t' + "ExperimentalMass" + '\t' + "OriginalNSequence" + '\t' + "OriginalNScore" + '\t' + "OriginalCSequence" + '\t' + "OriginalCScore" + '\t' + "SampleSequence" + '\t' + "Ambiguity" + '\t' + "ProbableType" + '\t' + "MostProbableSequenceJunctions" + '\t' + "MostProbableSequence(s)" + '\t' + "MostProbableParents" + '\t' + "AllPossibleSequenceJunctions" + '\t' + "AllPossibleSequence(s)" + '\t' + "AllPossibleParent(s)" + '\t' + "NumberOfPossibleSequences" + '\t' + "PotentialFalsePositives" + '\t' + "TotalScore");

                Parallel.ForEach(psms, new ParallelOptions {
                    MaxDegreeOfParallelism = commonParameters.MaxThreadsToUsePerFile
                }, (psm) =>
                {
                    if (psm.candidates.Any(x => x.fusionType == FusionCandidate.FusionType.TS))
                    {
                        Ms2ScanWithSpecificMass spectrum = spectra[psm.scanNumber];
                        //printout the scan, the mass, the sequences with and without junctions, the number of potential sequences
                        string allPossibleSequences             = "";
                        string mostProbableSequences            = "";
                        int indexOfFirstProbableSequence        = -1;
                        string mostProbableParents              = "";
                        string allPossibleParents               = "";
                        FusionCandidate.FusionType probableType = psm.fusionType;
                        for (int fc = 0; fc < psm.candidates.Count(); fc++)
                        {
                            FusionCandidate fusionCandidate = psm.candidates[fc]; //need fc for indexOfFirstProbableSequence
                            if (fusionCandidate.fusionType != FusionCandidate.FusionType.TS)
                            {
                                continue;
                            }
                            char[] tempArray = fusionCandidate.seq.ToCharArray();
                            //if most probable, add to all and most

                            //record sequences
                            if (indexOfFirstProbableSequence < 0)
                            {
                                indexOfFirstProbableSequence = fc;
                            }
                            for (int i = 0; i < tempArray.Count(); i++)
                            {
                                mostProbableSequences += tempArray[i];
                                allPossibleSequences  += tempArray[i];
                                foreach (int junction in fusionCandidate.junctionIndexes)
                                {
                                    if (junction == i)
                                    {
                                        mostProbableSequences += "-";
                                        allPossibleSequences  += "-";
                                    }
                                }
                            }
                            mostProbableSequences += "|";
                            allPossibleSequences  += "|";

                            //record parents
                            string tempParents = "";

                            mostProbableParents += tempParents;
                            allPossibleParents  += tempParents;
                        }

                        allPossibleSequences  = allPossibleSequences.Substring(0, allPossibleSequences.Length - 1);   //remove last "|"
                        mostProbableSequences = mostProbableSequences.Substring(0, mostProbableSequences.Length - 1); //remove last "|"

                        string ambiguity = "";
                        NeoFindAmbiguity.FindIons(psm.candidates[indexOfFirstProbableSequence], psm, spectrum); //this should be carried over, but it's not...
                                                                                                                //      mutableError_message += e;
                        bool[] foundIons = psm.candidates[indexOfFirstProbableSequence].foundIons;
                        char[] firstSeq  = psm.candidates[indexOfFirstProbableSequence].seq.ToCharArray();

                        bool ambiguous = false;
                        for (int i = 1; i < foundIons.Length; i++)
                        {
                            if (foundIons[i])                 //if found
                            {
                                ambiguity += firstSeq[i - 1]; //add aa
                                if (ambiguous)                //if it is part of an ambiguous sequence
                                {
                                    ambiguity += ")";
                                    ambiguous  = false; //no longer ambiguous
                                }
                            }
                            else
                            {
                                if (!ambiguous)
                                {
                                    ambiguous  = true;
                                    ambiguity += "(";
                                }
                                ambiguity += firstSeq[i - 1];
                            }
                        }
                        ambiguity += firstSeq[foundIons.Length - 1];
                        if (ambiguous)
                        {
                            ambiguity += ")";
                        }
                        string potentialFalsePositives = "";

                        if (potentialFalsePositives.Length > 0)
                        {
                            potentialFalsePositives = potentialFalsePositives.Substring(0, potentialFalsePositives.Length - 1); //remove last |
                            if (potentialFalsePositives.Length > 30000)
                            {
                                potentialFalsePositives = potentialFalsePositives.Substring(0, 30000);
                            }
                        }
                        //workarounds for excel. Actual limit is 32767, but that doesn't seem to work
                        if (mostProbableParents.Length > 30000)
                        {
                            mostProbableParents = mostProbableParents.Substring(0, 30000);
                        }
                        if (allPossibleParents.Length > 30000)
                        {
                            allPossibleParents = allPossibleParents.Substring(0, 30000);
                        }
                        int score = 0;
                        foreach (bool b in psm.candidates[indexOfFirstProbableSequence].foundIons)
                        {
                            if (b)
                            {
                                score++;
                            }
                        }
                        lock (file)
                        {
                            file.WriteLine(psm.scanNumber.ToString() + '\t' + psm.expMass.ToString() + '\t' + psm.nInfo.seq + '\t' + psm.nInfo.score + '\t' + psm.cInfo.seq + '\t' + psm.cInfo.score + '\t' + psm.candidates[indexOfFirstProbableSequence].seq + '\t' + ambiguity + '\t' + psm.fusionType.ToString() + '\t' + mostProbableSequences + '\t' + mostProbableSequences.Replace("-", "") + '\t' + mostProbableParents + '\t' + allPossibleSequences + '\t' + allPossibleSequences.Replace("-", "") + '\t' + allPossibleParents + '\t' + psm.candidates.Count().ToString() + '\t' + potentialFalsePositives + '\t' + score);
                            //progress++;
                            //this.worker.ReportProgress((int)(progress / psms.Count() * 100));
                        }
                    }
                });
            }
        }
Example #3
0
        protected override MyTaskResults RunSpecific(string OutputFolder, List <DbForTask> dbFilenameList, List <string> currentRawFileList, string taskId, FileSpecificParameters[] fileSettingsList)
        {
            MyTaskResults = new MyTaskResults(this);

            if (NeoType.Equals(NeoTaskType.AggregateTargetDecoyFiles))
            {
                //getfolders
                if (NeoParameters.DecoyFilePath == null)
                {
                    NeoParameters.DecoyFilePath = new DirectoryInfo(OutputFolder).Name;
                    string taskString = NeoParameters.DecoyFilePath.Split('-')[0];
                    int    taskNum    = Convert.ToInt32(taskString.Substring(4, taskString.Length - 4));
                    taskNum--;
                    NeoParameters.DecoyFilePath = OutputFolder.Substring(0, OutputFolder.Length - NeoParameters.DecoyFilePath.Length) + "Task" + taskNum + "-SearchTask\\" + Path.GetFileNameWithoutExtension(currentRawFileList[0]) + "_PSMs.psmtsv";
                    if (NeoParameters.TargetFilePath == null)
                    {
                        NeoParameters.TargetFilePath = new DirectoryInfo(OutputFolder).Name;
                        taskNum--;
                        NeoParameters.TargetFilePath = OutputFolder.Substring(0, OutputFolder.Length - NeoParameters.TargetFilePath.Length) + "Task" + taskNum + "-SearchTask\\" + Path.GetFileNameWithoutExtension(currentRawFileList[0]) + "_PSMs.psmtsv";
                    }
                }
                if (NeoParameters.TargetFilePath == null)
                {
                    NeoParameters.TargetFilePath = new DirectoryInfo(OutputFolder).Name;
                    string taskString = NeoParameters.TargetFilePath.Split('-')[0];
                    int    taskNum    = Convert.ToInt32(taskString.Substring(4, taskString.Length - 4));
                    taskNum--;
                    NeoParameters.TargetFilePath = OutputFolder.Substring(0, OutputFolder.Length - NeoParameters.TargetFilePath.Length) + "Task" + taskNum + "-SearchTask\\" + Path.GetFileNameWithoutExtension(currentRawFileList[0]) + "_PSMs.psmtsv";
                }
                AggregateSearchFiles.Combine(NeoParameters.TargetFilePath, NeoParameters.DecoyFilePath, OutputFolder + "\\" + Path.GetFileNameWithoutExtension(currentRawFileList[0]));
            }
            else if (NeoType.Equals(NeoTaskType.AggregateNormalSplicedFiles))
            {
                //reset database
                dbFilenameList = StoredDatabases;

                string normalPath = "";
                string cisPath    = new DirectoryInfo(OutputFolder).Name;
                string taskString = cisPath.Split('-')[0];
                int    taskNum    = Convert.ToInt32(taskString.Substring(4, taskString.Length - 4));
                taskNum -= 2;
                string transPath = OutputFolder.Substring(0, OutputFolder.Length - cisPath.Length) + "Task" + (taskNum + 1) + "-SearchTask\\" + Path.GetFileNameWithoutExtension(currentRawFileList[0]) + "_PSMs.psmtsv";
                cisPath = OutputFolder.Substring(0, OutputFolder.Length - cisPath.Length) + "Task" + taskNum + "-SearchTask\\" + Path.GetFileNameWithoutExtension(currentRawFileList[0]) + "_PSMs.psmtsv";
                AggregateSearchFiles.RecursiveNeoAggregation(normalPath, cisPath, OutputFolder, "CisResults.psmtsv");
                AggregateSearchFiles.RecursiveNeoAggregation(normalPath, transPath, OutputFolder, "TransResults.psmtsv");
            }
            else if (NeoType.Equals(NeoTaskType.GenerateSplicedPeptides))
            {
                NeoMassCalculator.ImportMasses();

                MyFileManager myFileManager = new MyFileManager(true);

                //Import Spectra
                for (int spectraFileIndex = 0; spectraFileIndex < currentRawFileList.Count; spectraFileIndex++)
                {
                    var origDataFile = currentRawFileList[spectraFileIndex];
                    CommonParameters combinedParams = SetAllFileSpecificCommonParams(CommonParameters, fileSettingsList[spectraFileIndex]);

                    var thisId = new List <string> {
                        taskId, "Individual Spectra Files", origDataFile
                    };
                    NewCollection(Path.GetFileName(origDataFile), thisId);
                    Status("Loading spectra file...", thisId);
                    MsDataFile myMsDataFile = myFileManager.LoadFile(origDataFile, combinedParams.TopNpeaks, combinedParams.MinRatio, combinedParams.TrimMs1Peaks, combinedParams.TrimMsMsPeaks, combinedParams);
                    Status("Getting ms2 scans...", thisId);
                    Ms2ScanWithSpecificMass[] arrayOfMs2ScansSortedByMass = GetMs2Scans(myMsDataFile, origDataFile, combinedParams.DoPrecursorDeconvolution, combinedParams.UseProvidedPrecursorInfo, combinedParams.DeconvolutionIntensityRatio, combinedParams.DeconvolutionMaxAssumedChargeState, combinedParams.DeconvolutionMassTolerance).OrderBy(b => b.PrecursorMass).ToArray();

                    //Import Database
                    Status("Loading modifications...", taskId);

                    List <ModificationWithMass> variableModifications = GlobalVariables.AllModsKnown.OfType <ModificationWithMass>().Where(b => CommonParameters.ListOfModsVariable.Contains((b.modificationType, b.id))).ToList();
                    List <ModificationWithMass> fixedModifications    = GlobalVariables.AllModsKnown.OfType <ModificationWithMass>().Where(b => CommonParameters.ListOfModsFixed.Contains((b.modificationType, b.id))).ToList();
                    List <string> localizeableModificationTypes       = GlobalVariables.AllModTypesKnown.ToList();

                    // load proteins
                    List <Protein> proteinList = LoadProteins(taskId, dbFilenameList, true, DecoyType.None, localizeableModificationTypes, combinedParams);

                    //Read N and C files
                    string nPath = NeoParameters.NFilePath;
                    string cPath = NeoParameters.CFilePath;
                    //if termini input

                    if (nPath == null || cPath == null)
                    {
                        //if no termini input
                        string   taskHeader = "Task";
                        string[] pathArray  = OutputFolder.Split('\\');
                        string   basePath   = "";
                        for (int i = 0; i < pathArray.Length - 1; i++)
                        {
                            basePath += pathArray[i] + '\\';
                        }
                        string currentTaskNumber = pathArray[pathArray.Length - 1].Split('-')[0];
                        currentTaskNumber = currentTaskNumber.Substring(taskHeader.Length, currentTaskNumber.Length - taskHeader.Length);
                        string NHeader = "";
                        string CHeader = "";
                        if (cPath == null)
                        {
                            CHeader = taskHeader + (Convert.ToInt16(currentTaskNumber) - 1);
                            if (nPath == null)
                            {
                                NHeader = taskHeader + (Convert.ToInt16(currentTaskNumber) - 2);
                            }
                        }
                        else
                        {
                            NHeader = taskHeader + (Convert.ToInt16(currentTaskNumber) - 1);
                        }
                        foreach (string s in Directory.GetDirectories(basePath))
                        {
                            if (s.Contains(NHeader))
                            {
                                nPath = s;
                            }
                            else if (s.Contains(CHeader))
                            {
                                cPath = s;
                            }
                        }
                        string fileName = Path.GetFileNameWithoutExtension(currentRawFileList[0]) + "_PSMs.psmtsv";
                        nPath += "\\" + fileName;
                        cPath += "\\" + fileName;
                    }

                    Status("Importing Search Results...", taskId);
                    List <NeoPsm> psms = ImportPsmtsv.ImportNeoPsms(nPath, cPath);

                    //Splice
                    Status("Splicing Fragments...", taskId);
                    List <NeoPsm> candidates = NeoSplicePeptides.SplicePeptides(psms);

                    //Find Ambiguity
                    Status("Identifying Ambiguity...", taskId);
                    NeoFindAmbiguity.FindAmbiguity(candidates, proteinList, arrayOfMs2ScansSortedByMass, dbFilenameList[0].FilePath);

                    //Export Results
                    Status("Exporting Results...", taskId);
                    NeoExport.ExportAll(candidates, arrayOfMs2ScansSortedByMass, OutputFolder);

                    //Switch databases
                    string outputFolder = NeoExport.path + NeoExport.folder + @"\" + NeoExport.folder + "FusionDatabaseAppendixNC.fasta";
                    dbFilenameList = new List <DbForTask>()
                    {
                        new DbForTask(outputFolder, false)
                    };
                }
            }
            else //if SearchTransDb
            {
                string outputFolder = NeoExport.path + NeoExport.folder + @"\" + NeoExport.folder + "FusionDatabaseAppendixTS.fasta";
                dbFilenameList = new List <DbForTask>()
                {
                    new DbForTask(outputFolder, false)
                };
            }

            return(MyTaskResults);
        }