This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to obtain TSS from list of given genes

Hi all,

I have a list of genes (see format below) and I would like to obtain the TSS for all 19 of these genes. How can I do this?

ENSMUSG00000029847
ENSMUSG00000085236
ENSMUSG00000063364
ENSMUSG00000085247
ENSMUSG00000072893
ENSMUSG00000018800
ENSMUSG00000020865
ENSMUSG00000023832
ENSMUSG00000045730
ENSMUSG00000007827
ENSMUSG00000021950
ENSMUSG00000071847
ENSMUSG00000025154
ENSMUSG00000047446
ENSMUSG00000026628
ENSMUSG00000029673
rna-seq r

could you provide the format, please

ENSMUSG00000029847
ENSMUSG00000085236
ENSMUSG00000063364
ENSMUSG00000085247
ENSMUSG00000072893
ENSMUSG00000018800
ENSMUSG00000020865
ENSMUSG00000023832
ENSMUSG00000045730
ENSMUSG00000007827
ENSMUSG00000021950
ENSMUSG00000071847
ENSMUSG00000025154
ENSMUSG00000047446
ENSMUSG00000026628
ENSMUSG00000029673
ENSMUSG00000021070
ENSMUSG00000051331
ENSMUSG00000025468
ENSMUSG00000025076
ENSMUSG00000034303
ENSMUSG00000031841
ENSMUSG00000037628
ENSMUSG00000071637
ENSMUSG00000016028
ENSMUSG00000056267
ENSMUSG00000022945
ENSMUSG00000057337
ENSMUSG00000062248
ENSMUSG00000004473
ENSMUSG00000045672
ENSMUSG00000015224
ENSMUSG00000001467
ENSMUSG00000002297
ENSMUSG00000027797
ENSMUSG00000007682
ENSMUSG00000020143
ENSMUSG00000024501
ENSMUSG00000031530
ENSMUSG00000022838
ENSMUSG00000063600
ENSMUSG00000035105
ENSMUSG00000037868
ENSMUSG00000048029
ENSMUSG00000019978
ENSMUSG00000015766
ENSMUSG00000055184
ENSMUSG00000006369
ENSMUSG00000073633
ENSMUSG00000057967
ENSMUSG00000021250
ENSMUSG00000035451
ENSMUSG00000052135
ENSMUSG00000047604
ENSMUSG00000026657
ENSMUSG00000030703
ENSMUSG00000039131
ENSMUSG00000036395
ENSMUSG00000074178
ENSMUSG00000069170
ENSMUSG00000096807
ENSMUSG00000060639
ENSMUSG00000054717
ENSMUSG00000021676
ENSMUSG00000038894
ENSMUSG00000025321
ENSMUSG00000052684
ENSMUSG00000052837
ENSMUSG00000055675
ENSMUSG00000047959
ENSMUSG00000027827
ENSMUSG00000058248
ENSMUSG00000023243
ENSMUSG00000033863
ENSMUSG00000071537
ENSMUSG00000021798
ENSMUSG00000079330
ENSMUSG00000028613
ENSMUSG00000033105
ENSMUSG00000040488
ENSMUSG00000029910
ENSMUSG00000027377
ENSMUSG00000022324
ENSMUSG00000038732
ENSMUSG00000041607
ENSMUSG00000032776
ENSMUSG00000028655
ENSMUSG00000029490
ENSMUSG00000041945
ENSMUSG00000036155
ENSMUSG00000040987
ENSMUSG00000033752
ENSMUSG00000006517
ENSMUSG00000022836
ENSMUSG00000039057
ENSMUSG00000049690
ENSMUSG00000079481
ENSMUSG00000038879
ENSMUSG00000055761
ENSMUSG00000055994
ENSMUSG00000032939
ENSMUSG00000048148
ENSMUSG00000066861
ENSMUSG00000032661
ENSMUSG00000009654
ENSMUSG00000039196
ENSMUSG00000022330
ENSMUSG00000075270
ENSMUSG00000059173
ENSMUSG00000074661
ENSMUSG00000021699
ENSMUSG00000074661
ENSMUSG00000021699
ENSMUSG00000023795
ENSMUSG00000028023
ENSMUSG00000048827
ENSMUSG00000028909
ENSMUSG00000006411
ENSMUSG00000021708
ENSMUSG00000046402
ENSMUSG00000019944
ENSMUSG00000039328
ENSMUSG00000021838
ENSMUSG00000031604
ENSMUSG00000026039
ENSMUSG00000032908
ENSMUSG00000032261
ENSMUSG00000040749
ENSMUSG00000019838
ENSMUSG00000035472
ENSMUSG00000005107
ENSMUSG00000041313
ENSMUSG00000056427
ENSMUSG00000029093
ENSMUSG00000021990
ENSMUSG00000038451
ENSMUSG00000036825
ENSMUSG00000028718
ENSMUSG00000059602
ENSMUSG00000038347
ENSMUSG00000039179
ENSMUSG00000024727
ENSMUSG00000000244
ENSMUSG00000033222
ENSMUSG00000036752
ENSMUSG00000073016
ENSMUSG00000028560
ENSMUSG00000032010
ENSMUSG00000027831
ENSMUSG00000027840
ENSMUSG00000035045
ENSMUSG00000068551

Hi Giovanni,

Thank you for the help!

A few questions: (I am relevatively new to R).

for mygenes.transcripts, I had copy and pasted

mygenes.transcripts = subset(transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns=c("tx_id", "tx_name","gene_id")), gene_id %in% mygenes)

but error keeps saying 

Error in subset(transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns = c("tx_id",  : 
  error in evaluating the argument 'x' in selecting a method for function 'subset': Error in transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns = c("tx_id",  : 
  error in evaluating the argument 'x' in selecting a method for function 'transcripts': Error: object 'TxDb.Mmusculus.UCSC.mm10.ensGene' not found

1 answer

There are many ways to do this. Apart from biomaRt, you can use the Mus musculus TxDb object:

> source("https://bioconductor.org/biocLite.R")
> biocLite('TxDb.Mmusculus.UCSC.mm10.ensGene')
> mygenes = c("ENSMUSG00000029847",
"ENSMUSG00000085236", "ENSMUSG00000063364","ENSMUSG00000085247",
"ENSMUSG00000072893","ENSMUSG00000018800","ENSMUSG00000020865",
"ENSMUSG00000023832","ENSMUSG00000045730","ENSMUSG00000007827",
"ENSMUSG00000021950","ENSMUSG00000071847","ENSMUSG00000025154",
"ENSMUSG00000047446","ENSMUSG00000026628","ENSMUSG00000029673")

> mygenes.transcripts = subset(transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns=c("tx_id", "tx_name","gene_id")), gene_id %in% mygenes)
GRanges object with 62 ranges and 3 metadata columns:
       seqnames                 ranges strand   |     tx_id            tx_name            gene_id
          <Rle>              <IRanges>  <Rle>   | <integer>        <character>    <CharacterList>
   [1]     chr1 [191170296, 191183340]      -   |      4925 ENSMUST00000027941 ENSMUSG00000026628
   [2]     chr1 [191171425, 191183108]      -   |      4926 ENSMUST00000131854 ENSMUSG00000026628
   [3]     chr2 [135169573, 135215616]      -   |     13731 ENSMUST00000138303 ENSMUSG00000085247
   [4]     chr2 [150310935, 150362765]      -   |     13893 ENSMUST00000051153 ENSMUSG00000063364
   [5]     chr2 [150310937, 150362733]      -   |     13894 ENSMUST00000124945 ENSMUSG00000063364
   ...      ...                    ...    ... ...       ...                ...                ...
  [58]    chr18   [62177817, 62179959]      -   |     86501 ENSMUST00000053640 ENSMUSG00000045730
  [59]    chr19   [41766588, 41802047]      -   |     88750 ENSMUST00000026150 ENSMUSG00000025154
  [60]    chr19   [41766591, 41802084]      -   |     88751 ENSMUST00000163265 ENSMUSG00000025154
  [61]    chr19   [41769800, 41781336]      -   |     88752 ENSMUST00000176266 ENSMUSG00000025154
  [62]    chr19   [41769994, 41802047]      -   |     88753 ENSMUST00000177495 ENSMUSG00000025154

This will create a GenomicRanges object called mygenes.transcripts, from which you can access the coordinates of all transcripts of each gene. If you want to avoid complications and prefer to have just one coordinate per gene, use genes() instead of transcripts()

To get the TSS, just resize the object to one base:

> mygenes.tss = resize(mygenes.transcripts, width=1, fix='start')

I ran into some errors and had to specify the package namespaces and load the GenomicFeatures library:

> source("https://bioconductor.org/biocLite.R")
...
> biocLite('TxDb.Mmusculus.UCSC.mm10.ensGene')
...
> library("GenomicFeatures")
...
> mygenes = c("ENSMUSG00000029847",
"ENSMUSG00000085236", "ENSMUSG00000063364","ENSMUSG00000085247",
"ENSMUSG00000072893","ENSMUSG00000018800","ENSMUSG00000020865",
"ENSMUSG00000023832","ENSMUSG00000045730","ENSMUSG00000007827",
"ENSMUSG00000021950","ENSMUSG00000071847","ENSMUSG00000025154",
"ENSMUSG00000047446","ENSMUSG00000026628","ENSMUSG00000029673")
> mygenes.transcripts = subset(GenomicFeatures::transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene::TxDb.Mmusculus.UCSC.mm10.ensGene, columns=c("tx_id", "tx_name","gene_id")), gene_id %in% mygenes)
GRanges object with 62 ranges and 3 metadata columns:
       seqnames                 ranges strand   |     tx_id            tx_name
          <Rle>              <IRanges>  <Rle>   | <integer>        <character>
   [1]     chr1 [191170296, 191183340]      -   |      4925 ENSMUST00000027941
   [2]     chr1 [191171425, 191183108]      -   |      4926 ENSMUST00000131854
   [3]     chr2 [135169573, 135215616]      -   |     13731 ENSMUST00000138303
   [4]     chr2 [150310935, 150362765]      -   |     13893 ENSMUST00000051153
   [5]     chr2 [150310937, 150362733]      -   |     13894 ENSMUST00000124945
   ...      ...                    ...    ... ...       ...                ...
  [58]    chr18   [62177817, 62179959]      -   |     86501 ENSMUST00000053640
  [59]    chr19   [41766588, 41802047]      -   |     88750 ENSMUST00000026150
  [60]    chr19   [41766591, 41802084]      -   |     88751 ENSMUST00000163265
  [61]    chr19   [41769800, 41781336]      -   |     88752 ENSMUST00000176266
  [62]    chr19   [41769994, 41802047]      -   |     88753 ENSMUST00000177495
                  gene_id
          <CharacterList>
   [1] ENSMUSG00000026628
   [2] ENSMUSG00000026628
   [3] ENSMUSG00000085247
   [4] ENSMUSG00000063364
   [5] ENSMUSG00000063364
   ...                ...
  [58] ENSMUSG00000045730
  [59] ENSMUSG00000025154
  [60] ENSMUSG00000025154
  [61] ENSMUSG00000025154
  [62] ENSMUSG00000025154
  -------
  seqinfo: 66 sequences (1 circular) from mm10 genome

It looks like the fix setting in resize uses the correct start position for the interval's strand. Note that these resized coordinates are 1-based, if the OP plans to ultimately export BED data.

Thank you for the correction. Indeed many Bioconductor libraries have problems of namespaces. In particular loading dplyr after AnnotationDbi causes a lot of naming conflicts, e.g. on the select function.

Hi Giovanni,

Thank you for the help!

A few questions: (I am relevatively new to R).

for mygenes.transcripts, I had copy and pasted

mygenes.transcripts = subset(transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns=c("tx_id", "tx_name","gene_id")), gene_id %in% mygenes)

but error keeps saying

Error in subset(transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns = c("tx_id",  : 
  error in evaluating the argument 'x' in selecting a method for function 'subset': Error in transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns = c("tx_id",  : 
  error in evaluating the argument 'x' in selecting a method for function 'transcripts': Error: object 'TxDb.Mmusculus.UCSC.mm10.ensGene' not found

Hi Giovanni,

Thank you for the help!

A few questions: (I am relevatively new to R).

for mygenes.transcripts, I had copy and pasted

mygenes.transcripts = subset(transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns=c("tx_id", "tx_name","gene_id")), gene_id %in% mygenes)

but error keeps saying

Error in subset(transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns = c("tx_id",  : 
  error in evaluating the argument 'x' in selecting a method for function 'subset': Error in transcripts(TxDb.Mmusculus.UCSC.mm10.ensGene, columns = c("tx_id",  : 
  error in evaluating the argument 'x' in selecting a method for function 'transcripts': Error: object 'TxDb.Mmusculus.UCSC.mm10.ensGene' not found

Also, on a separate note: how do I format mygenes if I have about 150 genes? Would I have to manually type in these ensemble IDs or is there a shortcut?

Thank you in advance,
Tanni

Save your ensembl IDs in a file, one per line, then read it with read.csv('filename', header=FALSE)

You need to install the Mus musculus TxDb package in your system. The easiest way is to run biocLite('Mus.musculus') which will also install other mouse-related libraries.

When doing this, aren't you ignoring the strand? If the strand is '-', we should take the end as the start, right?

Log in to answer this question.