using CSV using DataFrames using Tables using GenomicFeatures
function fs2NameTuple(fs::String) query = DataFrame(CSV.File(fs, delim="\t", header=0)) if size(query)[2] == 5 query = rename!(query, :Column1 => :Chromosome, :Column2 => :Start, :Column3 => :End, :Column4 => :Name, :Column5 => :Score) query = Tables.rowtable(query) result = IntervalCollection([Interval(qy.Chromosome, qy.Start, qy.End, '?', qy.Name) for qy in query], true) result elseif size(query)[2] == 4 query = rename!(query, :Column1 => :Chromosome, :Column2 => :Start, :Column3 => :End, :Column4 => :Name) query = Tables.rowtable(query) result = IntervalCollection([Interval(qy.Chromosome, qy.Start, qy.End, '?', qy.Name) for qy in query], true) result else println("please confirm your bed files") end end
function getInterval(A::IntervalCollection, B::IntervalCollection) for i in eachoverlap(A, B) println(i[1].seqname, "\t", i[1].first, "\t", i[1].last, "\t", i[1].metadata, "\t", i[2].seqname, "\t", i[2].first, "\t", i[2].last, "\t", i[2].metadata) end end getInterval(fs2NameTuple("test1.bed"),fs2NameTuple("test2.bed"))
|