ALDEx updates
Julia M. Di Bella
December 19, 2013

Major updates to aldex():

1. Added gene.ratios and ratio.method options to ALDEx. When gene.ratios=TRUE, ALDEx compares the ratios between transcription levels of sets of two genes between conditions instead of the transcription levels of the genes alone. This is useful for studying, for example, changes in antisense transcription compared to sense transcription between conditions, or changes in riboswitch transcription compared to transcription of the downstream gene. ratio.method defines how these pairs of genes are formatted in the table. When ratio.method="rows", ALDEx assumes that adjacent rows are pairs; i.e. rows 1 and 2 are the first pair, rows 3 and 4 are the second pair, etc. When ratio.method="columns", ALDEx assumes that adjacent columns are pairs; i.e. columns 1 and 2 are the first pair, columns 3 and 4 are the second pair, etc. For both cases the analysis is the same. Pairs of genes are assumed to belong to the same sample and thus when center-log-transformed are on the same scale.
2. Fixed bug so that results from Wilcoxon's RST are output with "wi" variables and results from Welch's T-test are output with "we" variables.

Summary of modifications to aldex(), by line number

24:25	Removed lfdr.cutoff, test, and fdr options since not used in this function anymore. Added gene.ratios and ratio.method. Default gene.ratios=FALSE; if set to TRUE, this will compare ratios between genes (or antisense, riboswitches, etc.) instead of the transcription of the genes itself. Default ratio.method="". If set to "rows" it will assume that genes that should be compared are interleaved within input table, ie, row1-row2, row3-row4, etc. If set to "columns" it will assume adjacent columns are compared. It will interleave the columns to get it in the "rows" format, then proceed as per "rows".
60:63	Tests that if gene.ratios=TRUE ratio.method="columns" or "rows". If not, stops and returns error.
65:91	If ratio.methods="columns" tests that the number of columns is even; if not, stops and returns error. Otherwise, transforms table. Assuming that original columns are S1a, S1b, S2a, S2b, etc., returns a table with half the columns (S1, S2, S3, etc.) but twice the rows, with set A and setB interleaved (ie rows become G1a, G1b, G2a, G2b). This allows downstream analysis in "rows" and "columns" modes to be identical and allows easy calculation of the center log transform, since the "A" and "B" sets of genes are in the same sample. For the new table, the row names are the original row names with _A and _B added alternately, and the column names are the column names for the odd-numbered columns of the original table.
93:96	If ratio.methods="rows" tests that the number of rows is even; if not, stops and returns error.
99:124	Originaly, if there was a row in which the row sum was <= minsum, it was removed. An if statement retains this functionality if gene.ratios=FALSE. If gene.ratios=TRUE then if the row sum <=minsum, both that row and its corresponding row in the row pair is removed from the table. E.g. A gene has no antisense transcription ever, then calculating the sense:antisense ratio is meaningless.
165:166	Commented out line 166 which requires that the variable test be defined by user. This is not used in downstream code and is no longer required as input.
206:223	When matrices to save lFDR, Q, and P are set, if gene.ratios=TRUE then the matrix must have half the rows, since the stats will be done on the ratios of the gene pairs. An if statement has been added to change the number of rows in these matrices if needed.
234:248	If gene.ratios=true, this calculates the ratios of the gene pairs before the statistical tests are done (thus the ratios are calculated for each Monte Carlo replicate). The values are subtracted because that subtraction in log space is equivalent to division Euclidean space.
254:255	Wilcoxon's RST data was being saved into we.p.matrix and we.f, which is counterintuitive. Changed it to save into wi.p.matrix and wi.f so output is accurate.
259:260	Likewise, Welch's T-test data was being saved into wi.p.matrix and wi.f; changed it to save into we.p.matrix and we.f so output is accurate.
402:408 If gene.ratios=TRUE, there are twice as many row names as there are rows in the output table. Changed so that if gene.ratios=TRUE, the row names of the output are the names of the odd-numbered rows of the ALDEx input table. If ratio.method="columns", this also takes out the _A I originally added in when interleaving the table.