Category Archives: Biology

主成分分析

使用《Bioinformatics and Molecular Evolution》Table 2.2 (page 24)中的数据:

> aa
  VOL  BULK POLARITY    PI HYD1  HYD2 SURFACE_AREA FRACT_AREA
A  67 11.50     0.00  6.00  1.8   1.6          113       0.74
R 148 14.28    52.00 10.76 -4.5 -12.3          241       0.64
N  96 12.28     3.38  5.41 -3.5  -4.8          158       0.63
D  91 11.68    49.70  2.77 -3.5  -9.2          151       0.62
C  86 13.46     1.48  5.05  2.5   2.0          140       0.91
Q 114 14.45     3.53  5.65 -3.5  -4.1          189       0.62
E 109 13.57    49.90  3.22 -3.5  -8.2          183       0.62
G  48  3.40     0.00  5.97 -0.4   1.0           85       0.72
H 118 13.69    51.60  7.59 -3.2  -3.0          194       0.78
I 124 21.40     0.13  6.02  4.5   3.1          182       0.88
L 124 21.40     0.13  5.98  3.8   2.8          180       0.85
K 135 15.71    49.50  9.74 -3.9  -8.8          211       0.52
M 124 16.25     1.43  5.74  1.9   3.4          204       0.85
F 135 19.80     0.35  5.48  2.8   3.7          218       0.88
P  90 17.43     1.58  6.30 -1.6  -0.2          143       0.64
S  73  9.47     1.67  5.68 -0.8   0.6          122       0.66
T  93 15.77     1.66  5.66 -0.7   1.2          146       0.70
W 163 21.67     2.10  5.89 -0.9   1.9          259       0.85
Y 141 18.03     1.61  5.66 -1.3  -0.7          229       0.76
V 105 21.57     0.13  5.96  4.2   2.6          160       0.85
> aa.pc=prcomp(aa, center=TRUE, scale.=TRUE)
> aa.pc
Standard deviations:
[1] 1.88954924 1.67729608 0.88574923 0.65278312 0.53130822 0.27233782 0.21394709
[8] 0.05808934

Rotation:
                     PC1         PC2           PC3         PC4        PC5
VOL           0.05790316 -0.58494270  0.1057571970 -0.09311996  0.1684497
BULK         -0.22089815 -0.48085679  0.1685873871 -0.15647005 -0.6842181
POLARITY      0.44390146 -0.10372198  0.1432388489  0.73088587 -0.1747201
PI            0.18580066 -0.25244261 -0.9417631776  0.02722752 -0.0522075
HYD1         -0.49279466 -0.03284274 -0.1281013177  0.35033569 -0.3534423
HYD2         -0.50821923  0.03312719 -0.1292531953 -0.12776013  0.1837842
SURFACE_AREA  0.10045084 -0.56587879  0.1408585179 -0.10640314  0.3652725
FRACT_AREA   -0.45283231 -0.17244828  0.0009997326  0.53059489  0.4220135
                     PC6         PC7          PC8
VOL          -0.11705506  0.21351836 -0.739571539
BULK          0.25124136 -0.35181704  0.109655303
POLARITY      0.39252691  0.22974777  0.009653888
PI            0.04562347 -0.09136074  0.030622127
HYD1         -0.50083501  0.48686655  0.064292387
HYD2          0.70974650  0.41191312 -0.019940539
SURFACE_AREA -0.11107422  0.24097250  0.659316956
FRACT_AREA   -0.01018472 -0.55201871 -0.027363410
> summary(aa.pc)
Importance of components:
                          PC1    PC2     PC3     PC4     PC5     PC6     PC7
Standard deviation     1.8895 1.6773 0.88575 0.65278 0.53131 0.27234 0.21395
Proportion of Variance 0.4463 0.3517 0.09807 0.05327 0.03529 0.00927 0.00572
Cumulative Proportion  0.4463 0.7980 0.89603 0.94930 0.98459 0.99386 0.99958
                           PC8
Standard deviation     0.05809
Proportion of Variance 0.00042
Cumulative Proportion  1.00000

Read more »

Completing a Tree

Problem
An undirected graph is connected if there is a path connecting any two nodes. A tree is a connected (undirected) graph containing no cycles; this definition forces the tree to have a branching structure organized around a central core of nodes, just like its living counterpart. See Figure 2.

We have already grown familiar with trees in “Mendel's First Law”, where we introduced the probability tree diagram to visualize the outcomes of a random variable.

In the creation of a phylogeny, taxa are encoded by the tree's leaves, or nodes having degree 1. A node of a tree having degree larger than 1 is called an internal node.

Given: A positive integer n (n≤1000) and an adjacency list corresponding to a graph on n nodes that contains no cycles.

Return: The minimum number of edges that can be added to the graph to produce a tree.
Sample Dataset
10
1 2
2 8
4 10
5 9
6 10
7 9
Sample Output
3

To solve this problem, we should calculate the number of disconnected components of the graph. It is equal to the number of connectted components plus the isolated nodes.

I defined the GraphComponent class to store the whole adjacent list (edge list), node list, a connectted component and the left adjacent list.
Read more »

Overlap Graphs & Hello JAVA

Problem
A graph whose nodes have all been labeled can be represented by an adjacency list, in which each row of the list contains the two node labels corresponding to a unique edge.

A directed graph (or digraph) is a graph containing directed edges, each of which has an orientation. That is, a directed edge is represented by an arrow instead of a line segment; the starting and ending nodes of an edge form its tail and head, respectively. The directed edge with tail v and head w is represented by (v,w) (but not by (w,v)). A directed loop is a directed edge of the form (v,v).

For a collection of strings and a positive integer k, the overlap graph for the strings is a directed graph Ok in which each string is represented by a node, and string s is connected to string t with a directed edge when there is a length k suffix of s that matches a length k prefix of t, as long as s≠t; we demand s≠t to prevent directed loops in the overlap graph (although directed cycles may be present).

Given: A collection of DNA strings in FASTA format having total length at most 10 kbp.

Return: The adjacency list corresponding to O3. You may return edges in any order.

Sample Dataset
>Rosalind_0498
AAATAAA
>Rosalind_2391
AAATTTT
>Rosalind_2323
TTTTCCC
>Rosalind_0442
AAATCCC
>Rosalind_5013
GGGTGGG

Sample Output
Rosalind_0498 Rosalind_2391
Rosalind_0498 Rosalind_0442
Rosalind_2391 Rosalind_2323

Read more »

visualization methods in ChIPseeker

After two weeks developed, I have added/updated some plot functions in ChIPseeker (version >=1.0.1).

ChIP peaks over Chromosomes

?View Code RSPLUS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
> files=getSampleFiles()
> peak=readPeakFile(files[[1]])
> peak
GRanges with 1331 ranges and 2 metadata columns:
         seqnames                 ranges strand   |             V4        V5
            <rle>              <iranges>  <rle>   |       <factor> <numeric>
     [1]     chr1     [ 815092,  817883]      *   |    MACS_peak_1    295.76
     [2]     chr1     [1243287, 1244338]      *   |    MACS_peak_2     63.19
     [3]     chr1     [2979976, 2981228]      *   |    MACS_peak_3    100.16
     [4]     chr1     [3566181, 3567876]      *   |    MACS_peak_4    558.89
     [5]     chr1     [3816545, 3818111]      *   |    MACS_peak_5     57.57
     ...      ...                    ...    ... ...            ...       ...
  [1327]     chrX [135244782, 135245821]      *   | MACS_peak_1327     55.54
  [1328]     chrX [139171963, 139173506]      *   | MACS_peak_1328    270.19
  [1329]     chrX [139583953, 139586126]      *   | MACS_peak_1329    918.73
  [1330]     chrX [139592001, 139593238]      *   | MACS_peak_1330    210.88
  [1331]     chrY [ 13845133,  13845777]      *   | MACS_peak_1331     58.39
  ---
  seqlengths:
    chr1 chr10 chr11 chr12 chr13 chr14 ...  chr6  chr7  chr8  chr9  chrX  chrY
      NA    NA    NA    NA    NA    NA ...    NA    NA    NA    NA    NA    NA
> plotChrCov(peak, weightCol="V5")
</numeric></factor></rle></iranges></rle>

chrCoverage
Read more »

ChIPseeker for ChIP peak annotation

ChIPpeakAnno WAS the only R package for ChIP peak annotation. I used it for annotating peak in my recent study.

I found it does not consider the strand information of genes. I reported the bug to the authors, but they are reluctant to change.

So I decided to develop my own package, ChIPseeker, and it's now available in Bioconductor.
Read more »