Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################
- # Explore genomics regions #
- ######################################
- # Script file for the video "Hunt for genes! | How to extract gene content of genomic regions" on the Genomics Boot Camp YouTube channel
- # Clear workspace
- rm(list = ls())
- # Set working directory
- setwd("d:/analysis/2020_GenomicsBootCamp_Demo/")
- # load packages
- if (!require("tidyverse")) {
- install.packages("tidyverse", dependencies = TRUE)
- library(tidyverse)
- }
- if (!require("qqman")) {
- install.packages("qqman", dependencies = TRUE)
- library(qqman)
- }
- #load and visualize Fst results
- data <- read_delim("FstResults.fst", delim = "\t") %>%
- drop_na()
- manhattan(data, chr = "CHR", bp = "POS", p = "FST", logp = F, suggestiveline = 0.8)
- #########################
- # Regions of interest (RoI)
- #########################
- # Required input data format: chromosome:startPosition:endPosition, e.g. "1:13280734:31789988"
- segmentsBiomart <- data %>%
- filter(FST >= 0.8) %>%
- mutate(RoI = paste(CHR,POS-250000,POS+250000,sep = ":")) %>%
- dplyr::select(RoI) %>%
- t()
- write_delim(as.data.frame(t(segmentsBiomart)), "RoI4BioMart.txt", col_names = F,delim = ",")
- ################################
- # Extract genomic regions with biomaRt
- ################################
- if (!requireNamespace("BiocManager", quietly = TRUE))
- install.packages("BiocManager")
- BiocManager::install("biomaRt")
- library("biomaRt")
- browseVignettes("biomaRt")
- listMarts(host="www.ensembl.org")
- ensembl <- useMart("ensembl")
- datasets <- listDatasets(ensembl) ## to show names of all databases
- ## protein coding genes - for all genes detele "biotype"
- ensembl = useMart(biomart="ENSEMBL_MART_ENSEMBL",dataset="chircus_gene_ensembl")
- attributes = listAttributes(ensembl) ## to show name of all possibilities
- filters = listFilters(ensembl)
- biomaRt_results=getBM(attributes = c("ensembl_gene_id", "external_gene_name", "gene_biotype",
- "go_id", "name_1006", "definition_1006", "go_linkage_type", "namespace_1003",
- "kegg_enzyme",
- "chromosome_name", "start_position", "end_position","description"),
- filters = c("chromosomal_region","biotype"),
- values =list(chromosomal_region=segmentsBiomart,biotype="protein_coding"),
- mart =ensembl)
- #write out results
- # take care, with a lot of attributes and segments the txt files could be large
- write_delim(biomaRt_results, "resultsFromBioMart.txt", delim = ";")
- ################################
- # post-processing of biomaRt results
- ################################
- # read back results to extract gene names or follow up with post processing
- # biomaRt_results <- read_delim("resultsFromBioMart.txt", delim = ";")
- # example - list of gene names
- geneNames <- biomaRt_results %>%
- drop_na(external_gene_name) %>%
- dplyr::select(external_gene_name) %>%
- unique() %>%
- write_delim("listOfGenes_Fst_AngGum.txt", delim = ";")
Advertisement
Add Comment
Please, Sign In to add comment