数据来源于ngsplot的MSU的基因组文件
load("F:/H3K9hib_salt/WT_chip-seq/Meta_plots/MSUv7.ensembl.exon.promoter.protein_coding.RData")
# 检查对象的类型
class(genome.coord)
# 尝试将对象转换为数据框
if (class(genome.coord) != "data.frame") {
genome.coord <- as.data.frame(genome.coord)
print("The object has been converted to a data frame.")
} else {
print("The object is already a data frame.")
}
# 查看转换后的数据框内容
head(genome.coord)
chrom start end gid gname tid strand class biotype byname.uniq bygid.uniq
75652 ChrSy 785 1168 ChrSy.fgenesh.gene.1 ChrSy.fgenesh.gene.1 ChrSy.fgenesh.mRNA.1 - promoter protein_coding TRUE TRUE
329717 ChrSy 50779 51012 ChrSy.fgenesh.gene.10 ChrSy.fgenesh.gene.10 ChrSy.fgenesh.mRNA.10 - promoter protein_coding TRUE TRUE
337755 ChrSy 53593 53841 ChrSy.fgenesh.gene.11 ChrSy.fgenesh.gene.11 ChrSy.fgenesh.mRNA.11 - promoter protein_coding TRUE TRUE
325371 ChrSy 58993 59748 ChrSy.fgenesh.gene.12 ChrSy.fgenesh.gene.12 ChrSy.fgenesh.mRNA.12 + promoter protein_coding TRUE TRUE
93954 ChrSy 68366 68668 ChrSy.fgenesh.gene.13 ChrSy.fgenesh.gene.13 ChrSy.fgenesh.mRNA.13 - promoter protein_coding TRUE TRUE
152362 ChrSy 73936 74597 ChrSy.fgenesh.gene.14 ChrSy.fgenesh.gene.14 ChrSy.fgenesh.mRNA.14 + promoter protein_coding TRUE TRUE
转化为bed文件
bed_data <- genome.coord[, c("chrom", "start", "end", "gid", "strand")]
# 确保列名符合 BED 文件格式
colnames(bed_data) <- c("chrom", "chromStart", "chromEnd", "name", "strand")
# 查看转换后的数据框内容
head(bed_data)
chrom chromStart chromEnd name strand
75652 ChrSy 785 1168 ChrSy.fgenesh.gene.1 -
329717 ChrSy 50779 51012 ChrSy.fgenesh.gene.10 -
337755 ChrSy 53593 53841 ChrSy.fgenesh.gene.11 -
325371 ChrSy 58993 59748 ChrSy.fgenesh.gene.12 +
93954 ChrSy 68366 68668 ChrSy.fgenesh.gene.13 -
152362 ChrSy 73936 74597 ChrSy.fgenesh.gene.14 +
# 保存为 BED 文件
write.table(bed_data, file = "output_with_gene_id_and_strand.bed", quote = FALSE, sep = "\t", row.names = FALSE, col.names = FALSE)
print("The BED file has been saved as 'output_with_gene_id_and_strand.bed'.")