Stacks Image 20108

For Academics

Merge data

You will often want to combine different datasets with a column in common. This is easy to do in R.

For example the mapping of sequencing reads of different tissues to contigs generated from all the reads.

It could also be different information on the same individuals.

In the sequencing example, the mapping datasets may not fully overlap. For example contig 1 may be represented in tissue 1, but not tissue 2, and hence dataset1 but not dataset2.

We would like to merge the datasets based on their common column (contig). The resulting dataset can be used for statistical analysis, for example for differences in the read number per tissue.

This is straightforward in R using the merge command.

First load the datasets:

tissueData1<-read.table("/Users/username/Desktop/tissueData1", header=T)
tissueData2<-read.table("/Users/username/Desktop/tissueData2.txt", header=T)
tissueData3<-read.table("/Users/username/Desktop/tissueData3.txt", header=T)
tissueData4<-read.table("/Users/username/Desktop/tissueData4.txt", header=T)

Now merge by adding one dataset at a time. We merge based on the total_contig and tissue_contig columns, which have overlapping values (i.e. contig1, contig2, etc).

merged1=merge(tissueData1, tissueData2, by.x="tissue1_contig", by.y="tissue2_contig", all=T )
merged2=merge(merged1, tissueData3, by.x="total_contig", by.y="tissue3_contig", all=T )
mergedData=merge(merged3, tissueData4, by.x="total_contig", by.y="tissue4_contig", all=T )

Note: all=T retains the data from rows that did not have a common value in the columns used for merging. In this case NAs are automatically added to the values in the merged row.

The merge command can do more tricks, to learn more about it:

Previous Post 31 / 50 Post


Sex chromosome papers RSS

Chromosome-level genome assembly and sex chromosome identification of the pink stem borer, Sesamia inferens (Lepidoptera: Noctuidae)

The genome sequence of a ground beetle, Ophonus ardosiacus (Lutshnik, 1922)

The genome sequence of a hoverfly, Pocota personata (Harris, 1780)