僅作個人筆記 使用4DNvestigator計算VNE

% ==== 固定參數(shù)(按需改動路徑) ====
repo      = 'F:\Matlab.workspace\4DNvestigator';
juicerJar = fullfile(repo, 'juicer_tools.jar');        % 建議 Juicer Tools 2.20.00
hicFile   = 'E:\workspace\FenshuChrVar\48.heart.HiC\Erothschildi.heart.hic';
outDir    = 'E:\workspace\FenshuChrVar\48.heart.HiC\VNE_allchr_fixed';
bpFrag    = 'BP';
normName  = 'KR';
binSize   = 1e5;                                       % 固定分辨率:100 kb

% ==== 環(huán)境 ====
cd(repo); addpath(genpath(repo));
if ~exist(outDir,'dir'), mkdir(outDir); end

% ==== 主流程:Chr1..Chr31,整條染色體一次性計算 ====
chroms = 1:29;
VNE    = nan(numel(chroms),1);

for idx = 1:numel(chroms)
    c = chroms(idx);
    chrArg = sprintf('Chr%d', c);                      % 你的 .hic 命名為 ChrN

    dumpTxt = fullfile(outDir, sprintf('dump_%s_%dkb.txt', chrArg, binSize/1000));
    cmd = sprintf('java -jar "%s" dump oe %s "%s" %s %s %s %d "%s"', ...
        juicerJar, upper(normName), hicFile, chrArg, chrArg, upper(bpFrag), binSize, dumpTxt);
    st = system(cmd);
    if st~=0 || ~exist(dumpTxt,'file') || dir(dumpTxt).bytes==0
        % 若極少數(shù)樣本并非 ChrN 命名,可試備用命名(chrN)
        chrArg2 = sprintf('chr%d', c);
        dumpTxt = fullfile(outDir, sprintf('dump_%s_%dkb.txt', chrArg2, binSize/1000));
        cmd = sprintf('java -jar "%s" dump oe %s "%s" %s %s %s %d "%s"', ...
            juicerJar, upper(normName), hicFile, chrArg2, chrArg2, upper(bpFrag), binSize, dumpTxt);
        st = system(cmd);
        if st~=0 || ~exist(dumpTxt,'file') || dir(dumpTxt).bytes==0
            warning('Chr%d 無法導(dǎo)出(命名或分辨率不存在),VNE=NaN', c);
            VNE(idx) = NaN; continue
        end
    end

    M = readmatrix(dumpTxt);
    if isempty(M) || size(M,2)<3
        warning('Chr%d dump 文件異常,VNE=NaN', c);
        VNE(idx) = NaN; continue
    end

    i0 = double(M(:,1)); j0 = double(M(:,2)); v = double(M(:,3));
    if max([i0; j0]) > 1e7
        % dump 輸出為坐標(biāo),轉(zhuǎn)為 bin 索引
        i = floor(i0./binSize) + 1;
        j = floor(j0./binSize) + 1;
    else
        % dump 輸出為 0-based bin 索引,轉(zhuǎn) 1-based
        i = i0 + 1;
        j = j0 + 1;
    end

    nBins = max([i; j]);
    if nBins < 2
        warning('Chr%d nBins<2,VNE=NaN', c);
        VNE(idx) = NaN; continue
    end

    S = sparse(i, j, v, nBins, nBins);
    S = S + S.' - spdiags(diag(S), 0, nBins, nBins);   % 對稱化

    % 4DNvestigator 默認(rèn):先做相關(guān)矩陣,再算 VNE
    H = full(S);                                       % 注意:這里會占用 O(nBins^2) 內(nèi)存
    VNE(idx) = hicEntropy(H, [], [], 'corr');

    fprintf('Chr%d 完成,%dkb,nBins=%d,VNE=%.4f\n', c, binSize/1000, nBins, VNE(idx));
end

T = table(chroms(:), VNE, 'VariableNames', {'chrom','VNE'});
outTsv = fullfile(outDir, sprintf('VNE_allchr_%dkb.tsv', binSize/1000));
writetable(T, outTsv, 'FileType','text','Delimiter','\t');

disp('完成,結(jié)果表:'); disp(outTsv);

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容