a217 has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I was hoping one of the monks could give me some guidance regarding a short script I'm working on. Below is sample data separated by tab:
chr start end pos1 pos2 CGtype Cov. Methy Stra +nd chr1 18598 19673 18676 18676 CHH 0 0 + chr1 18598 19673 18689 18689 CG 2 0 + chr1 18598 19673 18997 18997 CHH 0 0 + chr1 18598 19673 19546 19546 CG 4 0 + chr1 18598 19673 19671 19671 CHG 7 0 + chr1 124987 125426 125001 125001 CHH 1 0 + chr1 124987 125426 125226 125226 CG 0 0 + chr1 124987 125426 125426 125426 CG 0 0 + chr1 317653 318092 317653 317653 CHG 11 0 + chr1 317653 318092 317795 317795 CHG 0 0 + chr1 317653 318092 318090 318090 CHH 3 0 + chr1 427014 428027 427025 427025 CHH 0 0 + chr1 439136 440407 439687 439687 CHH 9 0 + chr1 523082 523977 523167 523167 CG 0 0 + chr1 534601 536512 535789 535789 CHH 1 0 + chr1 703847 704410 703999 703999 CHH 0 0 + chr1 752279 753308 753330 753330 CHH 0 0 +
On each line, a chromosome number is listed along with a region defined by start and end positions. The values in the position columns should correspond to the region. My goal is to create a summary file with columns as follows:
"CpG" "length" "CG" "CG>0" "CG>5" "CG>10" "CG>0mean" "CG>0median" "CG>5mean" "CG>5median" "CG>10mean" "CG>10median"
Note these are just the column names, and I've used quotations to help distinguish them. The actual data is separated by tab.
The "CpG" column will serve as the ID. For example, the first ID would be chr1:18598-19673. The second column, "length," is the total number of lines corresponding to each ID. In the above example, the length of chr1:18598-19673 is 5. The next column, "CG," represents the total number of lines in the region that are labeled CG (as opposed to CHH or CHG) and the above example would have a value of 2. The column, "CG>0", represents the CG sites with coverage (in column "Cov." in the example) greater than zero (hence, chr1:18598-19673 would have CG>0 value of 2). It follows that the columns "CG>5" and "CG>10" represents instances where the coverage is greater than 5 and greater than 10, respectively. (and their values for chr1:18598-19673 region would be zero since there are no CG sites with coverage greater than 5 or 10).
Now comes the main issue I've had in approaching this. The following "mean" and "median" columns must calculate the mean and median of the methylation count (listed in the "Methy" column in the example). In the example, all of the methy values are zero, so the mean and median for CG>0, CG>5, and CG>10 would be all zero as well. However, in the real data set, the numbers may vary. The main problem I face is that I need to calculate the mean and median for each separate sub-dataset. If you have any suggestions for me I would appreciate the assistance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with Mean/Median for data analysis
by TJPride (Pilgrim) on Dec 21, 2011 at 05:26 UTC | |
by Anonymous Monk on Dec 21, 2011 at 05:43 UTC | |
by TJPride (Pilgrim) on Dec 21, 2011 at 07:05 UTC | |
|
Re: Help with Mean/Median for data analysis
by Marshall (Canon) on Dec 21, 2011 at 15:30 UTC | |
|
Re: Help with Mean/Median for data analysis
by pvaldes (Chaplain) on Dec 22, 2011 at 12:27 UTC | |
by Marshall (Canon) on Dec 22, 2011 at 12:58 UTC | |
by pvaldes (Chaplain) on Dec 22, 2011 at 13:11 UTC |