Ejemplo n.º 1
0
        static public KmerDefinition GetInstance(int b, int e, int a)
        {
            KmerDefinition aKmerDefinition = new KmerDefinition();

            aKmerDefinition.BeforeMerCount         = b;
            aKmerDefinition.EpitopeMerCount        = e;
            aKmerDefinition.AfterMerCount          = a;
            aKmerDefinition.NumberOfEAt1stPosition = 1;

            Debug.Assert(aKmerDefinition.NumberOfEAt1stPosition == 1 || aKmerDefinition.BeforeMerCount == 0);             //!!! these two cases are the only ones tested

            return(aKmerDefinition);
        }
Ejemplo n.º 2
0
        public static MerAndHlaToLength GetInstance(string aaSequence, HlaToLength aHlaToLength, KmerDefinition kmerDefinition)
        {
            SpecialFunctions.CheckCondition(aaSequence.Length > 0 && char.IsUpper(aaSequence[0]));             //Spot check that all upper
            MerAndHlaToLength aMerAndHlaToLength = new MerAndHlaToLength();

            aMerAndHlaToLength.Mer         = aaSequence;
            aMerAndHlaToLength.HlaToLength = aHlaToLength;
            //aMerAndHlaToLength.Study = study;
            aMerAndHlaToLength.KmerDefinition = kmerDefinition;
            return(aMerAndHlaToLength);
        }
        public string Evaluate(KmerDefinition kmerDefinition,
                               string featureString, bool isPositive, int rowId, int groupId, string sOperator,
                               string[] rgKmer, HlaGroup hlaGroup /*, int lengthOfOriginalLanlEpitopeOrLongMin*/)
        {
            for (int iProperty = 0; iProperty < AAPropertyCollection.Length; ++iProperty)
            {
                string sAAProperty = (string)AAPropertyCollection[iProperty];
                if (featureString.StartsWith(sAAProperty))
                {
                    char chBEA;
                    int  iPos = GetPos(kmerDefinition, featureString, out chBEA);
                    SpecialFunctions.CheckCondition(iPos != -1); //!!! raise error
                    string sAminoAcid = rgKmer[iPos];
                    bool?  goalValue  = GoalValue(sAminoAcid, iProperty);
                    switch (goalValue)
                    {
                    case true:
                        return("1");

                    case false:
                        return("0");

                    case null:
                        return("#");
                    }
                }
            }
            //!!!switch to switch
            if (featureString == "RowId")
            {
                return(rowId.ToString());
            }
            if (featureString == "Operator")
            {
                return(sOperator);
            }
            if (featureString == "GroupId")
            {
                return(groupId.ToString());
            }
            if (featureString == "Immunogenic")
            {
                return(isPositive ? "1" : "0");
            }
            //if (featureString == "KmerLength")
            //{
            //    Debug.Assert(lengthOfOriginalLanlEpitopeOrLongMin != int.MinValue);
            //    return lengthOfOriginalLanlEpitopeOrLongMin.ToString();
            //}
            if (featureString.StartsWith("amino"))
            {
                char chBEA;
                int  iPos = GetPos(kmerDefinition, featureString, out chBEA);
                SpecialFunctions.CheckCondition(iPos != -1); //!!! raise error
                string sAminoAcid = rgKmer[iPos];
                string sGoalValue = AANumberAsGoalValue(sAminoAcid);
                return(sGoalValue);
            }
            //if(featureString == "HLA") //HLA,HLA2digits,HLALetter //HLA-A*0201,HLA-A*02,A
            //{
            //    string sGoalValue = string.Format("HLA-{0}*{1:0000}", hlaGroup.HlaClass, hlaGroup.HlaNumber);
            //    return sGoalValue;
            //}
            //if(featureString == "HLA2digits") //HLA,HLA2digits,HLALetter //HLA-A*0201,HLA-A*02,A
            //{
            //    string sGoalValue = string.Format("HLA-{0}*{1:00}",hlaGroup.HlaClass, hlaGroup.TwoDigits());
            //    return sGoalValue;
            //}
            //else if(featureString == "HLALetter") //HLA,HLA2digits,HLALetter //HLA-A*0201,HLA-A*02,A
            //{
            //    return hlaGroup.HlaClass;
            //}
            //if (featureString == "HLAHarvard") //HLA,HLA2digits,HLALetter //HLA-A*0201,HLA-A*02,A
            //{
            //    return BMixedHlaResolution.HlaGroupString(hlaGroup);
            //}
            //if (featureString.StartsWith(OldStyleEpitopeTrainingData.HlaHarvardFeatureString)) //!!!const
            //{
            //    string goal = featureString.Substring(OldStyleEpitopeTrainingData.HlaHarvardFeatureString.Length);
            //    string value = BMixedHlaResolution.HlaGroupString(hlaGroup);
            //    return (goal == value) ? "1" : "0";

            //}
            //if (featureString == "Supertype") //HLA,HLA2digits,HLALetter //HLA-A*0201,HLA-A*02,A
            //{
            //    return SupertypeMapping.HlaGroupString(hlaGroup);
            //}
            Debug.Assert(false); //!!!need code
            return(null);
        }
        public int GetPos(KmerDefinition kmerDefinition, string sVariable, out char chBEA)
        {
            int iLetter;

            for (iLetter = sVariable.Length - 1; iLetter >= 0; --iLetter)
            {
                if (char.IsLetter(sVariable[(int)iLetter]))
                {
                    break;
                }
            }
            Debug.Assert(0 < iLetter && iLetter < sVariable.Length - 1); // real assert
            chBEA = sVariable[(int)iLetter];
            int iNum = int.Parse(sVariable.Substring((int)iLetter + 1));

            int iPos;

            switch (chBEA)
            {
            case 'B':
            {
                // e.g.KmerDefinition.BeforeMerCount is 6, -6 to -1 are positions 0 to 5
                iPos = kmerDefinition.BeforeMerCount + iNum;
                if (!(0 <= iPos && iPos < kmerDefinition.BeforeMerCount))
                {
                    chBEA = ' ';
                }
            }
            break;

            case 'E':
            {
                // e.g.KmerDefinition.BeforeMerCount is 6, NumberOfEAt1stPosition=1, 1 to 8 are positions 6 to 13
                // e.g.KmerDefinition.BeforeMerCount is 0, NumberOfEAt1stPosition=4, 4 to 11 are positions 0 to 7
                iPos = iNum + kmerDefinition.BeforeMerCount - kmerDefinition.NumberOfEAt1stPosition;
                if (!(kmerDefinition.BeforeMerCount <= iPos && iPos < kmerDefinition.BeforeMerCount + kmerDefinition.EpitopeMerCount))
                {
                    chBEA = ' ';
                }
            }
            break;

            case 'A':
            {
                // e.g.KmerDefinition.BeforeMerCount is 6, NumberOfEAt1stPosition=1, KmerDefinition.EpitopeMerCount = 8, 1 to 6 are positions 14 to 19
                // e.g.KmerDefinition.BeforeMerCount is 0, NumberOfEAt1stPosition=4, KmerDefinition.EpitopeMerCount = 8, 1 to 6 are positions 8 to 13
                iPos = iNum + kmerDefinition.BeforeMerCount + kmerDefinition.EpitopeMerCount - 1;
                if (!(kmerDefinition.BeforeMerCount + kmerDefinition.EpitopeMerCount <= iPos && iPos < kmerDefinition.FullMerCount))
                {
                    chBEA = ' ';
                }
            }
            break;

            default:
                iPos = -1;
                SpecialFunctions.CheckCondition(false);     //!!!raise error
                break;
            }
            return(iPos);
        }
Ejemplo n.º 5
0
 private static string FillInKmerOrNull(string aaSequence, string sProtein, int aa1, KmerDefinition kmerDefinition)
 {
     SpecialFunctions.CheckCondition(kmerDefinition.BeforeMerCount == 0 && kmerDefinition.AfterMerCount == 0, "look at old code to see how to handle other cases");
     if (aaSequence.Length == kmerDefinition.FullMerCount)
     {
         return(aaSequence);
     }
     else
     {
         return(null);
     }
 }