public bool InsertPosition(string _position, string _previousPosition, string _nextPosition) // inserts alignment position object in between noted positions { if (alnHash.ContainsKey(_previousPosition) && alnHash.ContainsKey(_nextPosition)) { if (GetNextPositionKey(_previousPosition) == _nextPosition) { AlignmentPosition newPosition = new AlignmentPosition(_previousPosition, _nextPosition); alnHash.Add(_position, newPosition); AlignmentPosition prevP = new AlignmentPosition(); AlignmentPosition nextP = new AlignmentPosition(); prevP = (AlignmentPosition)alnHash[_previousPosition]; nextP = (AlignmentPosition)alnHash[_nextPosition]; prevP.SetNextAlignmentPosition(_position); // need to test this! Does this change underlying obj? nextP.SetPreviousAlignmentPosition(_position); // ditto numberOfPositions++; return(true); } else { return(false); } } else { return(false); } }
public void AddNewPosition(string _position) // overload to add position to end of alignment { // find last position string currentLastPosition = GetLastPosition(); string endKey = "end"; AlignmentPosition oldLastPosition = new AlignmentPosition(); oldLastPosition = (AlignmentPosition)alnHash[currentLastPosition]; oldLastPosition.SetNextAlignmentPosition(_position); AlignmentPosition newPosition = new AlignmentPosition(); newPosition.SetPreviousAlignmentPosition(currentLastPosition); newPosition.SetNextAlignmentPosition(endKey); alnHash.Add(_position, newPosition); numberOfPositions++; return; }
public bool DeletePosition(string _position) // deletes position, moves Next and Prev keys and returns true if position exists { if (alnHash.ContainsKey(_position)) { string previousPosition = GetPreviousPositionKey(_position); string nextPosition = GetNextPositionKey(_position); if (previousPosition != "start") { AlignmentPosition prevP = new AlignmentPosition(); prevP = (AlignmentPosition)alnHash[previousPosition]; prevP.SetNextAlignmentPosition(nextPosition); } if (nextPosition != "end") { AlignmentPosition nextP = new AlignmentPosition(); nextP = (AlignmentPosition)alnHash[nextPosition]; nextP.SetPreviousAlignmentPosition(previousPosition); } Hashtable infoFromDeletedPosition = ((AlignmentPosition)alnHash[_position]).GetResidueInfo(); // need to get position info before it's deleted alnHash.Remove(_position); // clean up protein list here: if this is the last position containing said protein, // remove it from the list string[] allKeys = new string[alnHash.Count]; alnHash.Keys.CopyTo(allKeys, 0); string[] listOfProteinsInDeletedPosition = new string[infoFromDeletedPosition.Count]; infoFromDeletedPosition.Keys.CopyTo(listOfProteinsInDeletedPosition, 0); bool[] proteinStillPresent = new bool[listOfProteinsInDeletedPosition.Length]; for (int deletedPositionProteinIndex = 0; deletedPositionProteinIndex < listOfProteinsInDeletedPosition.Length; deletedPositionProteinIndex++) { proteinStillPresent[deletedPositionProteinIndex] = false; for (int alnKeyIndex = 0; alnKeyIndex < allKeys.Length; alnKeyIndex++) { if (((AlignmentPosition)alnHash[allKeys[alnKeyIndex]]).IsProteinPresent(listOfProteinsInDeletedPosition[deletedPositionProteinIndex])) { proteinStillPresent[deletedPositionProteinIndex] = true; break; } } } for (int deletedPositionProteinIndex = 0; deletedPositionProteinIndex < listOfProteinsInDeletedPosition.Length; deletedPositionProteinIndex++) { if (!proteinStillPresent[deletedPositionProteinIndex]) { if (proteinsInAlignment.Contains(listOfProteinsInDeletedPosition[deletedPositionProteinIndex])) { proteinsInAlignment.RemoveAt(proteinsInAlignment.IndexOf(listOfProteinsInDeletedPosition[deletedPositionProteinIndex])); } } } // this loop gets rid of proteins that are no longer in alignment after deletion of position numberOfPositions--; return(true); } else { return(false); } }