|
| 1 | +import pytest |
| 2 | +from deeptools.computeMatrix2 import r_computematrix # Adjust the import to your actual module |
| 3 | +import os.path |
| 4 | +import gzip |
| 5 | +import hashlib |
| 6 | + |
| 7 | +root = os.path.dirname(os.path.abspath(__file__)) + "/test_data/" |
| 8 | +matrix = root + "computeMatrixOperations.mat.gz" |
| 9 | +bed = root + "computeMatrixOperations.bed" |
| 10 | +rbindMatrix1 = root + "somegenes.txt.gz" |
| 11 | +rbindMatrix2 = root + "othergenes.txt.gz" |
| 12 | +bigwig = root + "testA.bw" |
| 13 | +outnpz = root + "output.mat.npz.gz" |
| 14 | + |
| 15 | +def test_r_computematrix_referencePoint(): |
| 16 | + mode = "reference-point" |
| 17 | + regionlis = [bed] |
| 18 | + bwlis = [bigwig] |
| 19 | + sampleslabel = ["sample1"] |
| 20 | + upstream = 1000 |
| 21 | + downstream = 1000 |
| 22 | + unscaled5prime = 0 |
| 23 | + unscaled3prime = 0 |
| 24 | + regionbodylength = 0 |
| 25 | + binsize = 50 |
| 26 | + missingdatazero = False |
| 27 | + metagene = False |
| 28 | + txnid = "" |
| 29 | + exonid = "" |
| 30 | + txniddesignator = "" |
| 31 | + scale = 1.0 |
| 32 | + nanafterend = False |
| 33 | + skipzeros = False |
| 34 | + minthresh = 0.0 |
| 35 | + maxthresh = 0.0 |
| 36 | + averagetypebins = "mean" |
| 37 | + sortregions = "keep" |
| 38 | + sortusing = "mean" |
| 39 | + ortusingsamples = [] |
| 40 | + referencepoint = "TSS" |
| 41 | + nproc = 1 |
| 42 | + verbose = False |
| 43 | + ofile = outnpz |
| 44 | + |
| 45 | + result = r_computematrix( |
| 46 | + mode, regionlis, bwlis, sampleslabel, upstream, downstream, unscaled5prime, unscaled3prime, |
| 47 | + regionbodylength, binsize, missingdatazero, metagene, txnid, exonid, txniddesignator, scale, |
| 48 | + nanafterend, skipzeros, minthresh, maxthresh, averagetypebins, sortregions, sortusing, |
| 49 | + ortusingsamples, referencepoint, nproc, verbose, ofile |
| 50 | + ) |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + with gzip.open(ofile, 'rb') as f: |
| 55 | + file_content = f.read() |
| 56 | + h = hashlib.md5(file_content).hexdigest() |
| 57 | + |
| 58 | + expectedh = '4f1a2ce422d5b74fb6b75a81916929db' |
| 59 | + assert h == expectedh |
| 60 | + |
| 61 | + os.remove(ofile) |
| 62 | + |
| 63 | +def test_r_computematrix_scale(): |
| 64 | + mode = "scale-regions" |
| 65 | + regionlis = [bed] |
| 66 | + bwlis = [bigwig] |
| 67 | + sampleslabel = ["sample1"] |
| 68 | + upstream = 1000 |
| 69 | + downstream = 1000 |
| 70 | + unscaled5prime = 0 |
| 71 | + unscaled3prime = 0 |
| 72 | + regionbodylength = 0 |
| 73 | + binsize = 50 |
| 74 | + missingdatazero = False |
| 75 | + metagene = False |
| 76 | + txnid = "" |
| 77 | + exonid = "" |
| 78 | + txniddesignator = "" |
| 79 | + scale = 1.0 |
| 80 | + nanafterend = False |
| 81 | + skipzeros = False |
| 82 | + minthresh = 0.0 |
| 83 | + maxthresh = 0.0 |
| 84 | + averagetypebins = "mean" |
| 85 | + sortregions = "keep" |
| 86 | + sortusing = "mean" |
| 87 | + ortusingsamples = [] |
| 88 | + referencepoint = "TSS" |
| 89 | + nproc = 1 |
| 90 | + verbose = False |
| 91 | + ofile = outnpz |
| 92 | + |
| 93 | + result = r_computematrix( |
| 94 | + mode, regionlis, bwlis, sampleslabel, upstream, downstream, unscaled5prime, unscaled3prime, |
| 95 | + regionbodylength, binsize, missingdatazero, metagene, txnid, exonid, txniddesignator, scale, |
| 96 | + nanafterend, skipzeros, minthresh, maxthresh, averagetypebins, sortregions, sortusing, |
| 97 | + ortusingsamples, referencepoint, nproc, verbose, ofile |
| 98 | + ) |
| 99 | + |
| 100 | + with gzip.open(ofile, 'rb') as f: |
| 101 | + file_content = f.read() |
| 102 | + h = hashlib.md5(file_content).hexdigest() |
| 103 | + |
| 104 | + |
| 105 | + expectedh = '4f1a2ce422d5b74fb6b75a81916929db' |
| 106 | + assert h == expectedh |
| 107 | + |
| 108 | + os.remove(ofile) |
| 109 | + |
0 commit comments