如何在R中每个样本连接两个DNAStringSet序列? [英] How to concatenate two DNAStringSet sequences per sample in R?

查看:50
本文介绍了如何在R中每个样本连接两个DNAStringSet序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 Large DNAStringSet 对象,其中每个对象包含2805个条目,每个对象的长度为201.我想简单地将它们组合起来,所以要具有2805个条目,因为每个对象都是这个大小,但是我想拥有一个对象,将两者结合起来.

I have two Large DNAStringSet objects, where each of them contain 2805 entries and each of them has length of 201. I want to simply combine them, so to have 2805 entries because each of them are this size, but I want to have one object, combination of both.

我试图这样做

s12 <- c(unlist(s1), unlist(s2))

但是创建了一个具有1127610个元素的单个 Large DNAString 对象,这不是我想要的.我只是想将每个样本合并在一起.

But that created single Large DNAString object with 1127610 elements, and this is not what I want. I simply want to combine them per sample.

我的 DNASTringSet 对象中名为 s1 s2 的每个条目的格式都与此类似:

Each entry in my DNASTringSet objects named s1 and s2, have similar format to this:

    width seq
[1]   201 CCATCCCAGGGGTGATGCCAAGTGATTCCA...CTAACTCTGGGGTAATGTCCTGCAGCCGG

推荐答案

如果您的目标是返回一个列表,其中每个列表元素是原始列表中相应列表元素的串联,则返回长度为2805的列表,其中每个列表元素的长度为402,您可以使用 Map 来实现.这是一个带有较小列表对的示例.

If your goal is to return a list where each list element is the concatenation of the corresponding list elements from the original lists restulting in a list of with length 2805 where each list element has a length of 402, you can achieve this with Map. Here is an example with a smaller pair of lists.

# set up the lists
set.seed(1234)
list.a <- list(a=1:5, b=letters[1:5], c=rnorm(5))
list.b <- list(a=6:10, b=letters[6:10], c=rnorm(5))

每个列表包含3个元素,它们是长度为5的向量.现在,使用 Map c 将列表按列表位置连接起来:

Each list contains 3 elements, which are vectors of length 5. Now, concatenate the lists by list position with Map and c:

Map(c, list.a, list.b)
$a
 [1]  1  2  3  4  5  6  7  8  9 10

$b
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"

$c
 [1] -1.2070657  0.2774292  1.0844412 -2.3456977  0.4291247  0.5060559 
     -0.5747400 -0.5466319 -0.5644520 -0.8900378

对于您所描述的问题,可以使用

For your problem as you have described it, you would use

s12 <- Map(c, s1, s2)

Map 的第一个参数是一个函数,该函数告诉 Map 如何处理给定的列表项.在这些列表项的上方是a和b,在您的示例中,它们是s1和s2.

The first argument of Map is a function that tells Map what to do with the list items that you have given it. Above those list items are a and b, in your example, they are s1 and s2.

这篇关于如何在R中每个样本连接两个DNAStringSet序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆