I created var_nt
dataframe by subsetting tx_df
columns based on row variant
- "J3", "J10", "J11", "J13".
Then, I converted the var_nt
dataframe to a GRanges
object (varnt_grange
) using the makeGRangesFromDataFrame
function.
Now, I want to write a for loop to collapse the varnt_grange
into a single vector.
library(SGSeq)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(BSgenome.Hsapiens.UCSC.hg19)
library(org.Hs.eg.db)
txf_df$variant <- with(txf_df, paste0(type, ave(1:nrow(txf_df), type, FUN=seq_along)))
var_nt <- subset(txf_df, variant %in% c("J3", "J10", "J11", "J13"))
varnt_grange <- makeGRangesFromDataFrame(var_nt, keep.extra.columns=T)
for (j in gene.list$entrez){
varnt_grange.nt <- varnt_grange[varnt_grange$geneName %in% j]
#Collapse the ranges of the genes into a single vector
varnt.grange.nt <- IRanges::reduce(varnt_grange.nt)
}
I'm expecting a single vector of gene ranges by I'm getting 0 ranges.
Output
> varnt.grange.nt
GRanges object with 0 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
Data:
> dput(txf_df)
structure(list(seqnames = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "16", class = "factor"),
start = c(12058964L, 12059311L, 12059311L, 12060052L, 12060198L,
12060198L, 12060877L, 12061000L, 12061427L, 23313591L, 23313758L,
23359913L, 23360231L, 23364122L, 23364395L, 23366620L, 23366810L,
23379177L, 23379280L, 23382620L, 23382783L, 23383097L, 23383204L,
23387059L, 23387176L, 23388486L, 23388561L, 23388650L, 23388707L,
23390027L, 23390088L, 23391415L, 23391490L, 23391742L, 23765948L,
23766437L, 23766982L, 23767054L, 23767168L, 23767248L, 23767384L,
23767514L, 23767709L, 23767770L, 23768522L, 23768644L, 23768851L,
25228285L, 25228378L, 25228519L, 25228766L, 25232778L, 25232904L,
25235683L, 25235897L, 25238389L, 25238523L, 25239765L, 29789561L,
29789627L, 29790581L, 29790642L, 29790826L, 29790958L, 29791425L,
56651502L, 56659585L, 56659791L, 56660378L, 56660378L, 56660443L,
56660792L, 56666534L, 56666671L, 56667252L, 56667317L, 56667663L,
56691855L, 56691998L, 56692587L, 56692652L, 56692985L, 56703726L,
56703824L, 56704418L, 56704483L, 56704810L, 66878282L, 66878430L,
66878841L, 66879137L, 66880933L, 66881130L, 66884444L, 66884562L,
66885366L, 66885461L, 66885567L, 66885629L, 66886615L, 66886770L,
66887279L, 66968347L, 66968374L, 66969614L, 66969879L, 66971940L,
66972144L, 66973120L, 66973261L, 66974125L, 66974258L, 66974340L,
66974598L, 66975027L, 66975125L, 66975409L, 66975549L, 66975671L,
66975751L, 66976008L, 66976152L, 66976551L, 66976551L, 66976640L,
66976688L, 66977202L, 66977274L, 66977742L, 67465036L, 67465416L,
67469531L, 67469743L, 67469860L, 67470045L, 67470152L, 67470289L,
67470491L, 82068858L, 82069294L, 82101775L, 82101987L, 82104547L,
82104732L, 82124507L, 82124644L, 82131680L, 56700653L, 56700882L,
56701224L, 56701224L, 56701289L, 56701292L, 56701878L, 75145758L,
75146419L, 75146500L, 75146611L, 75146732L, 75146822L, 75147433L,
75147560L, 75147640L, 75147768L, 75147864L, 75147864L, 75148063L,
75148132L, 75148424L, 75148583L, 75148725L, 75148866L, 75149096L,
75149237L, 75149446L, 75149558L, 75150547L), end = c(12059311L,
12060052L, 12061427L, 12060198L, 12060877L, 12061427L, 12061000L,
12061427L, 12061925L, 23313758L, 23359913L, 23360231L, 23364122L,
23364395L, 23366620L, 23366810L, 23379177L, 23379280L, 23382620L,
23382783L, 23383097L, 23383204L, 23387059L, 23387176L, 23388486L,
23388561L, 23388650L, 23388707L, 23390027L, 23390088L, 23391415L,
23391490L, 23391742L, 23392620L, 23766437L, 23766982L, 23767054L,
23767168L, 23767248L, 23767384L, 23767514L, 23767709L, 23767770L,
23768522L, 23768644L, 23768851L, 23770256L, 25228378L, 25228519L,
25228766L, 25232778L, 25232904L, 25235683L, 25235897L, 25238389L,
25238523L, 25239765L, 25240253L, 29789627L, 29790581L, 29790642L,
29790826L, 29790958L, 29791425L, 29792969L, 56667252L, 56659791L,
56660378L, 56660443L, 56661024L, 56660792L, 56661024L, 56666671L,
56667252L, 56667317L, 56667663L, 56667898L, 56691998L, 56692587L,
56692652L, 56692985L, 56693215L, 56703824L, 56704418L, 56704483L,
56704810L, 56705041L, 66878430L, 66880933L, 66879137L, 66880933L,
66881130L, 66884444L, 66884562L, 66885366L, 66885461L, 66885567L,
66885629L, 66886615L, 66886770L, 66887279L, 66888049L, 66969614L,
66969879L, 66971940L, 66971940L, 66972144L, 66973120L, 66973261L,
66974125L, 66974258L, 66974340L, 66974598L, 66975027L, 66975125L,
66975409L, 66975549L, 66975671L, 66975751L, 66976008L, 66976152L,
66976551L, 66976640L, 66976688L, 66977202L, 66977202L, 66977274L,
66977742L, 66978994L, 67465416L, 67469531L, 67469743L, 67469860L,
67470045L, 67470152L, 67470289L, 67470491L, 67471454L, 82069294L,
82101775L, 82101987L, 82104547L, 82104732L, 82124507L, 82124644L,
82131680L, 82132139L, 56700882L, 56701224L, 56701289L, 56701292L,
56701878L, 56701878L, 56701977L, 75146419L, 75146500L, 75146611L,
75146732L, 75146822L, 75147433L, 75147560L, 75147640L, 75147768L,
75147864L, 75148063L, 75148132L, 75148424L, 75148424L, 75148583L,
75148725L, 75148866L, 75149096L, 75149237L, 75149446L, 75149558L,
75150547L, 75150670L), width = c(348L, 742L, 2117L, 147L,
680L, 1230L, 124L, 428L, 499L, 168L, 46156L, 319L, 3892L,
274L, 2226L, 191L, 12368L, 104L, 3341L, 164L, 315L, 108L,
3856L, 118L, 1311L, 76L, 90L, 58L, 1321L, 62L, 1328L, 76L,
253L, 879L, 490L, 546L, 73L, 115L, 81L, 137L, 131L, 196L,
62L, 753L, 123L, 208L, 1406L, 94L, 142L, 248L, 4013L, 127L,
2780L, 215L, 2493L, 135L, 1243L, 489L, 67L, 955L, 62L, 185L,
133L, 468L, 1545L, 15751L, 207L, 588L, 66L, 647L, 350L, 233L,
138L, 582L, 66L, 347L, 236L, 144L, 590L, 66L, 334L, 231L,
99L, 595L, 66L, 328L, 232L, 149L, 2504L, 297L, 1797L, 198L,
3315L, 119L, 805L, 96L, 107L, 63L, 987L, 156L, 510L, 771L,
1268L, 1506L, 2327L, 2062L, 205L, 977L, 142L, 865L, 134L,
83L, 259L, 430L, 99L, 285L, 141L, 123L, 81L, 258L, 145L,
400L, 90L, 138L, 563L, 515L, 73L, 469L, 1253L, 381L, 4116L,
213L, 118L, 186L, 108L, 138L, 203L, 964L, 437L, 32482L, 213L,
2561L, 186L, 19776L, 138L, 7037L, 460L, 230L, 343L, 66L,
69L, 590L, 587L, 100L, 662L, 82L, 112L, 122L, 91L, 612L,
128L, 81L, 129L, 97L, 200L, 269L, 362L, 293L, 160L, 143L,
142L, 231L, 142L, 210L, 113L, 990L, 124L), strand = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(" ",
"-", "*"), class = "factor"), type = structure(c(3L, 1L,
1L, 2L, 1L, 1L, 2L, 1L, 4L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 4L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 4L,
3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 4L, 3L, 1L, 2L, 1L,
2L, 1L, 4L, 1L, 3L, 1L, 2L, 4L, 1L, 4L, 3L, 1L, 2L, 1L, 4L,
3L, 1L, 2L, 1L, 4L, 3L, 1L, 2L, 1L, 4L, 3L, 1L, 3L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 4L, 3L, 3L, 1L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 1L, 2L, 1L, 4L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
4L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 4L, 4L, 1L, 2L, 2L, 1L,
1L, 3L, 4L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L), .Label = c("J",
"I", "F", "L", "U"), class = "factor"), txName = structure(list(
c("uc002dbv.3", "uc010buy.3", "uc010buz.3"), c("uc002dbv.3",
"uc010buy.3"), "uc010buz.3", c("uc002dbv.3", "uc010buy.3"
), "uc010buy.3", "uc002dbv.3", "uc010buy.3", "uc010buy.3",
c("uc002dbv.3", "uc010buy.3", "uc010buz.3"), "uc002dln.3",
"uc002dln.3", "uc002dln.3", "uc002dln.3", "uc002dln.3",
"uc002dln.3", "uc002dln.3", "uc002dln.3", "uc002dln.3",
"uc002dln.3", "uc002dln.3", "uc002dln.3", "uc002dln.3",
"uc002dln.3", "uc002dln.3", "uc002dln.3", "uc002dln.3",
"uc002dln.3", "uc002dln.3", "uc002dln.3", "uc002dln.3",
"uc002dln.3", "uc002dln.3", "uc002dln.3", "uc002dln.3",
"uc002dmb.1", "uc002dmb.1", "uc002dmb.1", "uc002dmb.1",
"uc002dmb.1", "uc002dmb.1", "uc002dmb.1", "uc002dmb.1",
"uc002dmb.1", "uc002dmb.1", "uc002dmb.1", "uc002dmb.1",
"uc002dmb.1", "uc002doc.3", "uc002doc.3", "uc002doc.3",
"uc002doc.3", "uc002doc.3", "uc002doc.3", "uc002doc.3",
"uc002doc.3", "uc002doc.3", "uc002doc.3", "uc002doc.3",
"uc002dtr.4", "uc002dtr.4", "uc002dtr.4", "uc002dtr.4",
"uc002dtr.4", "uc002dtr.4", "uc002dtr.4", "uc010vhe.2",
c("uc002ejl.3", "uc002ejm.3"), c("uc002ejl.3", "uc002ejm.3"
), "uc002ejl.3", "uc002ejm.3", "uc002ejl.3", "uc002ejl.3",
"uc002ejn.3", "uc002ejn.3", c("uc010vhe.2", "uc002ejn.3"
), c("uc010vhe.2", "uc002ejn.3"), c("uc010vhe.2", "uc002ejn.3"
), "uc002ejt.3", "uc002ejt.3", "uc002ejt.3", "uc002ejt.3",
"uc002ejt.3", "uc002ejw.3", "uc002ejw.3", "uc002ejw.3",
"uc002ejw.3", "uc002ejw.3", "uc002eqi.3", "uc002eqi.3",
"uc002eqj.3", "uc002eqj.3", c("uc002eqi.3", "uc002eqj.3"
), c("uc002eqi.3", "uc002eqj.3"), c("uc002eqi.3", "uc002eqj.3"
), c("uc002eqi.3", "uc002eqj.3"), c("uc002eqi.3", "uc002eqj.3"
), c("uc002eqi.3", "uc002eqj.3"), c("uc002eqi.3", "uc002eqj.3"
), c("uc002eqi.3", "uc002eqj.3"), c("uc002eqi.3", "uc002eqj.3"
), c("uc002eqi.3", "uc002eqj.3"), c("uc002eqi.3", "uc002eqj.3"
), c("uc002eqq.3", "uc002eqr.3"), "uc002eqs.3", c("uc002eqq.3",
"uc002eqr.3"), "uc002eqs.3", c("uc002eqq.3", "uc002eqr.3",
"uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"
), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3",
"uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3",
"uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"
), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3",
"uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3",
"uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"
), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3",
"uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3",
"uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"
), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3",
"uc002eqr.3", "uc002eqs.3"), "uc002eqq.3", c("uc002eqr.3",
"uc002eqs.3"), "uc002eqq.3", c("uc002eqr.3", "uc002eqs.3"
), c("uc002eqq.3", "uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3",
"uc002eqr.3", "uc002eqs.3"), c("uc002eqq.3", "uc002eqr.3",
"uc002eqs.3"), "uc002etd.3", "uc002etd.3", "uc002etd.3",
"uc002etd.3", "uc002etd.3", "uc002etd.3", "uc002etd.3",
"uc002etd.3", "uc002etd.3", "uc002fgv.3", "uc002fgv.3",
"uc002fgv.3", "uc002fgv.3", "uc002fgv.3", "uc002fgv.3",
"uc002fgv.3", "uc002fgv.3", "uc002fgv.3", c("uc002eju.1",
"uc002ejv.1"), c("uc002eju.1", "uc002ejv.1"), "uc002eju.1",
"uc002ejv.1", "uc002eju.1", "uc002ejv.1", c("uc002eju.1",
"uc002ejv.1"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), "uc002fdn.3", "uc002fdm.3", "uc002fdn.3",
"uc002fdm.3", c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3"), c("uc002fdm.3",
"uc002fdn.3"), c("uc002fdm.3", "uc002fdn.3")), class = "AsIs"),
geneName = structure(list("608", "608", "608", "608", "608",
"608", "608", "608", "608", "6338", "6338", "6338", "6338",
"6338", "6338", "6338", "6338", "6338", "6338", "6338",
"6338", "6338", "6338", "6338", "6338", "6338", "6338",
"6338", "6338", "6338", "6338", "6338", "6338", "6338",
"63928", "63928", "63928", "63928", "63928", "63928",
"63928", "63928", "63928", "63928", "63928", "63928",
"63928", "343", "343", "343", "343", "343", "343", "343",
"343", "343", "343", "343", "653808", "653808", "653808",
"653808", "653808", "653808", "653808", "4499", "4493",
"4493", "4493", "4493", "4493", "4493", "4499", "4499",
"4499", "4499", "4499", "4494", "4494", "4494", "4494",
"4494", "4496", "4496", "4496", "4496", "4496", "766",
"766", "766", "766", "766", "766", "766", "766", "766",
"766", "766", "766", "766", "766", "766", "8824", "8824",
"8824", "8824", "8824", "8824", "8824", "8824", "8824",
"8824", "8824", "8824", "8824", "8824", "8824", "8824",
"8824", "8824", "8824", "8824", "8824", "8824", "8824",
"8824", "8824", "8824", "8824", "3291", "3291", "3291",
"3291", "3291", "3291", "3291", "3291", "3291", "3294",
"3294", "3294", "3294", "3294", "3294", "3294", "3294",
"3294", "4495", "4495", "4495", "4495", "4495", "4495",
"4495", "197257", "197257", "197257", "197257", "197257",
"197257", "197257", "197257", "197257", "197257", "197257",
"197257", "197257", "197257", "197257", "197257", "197257",
"197257", "197257", "197257", "197257", "197257", "197257"), class = "AsIs"),
variant = c("F1", "J1", "J2", "I1", "J3", "J4", "I2", "J5",
"L1", "F2", "J6", "I3", "J7", "I4", "J8", "I5", "J9", "I6",
"J10", "I7", "J11", "I8", "J12", "I9", "J13", "I10", "J14",
"I11", "J15", "I12", "J16", "I13", "J17", "L2", "F3", "J18",
"I14", "J19", "I15", "J20", "I16", "J21", "I17", "J22", "I18",
"J23", "L3", "F4", "J24", "I19", "J25", "I20", "J26", "I21",
"J27", "I22", "J28", "L4", "F5", "J29", "I23", "J30", "I24",
"J31", "L5", "J32", "F6", "J33", "I25", "L6", "J34", "L7",
"F7", "J35", "I26", "J36", "L8", "F8", "J37", "I27", "J38",
"L9", "F9", "J39", "I28", "J40", "L10", "F10", "J41", "F11",
"J42", "I29", "J43", "I30", "J44", "I31", "J45", "I32", "J46",
"I33", "J47", "L11", "F12", "F13", "J48", "J49", "I34", "J50",
"I35", "J51", "I36", "J52", "I37", "J53", "I38", "J54", "I39",
"J55", "I40", "J56", "I41", "J57", "I42", "I43", "J58", "J59",
"I44", "J60", "L12", "F14", "J61", "I45", "J62", "I46", "J63",
"I47", "J64", "L13", "F15", "J65", "I48", "J66", "I49", "J67",
"I50", "J68", "L14", "L15", "J69", "I51", "I52", "J70", "J71",
"F16", "L16", "J72", "I53", "J73", "I54", "J74", "I55", "J75",
"I56", "J76", "I57", "I58", "J77", "J78", "I59", "J79", "I60",
"J80", "I61", "J81", "I62", "J82", "F17")), row.names = c(NA,
-177L), class = "data.frame")
> dput(gene.list)
structure(list(Name = c("AQP8", "ZG16", "SCNN1B", "HSD11B2",
"TNFRSF17", "MT1M", "CHP2", "CA7", "HSD17B2", "MT1F", "LDHD",
"MT1G", "CES2", "MT1H", "MT1E"), Pvalue = c(3.24077275512836e-22,
4.14482213350182e-20, 1.6959409570969e-15, 8.67986104627575e-15,
3.17491475337798e-14, 3.30811992851482e-14, 5.0515106987893e-14,
5.68405659634921e-14, 1.24665357114941e-13, 3.05854823676429e-11,
2.03309742743294e-10, 1.23297016072789e-09, 3.88663170713946e-09,
6.55970351161761e-09, 1.98303161562218e-08), adjPvalue = c(8.3845272720681e-18,
1.07234838237959e-15, 4.38773844420109e-11, 2.24565364989246e-10,
8.21413944993951e-10, 8.55876787905354e-10, 1.30692684799077e-09,
1.47057912260747e-09, 3.22534211927776e-09, 7.91307599815656e-07,
5.2600296642545e-06, 3.18994039983521e-05, 0.000100554935527112,
0.000169712649252571, 0.00051304993959377), logFC = c(-3.73323340223377,
-2.87787132076412, -1.77694418475864, -1.55599182329306, -1.96370011101605,
-2.17842791093474, -2.24624889090768, -1.72194537032388, -2.07646463308581,
-1.25614441032473, -1.34216716634308, -1.30886936099932, -1.07391001123839,
-1.46153658305282, -1.01454529904826), entrez = c(AQP8 = "343",
ZG16 = "653808", SCNN1B = "6338", HSD11B2 = "3291", TNFRSF17 = "608",
MT1M = "4499", CHP2 = "63928", CA7 = "766", HSD17B2 = "3294",
MT1F = "4494", LDHD = "197257", MT1G = "4495", CES2 = "8824",
MT1H = "4496", MT1E = "4493")), row.names = c(1L, 4L, 18L, 26L,
31L, 32L, 33L, 35L, 43L, 82L, 100L, 118L, 135L, 152L, 171L), class = "data.frame")
CodePudding user response:
On each iteration, you are inadvertently rewriting over the same object, repeatedly. Instead, you can iterate over the values in gene.list$entrez using lapply
varnt_grange.nt =lapply(gene.list$entrez, function(j){
IRanges::reduce(varnt_grange[varnt_grange$geneName %in% j])
})
This will return you a list of GRange objects; many of the elements of this list are NULL, as iterates over all j
, but only two of them appear in varnt_grange$geneName
You can deal with that in many different ways; one way is to lapply only over those two like this:
lapply(gene.list$entrez[which(gene.list$entrez %in% varnt_grange$geneName)],
function(j) IRanges::reduce(varnt_grange[varnt_grange$geneName %in% j])
)
Output:
$SCNN1B
GRanges object with 3 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] 16 23379280-23382620
[2] 16 23382783-23383097
[3] 16 23387176-23388486
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
$TNFRSF17
GRanges object with 1 range and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] 16 12060198-12060877
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths