filter_vcf: filter_vcf_by_gff

View source: R/filtor.R

filter_vcfR Documentation

filter_vcf_by_gff

Description

filter vcf by gff file or by position or both

Usage

filter_vcf(vcf, gff = gff,
           mode = c("POS", "type", "both"),
           Chr = Chr, start = start, end = end,
           type = c("CDS", "exon", "gene", "genome", "custom"),
           cusTyp = c("CDS", "five_prime_UTR", "three_prime_UTR"))

Arguments

vcf

imported vcf

gff

imported gff

mode

filter mode, one of POS/type/both

Chr

CHROM name, needed if mode set to 'POS' or 'both'

start

Start position, needed if mode set to 'POS' or 'both'

end

End position, needed if mode set to 'POS' or 'both'

type

filter type, needed if mode set to 'type' or 'both', one of CDS/exon/gene/genome/custom, if type set to custom, the custom_type is needed.

cusTyp

vector, custom filter type, needed if type set to custom

Details

#' @description 根据变异位点所在区域的类型进行筛选 #' @title filter_hap_by_gff #' @usage #' filter_hap(gff = gff, #' hap = hap, #' hapPrefix_new = "C_H", #' type = c("CDS", "exon", "gene","genome", "custom"), #' custom_type = c("CDS", "exon", "gene")) #' @param gff gff文件 #' @param hap hap或hapResult #' @param hapPrefix_new new prefix for filtered haps #' @param type 筛选模式,CDS/exon/gene/genome/custom之一, #' 如果是custom则必须设定custom_type #' @param custom_type 自定义筛选模式 #' @importFrom IRanges start #' @importFrom IRanges ' #' @examples #' # filtet hap #' data("quickHap_test") #' hap <- get_hap(vcf) #' hap <- filter_hap(gff = gff, hap = hap, type = "CDS") #' #' @export filter_hap <- function(gff = gff, hap = hap, hapPrefix_new = "C_H", type = c("CDS", "exon", "gene", "genome", "custom"), custom_type = c("CDS", "exon", "gene")) if(!type stop('type must be one of c("CDS", "exon", "gene","genome", "custom")') if(type == "custom") type <- custom_type # filter gff file by type type if(type == "genome") gff <- gff else gff <- gff[gff$type meta <- hap[1:4,] POS <- suppressWarnings(as.numeric(meta[2,])) POS <- na.omit(POS) Chr <- meta[1,2] hapRange <- POS2GRanges(Chr = Chr, POS = POS) hapRange <- hapRange[!(hapRange POS_rm <- IRanges::start(hapRange) probe <- !(colnames(hap) hap <- hap[,probe] meta <- hap[1:4,] hap <- hap[5:nrow(hap), -1] hap <- assign_hapID(hap, hapPrefix = hapPrefix_new) hap <- rbind(meta, hap) return(hap)

Examples

# filtet hap
data("quickHap_test")
vcf_f1 <- filter_vcf(vcf, mode = "POS",
                    Chr = "scaffold_1",
                    start = 4300, end = 5890)

vcf_f2 <- filter_vcf(vcf, mode = "type",
                    gff = gff,
                    type = "CDS")
vcf_f3 <- filter_vcf(vcf, mode = "both",
                    Chr = "scaffold_1",
                    start = 4300, end = 5890,
                    gff = gff,
                    type = "CDS")


ZhangRenL/quickHapR documentation built on June 17, 2022, 12:04 a.m.