What is the difference between McNemar's test and the chi-squared test, and how do you know when to use each? I have tried reading up on different sources, but I am still not clear what test would be the appropriate in my case.  There are three different questions I am asking about my dataset:  


*

*The subjects are tested for infections from X  at different times. I want to know if the proportions of positive for X after is related to the proportion of positive for X before:
             After   
           |no  |yes|
Before|No  |1157|35 |
      |Yes |220 |13 |

results of chi-squared test: 
Chi^2 =  4.183     d.f. =  1     p =  0.04082 

results of McNemar's test: 
Chi^2 =  134.2     d.f. =  1     p =  4.901e-31

From my understanding, as the data are repeated measures, I must use McNemar's test, which tests if the proportion of positive for X has changed.
But my questions seems to need the chi-squared test - testing if the proportion of positive for X after is related to the proportion of positive for X before.
I am not even sure if I understand the difference between McNemar's test and the chi-squared correctly. What would be the right test if my question were, "Is the proportion of subjects infected with X after different from before?"

*A similar case, but where instead of before and after, I measure two different infections at one point in time:
        Y   
      |no  |yes|
X|No  |1157|35 |
 |Yes |220 |13 |

Which test would be right here if the question is "Does higher proportions of one infections relate to higher proportions of Y"?

*If my question was, "Is infection Y at time t2 related to infection X at time t1?", which test would be appropriate? 
              Y at t2   
            |no  |yes|
X at t1|No  |1157|35 |
       |Yes |220 |13 |

I was using McNemar's test in all these cases, but I have my doubts if that is the right test to answer my questions. I am using R. Could I use a binomial glm instead? Would that be analogous to the chi-squared test?
 A: The question of which test to use, contingency table $\chi^{2}$ versus McNemar's $\chi^{2}$ of a null hypothesis of no association between two binary variables is simply a question of whether your data are paired/dependent, or unpaired/independent:
Binary Data in Two Independent Samples
In this case, you would use a contingency table $\chi^{2}$ test.
For example, you might have a sample of 20 statisticians from the USA, and a separate independent sample of 37 statisticians from the UK, and have a measure of whether these statisticians are hypertensive or normotensive. Your null hypothesis is that both UK and US statisticians have the same underlying probability of being hypertensive (i.e. that knowing whether one is from the USA or from the UK tells one nothing about the probability of hypertension). Of course it is possible that you could have the same sample size in each group, but that does not change the fact of the samples being independent (i.e. unpaired).
Binary Data in Paired Samples
In this case you would use McNemar's $\chi^{2}$ test.
For example, you might have individually-matched case-control study data sampled from an international statistician conference, where 30 statisticians with hypertension (cases) and 30 statisticians without hypertension (controls; who are individually matched by age, sex, BMI & smoking status to particular cases), are retrospectively assessed for professional residency in the UK versus residency elsewhere. The null is that the probability of residing in the UK among cases is the same as the probability of residing in the UK as controls (i.e. that knowing about one's hypertensive status tells one nothing about one's UK residence history).
In fact, McNemar's test analyzes pairs of data. Specifically, it analyzes discordant pairs. So the $r$ and $s$ from $\chi^{2}=\frac{[(r−s)−1]^{2}}{(r+s)}$ are counts of discordant pairs.
Anto, in your example, your data are paired (same variable measured twice in same subject) and therefore McNemar's test is the appropriate choice of test for association.
[gung and I disagreed for a time about an earlier answer.]
Quoted References
"Assuming that we are still interested in comparing proportions, what can we do if our data are paired, rather than independent?... In this situation, we use McNemar's test."–Pagano and Gauvreau, Principles of Biostatistics, 2nd edition, page 349. [Emphasis added]
"The expression is better known as the McNemar matched-pair test statistic (McNemar, 1949), and has been a mainstay of matched-pair analysis."—Rothman, Greenland, & Lash. Modern Epidemiology, page 286. [Emphasis added]
"The paired t test and repeated measures of analysis of variance can be used to analyze experiments in which the variable being studied can be measured on an interval scale (and satisfies other assumptions required of parametric methods). What about experiments, analogous to the ones in Chapter 5, where the outcome is measured on a nominal scale? This problem often arises when asking whether or not a an individual responded to a treatment or when comparing the results of two different diagnostic tests that are classified positive or negative in the same individuals. We will develop a procedure to analyze such experiments, Mcnemar's test for changes, in the context of one such study."—Glanz, Primer of Biostatistics, 7th edition, page 200. [Emphasis added. Glanz works through an example of a misapplication the contingency table $\chi^{2}$ test to paired data on page 201.]
"For matched case-control data with one control per case, the resultant analysis is simple, and the appropriate statistical test is McNemar's chi-squared test... note that for the calculation of both the odds ratio and the statistic, the only contributors are the pairs which are disparate in exposure, that is the pairs where the case was exposed but the control was not, and those where the control was exposed but the case was not."—Elwood. Critical Appraisal of Epidemiological Studies and Clinical Trials, 1st edition, pages 189–190. [Emphasis added]
