src/DnaSynthesisCycle2.java
/**
     * Implements the two steps of a single cycle of DNA synthesis
     * updates the state of the genome by calls to methods in PotentialInitiationSite.
     * @param firingProbabilityForCycle
     * @param nucleotidesOfForkMovementForCycle 
     */
Implements the two steps of a single cycle of DNA synthesis
updates the state of the genome by calls to methods in PotentialInitiationSite.
Implements the two steps of a single cycle of DNA synthesis updates the state of the genome by calls to methods in PotentialInitiationSite .
public void start(double firingProbabilityForCycle, int nucleotidesOfForkMovementForCycle) {
        /**
         *  INITIATION ENGINE
         */
        lastActivePIS = leftEnd;
        for (PotentialInitiationSite2 site : potentialInitSiteList) { 
            if (site.IsActive()) {
                lastActivePIS = site;
            }
            else if (site.IsPotential()) {
                if (Math.random() < firingProbabilityForCycle) {                    
                    site.activate(lastActivePIS);
                    numberNucleotidesReplicated++;  
                    lastActivePIS = site;
                    initiations++;
                    actives++;
                    potentials--;
                    forks += 2;
                }
            }
        }        
        /**
        *  SYNTHESIS ENGINE
        * 
        * Left end is special case - leftmost active site has left-moving fork until it terminates.
        * The test for termination must take into account that there is no active fork at the left end of the chromosome.
        * Similarly, the number of nucleotides synthesized is increased by the activity of only a single fork.
        * Once a left-moving fork from a leftmost active site terminates, the leftmost active site has only a rightward-moving fork.
        * therefore we need to keep track of the position of a left moving fork until it terminates in order to:
        * 1) apply the correct test for termination, 2)correctly increment the number of nucleotides synthesized, and 
        * 3) mainly to determine whether Potential sites in the region to the left of moving fork are passively replicated.
        */
        if (initiations == 0) {return;}  
        PotentialInitiationSite2 leftSite = leftEnd.getRightActivePIS();  
        if (leftSite.IsLeftForkActive()) { 
            if ((leftSite.getPositionLeftFork() - nucleotidesOfForkMovementForCycle) <= 0) {  
                numberNucleotidesReplicated += leftSite.getPositionLeftFork();  
                leftSite.setPositionLeftFork((int) 0);
                leftEndFork = 0; 
                leftSite.inactivateLeftFork();
                forks--;
                closures++;
                if (!leftSite.IsRightForkActive()) {  
                    leftSite.terminate();  
                    terminations++;
                    actives--;
                }
            } else {
                leftSite.extendLeftFork(nucleotidesOfForkMovementForCycle);
                leftEndFork = leftSite.getPositionLeftFork();  
                numberNucleotidesReplicated += nucleotidesOfForkMovementForCycle;
            }
                /*for (int i = leftSite.getIndex() -1 ; i >= 0; i--) {
                    if (potentialInitSiteList.get(i).getPosition() >= leftEndFork) {
                        potentialInitSiteList.get(i).passivelyReplicate();
                    }
                    break;
                }*/
        }
        for (PotentialInitiationSite2 site : potentialInitSiteList) { 
            if (!site.IsActive()) {  
                if (site.IsLeftForkActive() || site.IsRightForkActive()) {
                    System.out.println("inactive site with active forks");
                }
            }
            if (site.IsActive()) {
                site.linkageCheck(seqLength);  
                if (site.IsRightForkActive()) {  
                    if (site.getRightActivePIS().equals(rightEnd)) { 
                        if ((site.getPositionRightFork() + nucleotidesOfForkMovementForCycle) >= seqLength - 1) {  
                            site.inactivateRightFork();
                            forks--;
                            numberNucleotidesReplicated += (seqLength - 1 - site.getPositionRightFork());
                            site.setPositionRightFork(seqLength - 1);
                            rightEndFork = seqLength - 1;  
                            closures++;
                            if (!site.IsLeftForkActive()) {  
                                site.terminate();
                                terminations++;
                                actives--;
                            }
                        } else {
                            site.extendRightFork(nucleotidesOfForkMovementForCycle);
                            rightEndFork = site.getPositionRightFork();  
                            numberNucleotidesReplicated += nucleotidesOfForkMovementForCycle;
                        }
                    } else { 
                        if (IsTerminatedOnRight(site,nucleotidesOfForkMovementForCycle)) {  
                            site.inactivateRightFork(); 
                            site.getRightActivePIS().inactivateLeftFork(); 
                            forks -= 2;
                            int spaceBetweenForks = site.getRightActivePIS().getPositionLeftFork() - site.getPositionRightFork() - 1;  
                            if (spaceBetweenForks == 1) {site.setPositionRightFork(site.getPositionRightFork() + 1);}  
                            if (spaceBetweenForks >=2) {  
                                site.setPositionRightFork(site.getPositionRightFork() + spaceBetweenForks / 2);
                                site.getRightActivePIS().setPositionLeftFork(site.getPositionRightFork() + 1);
                            }
                            forkOnLeft = site.getPositionRightFork();  
                            forkOnRight = site.getRightActivePIS().getPositionLeftFork(); 
                            if (forkOnRight - forkOnLeft != 1) {  
                                System.out.println("forks should have met" + (forkOnRight - forkOnLeft));
                            }
                            numberNucleotidesReplicated += spaceBetweenForks;
                            closures++;
                            if (!site.IsLeftForkActive()) {  
                                site.terminate(); 
                                terminations++;
                                actives--;
                            }
                            if (!site.getRightActivePIS().IsRightForkActive()) {  
                                if (!site.getRightActivePIS().IsActive()) {  
                                    System.out.println("redundant termination");
                                }
                                site.getRightActivePIS().terminate();  
                                terminations++;
                                actives--;
                            }
                        } else {
                            site.extendRightFork(nucleotidesOfForkMovementForCycle);
                            forkOnLeft = site.getPositionRightFork();
                            site.getRightActivePIS().extendLeftFork(nucleotidesOfForkMovementForCycle);
                            forkOnRight = site.getRightActivePIS().getPositionLeftFork();
                            numberNucleotidesReplicated += 2 * nucleotidesOfForkMovementForCycle;
                        }
                    }
                }
            } else if (site.IsPotential()) {
                if(IsPassivelyReplicated(site)) {
                    site.passivelyReplicate();
                    passives++;
                    potentials--;
                }
                else {
                    if (initiations >0) {
                        int i = 1;
                    }
                }
            }
        }
        fractionReplicated = (double) numberNucleotidesReplicated/seqLength;
    }
public void start ( double firingProbabilityForCycle , int nucleotidesOfForkMovementForCycle ) { /**
         *  INITIATION ENGINE
         */ lastActivePIS = leftEnd ; for ( PotentialInitiationSite2 site : potentialInitSiteList ) { if ( site . IsActive ( ) ) { lastActivePIS = site ; } else if ( site . IsPotential ( ) ) { if ( Math . random ( ) < firingProbabilityForCycle ) { site . activate ( lastActivePIS ) ; numberNucleotidesReplicated ++ ; lastActivePIS = site ; initiations ++ ; actives ++ ; potentials -- ; forks += 2 ; } } } /**
        *  SYNTHESIS ENGINE
        * 
        * Left end is special case - leftmost active site has left-moving fork until it terminates.
        * The test for termination must take into account that there is no active fork at the left end of the chromosome.
        * Similarly, the number of nucleotides synthesized is increased by the activity of only a single fork.
        * Once a left-moving fork from a leftmost active site terminates, the leftmost active site has only a rightward-moving fork.
        * therefore we need to keep track of the position of a left moving fork until it terminates in order to:
        * 1) apply the correct test for termination, 2)correctly increment the number of nucleotides synthesized, and 
        * 3) mainly to determine whether Potential sites in the region to the left of moving fork are passively replicated.
        */ if ( initiations == 0 ) { return ; } PotentialInitiationSite2 leftSite = leftEnd . getRightActivePIS ( ) ; if ( leftSite . IsLeftForkActive ( ) ) { if ( ( leftSite . getPositionLeftFork ( ) - nucleotidesOfForkMovementForCycle ) <= 0 ) { numberNucleotidesReplicated += leftSite . getPositionLeftFork ( ) ; leftSite . setPositionLeftFork ( ( int ) 0 ) ; leftEndFork = 0 ; leftSite . inactivateLeftFork ( ) ; forks -- ; closures ++ ; if ( ! leftSite . IsRightForkActive ( ) ) { leftSite . terminate ( ) ; terminations ++ ; actives -- ; } } else { leftSite . extendLeftFork ( nucleotidesOfForkMovementForCycle ) ; leftEndFork = leftSite . getPositionLeftFork ( ) ; numberNucleotidesReplicated += nucleotidesOfForkMovementForCycle ; } /*for (int i = leftSite.getIndex() -1 ; i >= 0; i--) {
                    if (potentialInitSiteList.get(i).getPosition() >= leftEndFork) {
                        potentialInitSiteList.get(i).passivelyReplicate();
                    }
                    break;
                }*/ } for ( PotentialInitiationSite2 site : potentialInitSiteList ) { if ( ! site . IsActive ( ) ) { if ( site . IsLeftForkActive ( ) || site . IsRightForkActive ( ) ) { System . out . println ( "inactive site with active forks" ) ; } } if ( site . IsActive ( ) ) { site . linkageCheck ( seqLength ) ; if ( site . IsRightForkActive ( ) ) { if ( site . getRightActivePIS ( ) . equals ( rightEnd ) ) { if ( ( site . getPositionRightFork ( ) + nucleotidesOfForkMovementForCycle ) >= seqLength - 1 ) { site . inactivateRightFork ( ) ; forks -- ; numberNucleotidesReplicated += ( seqLength - 1 - site . getPositionRightFork ( ) ) ; site . setPositionRightFork ( seqLength - 1 ) ; rightEndFork = seqLength - 1 ; closures ++ ; if ( ! site . IsLeftForkActive ( ) ) { site . terminate ( ) ; terminations ++ ; actives -- ; } } else { site . extendRightFork ( nucleotidesOfForkMovementForCycle ) ; rightEndFork = site . getPositionRightFork ( ) ; numberNucleotidesReplicated += nucleotidesOfForkMovementForCycle ; } } else { if ( IsTerminatedOnRight ( site , nucleotidesOfForkMovementForCycle ) ) { site . inactivateRightFork ( ) ; site . getRightActivePIS ( ) . inactivateLeftFork ( ) ; forks -= 2 ; int spaceBetweenForks = site . getRightActivePIS ( ) . getPositionLeftFork ( ) - site . getPositionRightFork ( ) - 1 ; if ( spaceBetweenForks == 1 ) { site . setPositionRightFork ( site . getPositionRightFork ( ) + 1 ) ; } if ( spaceBetweenForks >= 2 ) { site . setPositionRightFork ( site . getPositionRightFork ( ) + spaceBetweenForks / 2 ) ; site . getRightActivePIS ( ) . setPositionLeftFork ( site . getPositionRightFork ( ) + 1 ) ; } forkOnLeft = site . getPositionRightFork ( ) ; forkOnRight = site . getRightActivePIS ( ) . getPositionLeftFork ( ) ; if ( forkOnRight - forkOnLeft != 1 ) { System . out . println ( "forks should have met" + ( forkOnRight - forkOnLeft ) ) ; } numberNucleotidesReplicated += spaceBetweenForks ; closures ++ ; if ( ! site . IsLeftForkActive ( ) ) { site . terminate ( ) ; terminations ++ ; actives -- ; } if ( ! site . getRightActivePIS ( ) . IsRightForkActive ( ) ) { if ( ! site . getRightActivePIS ( ) . IsActive ( ) ) { System . out . println ( "redundant termination" ) ; } site . getRightActivePIS ( ) . terminate ( ) ; terminations ++ ; actives -- ; } } else { site . extendRightFork ( nucleotidesOfForkMovementForCycle ) ; forkOnLeft = site . getPositionRightFork ( ) ; site . getRightActivePIS ( ) . extendLeftFork ( nucleotidesOfForkMovementForCycle ) ; forkOnRight = site . getRightActivePIS ( ) . getPositionLeftFork ( ) ; numberNucleotidesReplicated += 2 * nucleotidesOfForkMovementForCycle ; } } } } else if ( site . IsPotential ( ) ) { if ( IsPassivelyReplicated ( site ) ) { site . passivelyReplicate ( ) ; passives ++ ; potentials -- ; } else { if ( initiations > 0 ) { int i = 1 ; } } } } fractionReplicated = ( double ) numberNucleotidesReplicated / seqLength ; }
Implements the two steps of a single cycle of DNA synthesis
 updates the state of the genome by calls to methods in PotentialInitiationSite.
Implements the two steps of a single cycle of DNA synthesis updates the state of the genome by calls to methods in PotentialInitiationSite .
//INITIATION ENGINE  FIX Maybe ISSUE WITH ORDER //System.out.println(""); //System.out.println(site.getPosition()); //result of placement of fork - initiation site is replicated by one of them //first initiation hasn't happened //DEAL WITH LEFT FORK OF LEFTMOST ACTIVE SITE //get leftmost active site //IF LEFTFORK OF LEFTMOSTSITE IS ACTIVE (if not we do nothing) //TWO CASES will the left fork terminate at the left end or will it not terminate //if so,  // if right fork was already inactivated, terminate the iste //CASE I -LEFT FORK TERMINATES - properly update number of nucleotides replicated, set the position of left fork to 0 //make a note of the position of the left end fork to check for passive repliction //set left fork to inactive //update number of forks and closures //if this inactivates the leftmostPIS - we catch it later //test for termination of leftmost fork on this cycle // note position of left end fork so use to check for passive replication //TERMINATE AND UPDATE LINKAGES //Set flags and update linkages //CASE 2 - LEFT FORK DOES NOT TERMINATE //if left fork from leftmost site not going to terminate at aleft end then extend fork to left //note the position of left most fork to check for passive replication //properly increment number of nucleotides synthesized //note position of left fork to determine whether potential sites have been passively replicated //CHECK FOR PASSIVE REPLICATION IN LEFT INTERVAL  Not necessary will be picked up in next loop //MAIN LOOP ITERATE ACROSS PIS  //UPDATE POSITIONS OF RIGHT FORK AND LEFT FORK OF NEXT ACTIVE //if site is not active skip but check thatit doesn't have active forks //don't need this as only updating actives and left and righ ends probably innocuous //PROCESS ALL ACTIVE SITES //FIX maybe eliminate in final //CASE I - RIGHTFORK IS ACTIVE AND IS THE RIGHTMOST ACTIVE SITE //TWO SUBCASES - RIGHT FORK WILL TERMINATE OR RIGHT FORK WILL NOT TERMINATE //right fork is active //Site is the rightmost - //CASE1A -RIGHT FORK OF RIGHTMOST ACTIVE SITE WILL TERMINATE AT RIGHT END     //if it terminates //for passive identification //terminate rightmost site if both forks inactivated - this is necessary because if it needs to be terminated //it would not have been terminated during processing of previous interval (it's not an endpoint of previousinterval //if not, this site will not have been terminated  //CASE IB - RIGHT FORK OF RIGHTMOST ACTIVE SITE WILL NOT TERMINATE TERMINATE //Extend right fork, save right fork psoition for dealing with passives, update nucs //rightmost fork doesn't terminate // save for passive replication test on potentils //CASE II - RIGHT FORK IS ACTIVE AND SITE IS NOT THE RIGHTMOST //TWO SUBCASE RIGHT AND LEFT FORKS (FROM RIGHT ACTIVE SITE) WILL MEET OR RIGHT AND LEFT FORKS WILL NOT MEET //Site is active and not the rightmost //CASE IIA - RIGHT FORK WILL MEET LEFT FORK FROM RIGHT ACTIVE SITE //inactivate both forks //update positions of both forks //save positions of forks for dealing passives //terminate either or both sites depending on the state of their other forks //update linkages of if either site terminates  //update nucs and update flags //if forks will meet //inactivate right fork //inactivate left fork of right active //changed long to int //only one nucleotide beteen forks just update right fork position //more than one nucleotide between forks - change positions of both //for dealing with passives //for dealing with passives //FIX - PROBABLY DON'T NEED THIS //for debugging detects positions of forks not updated correctly after they met //The rule is; any time a fork at a site is terminated check whether the other fork is also terminated //SHOULD UPDATE LINKAGES OK - now left active pis points to right active pis //for debugging //now active site to left of site points to activesite to right of right active site //CASE 2B -RIGHT FORK WILL NOT MEET LEFT FORK FROM RIGHT ACTIVE SITE //Extend both forks //save position of forks for dealing with passives //update nucs //DETERMINE WHETHER POTENTIAL SITE WAS ACTIVELY REPLICATED AND UPDaTE ACCORDINGLY //CASE I - IT IS PASSIVELY REPLICATED