R在希尔伯特曲线中的线段点和正方形点之间切换

问题描述

新年快乐! 下面我在 R 中有我的代码,它从 Bam 文件中创建了第一条染色体的 Hilber 曲线。

library(chromstaR)
library(genomicranges)
library(HilbertCurve)
library(circlize)
bampath <-"C:/Users/User/Documents/R/win-library/4.0/genomicranges/extdata/wgEncodeUwRepliSeqBg02esG1bAlnRep1.bam"
bam <- bampath

reads <- readBamFileAsGRanges(bam,chromosomes='chr1',pairedEndReads=FALSE,min.mapq=10,remove.duplicate.reads=TRUE)

hc = GenomicHilbertCurve(chr = "chr1",level = 5)
hc_points(hc,reads,gp = gpar(col = "blue")) 

现在我要创建的是以下内容。我想从线段的一点找到希尔伯特曲线中的坐标,相反,即从希尔伯特曲线的坐标中找到线段中的点。

我从网上找到了以下解决方案,但在 js 中。

function hilbertMap(quadits) {
        if ( quadits.length === 0 ) {
            return new Point(0,0);
        } else {
            return (function() {
                var pt,t,x,y;
                t = quadits.shift();
                pt = hilbertMap(quadits);
                x = pt.x;
                y = pt.y;
                switch(t) {
                    case 0: 
                        return new Point(y * 0.5 + 0,x * 0.5 + 0);
                    case 1:
                        return new Point(x * 0.5 + 0,y * 0.5 + 0.5);
                    case 2:
                        return new Point(x * 0.5 + 0.5,y * 0.5 + 0.5);
                    case 3:
                        return new Point(y * -0.5 + 1.0,x * -0.5 + 0.5);
                }
            })();
        }   
    }
    
    
    function hilbertMapInverse(x,y,depth) {
        var t;
        if ( depth > 1 ) {
            return 0;
        }
        else {
            if ( x < 0.5 ) {
                if ( y < 0.5 ) {
                    return (hilbertMapInverse(y * 2,x * 2,depth * 4) + 0) / 4;
                }
                else {
                    return (hilbertMapInverse(x * 2,y * 2 - 1,depth * 4) + 1) / 4;
                }
            }
            else {
                if ( y >= 0.5 ) {
                    return (hilbertMapInverse(x * 2 - 1,depth * 4) + 2) / 4;
                }
                else {
                    return (hilbertMapInverse(1 - y * 2,2 - x * 2,depth * 4) + 3) / 4;
                }
            }
        }
    }



})();

请在需要帮助时在 R 中转换 js 中的代码并附加到我的希尔伯特曲线上。 谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)