Skip to content

Commit

Permalink
Merge pull request #46 from 4dn-dcic/0.2.9
Browse files Browse the repository at this point in the history
0.2.9
  • Loading branch information
SooLee authored Oct 2, 2017
2 parents a0c6823 + 728cef7 commit 8d535ec
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.8
0.2.9
Binary file modified samples/merged_nodup.tab.chrblock_sorted.txt.gz.px2
Binary file not shown.
Binary file modified samples/merged_nodups.space.chrblock_sorted.subsample1.txt.gz.px2
Binary file not shown.
4 changes: 2 additions & 2 deletions src/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,10 @@ int ti_parse_region2d(const ti_index_t *idx, const char *str, int *tid, int *beg
free(s); return (res);
}
if(i == k && dim == 2) { //1d query on 2d data : interprete query 'x' as 'x|x'
s = (char*)realloc(s, l*2+2);
s = (char*)realloc(s, k*2+2);
strcpy(s+i+1, s);
s[i] = region_split_character;
l = l*2+1;
k = k*2+1;
}

//2d query on 2d data
Expand Down
2 changes: 1 addition & 1 deletion src/pairix.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef __TABIDX_H
#define __TABIDX_H

#define PACKAGE_VERSION "0.2.8"
#define PACKAGE_VERSION "0.2.9"

#include <stdint.h>
#include "kstring.h"
Expand Down
32 changes: 31 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def find_pairs_type(filename, delimiter='\t'):
except AttributeError:
pass
fields = line.rstrip().split(delimiter)
if is_str(fields[2]) and is_str(fields[6]):
if len(fields)>=6 and is_str(fields[2]) and is_str(fields[6]):
is_juicer = True
if is_str(fields[2]) and is_str(fields[4]):
is_4DN = True
Expand Down Expand Up @@ -119,6 +119,8 @@ def read_pairs(filename, file_type='undetermined', delimiter='\t'):
line = line.decode('utf-8')
except AttributeError:
pass
if line.startswith('#'):
continue
fields = line.rstrip().split(delimiter)
if file_type == 'juicer':
chrom1 = fields[1]
Expand Down Expand Up @@ -154,6 +156,14 @@ def get_result_2D(regions, chrom, start, end, chrom2, start2, end2):
return retval


def get_result_2D_4DN(regions, chrom, start, end, chrom2, start2, end2):
retval = []
for r in regions:
if r[1] == chrom and overlap1(r[2], r[2], start, end) and r[3] == chrom2 and overlap1(r[4], r[4], start2, end2):
retval.append(r)
return retval


def build_it_result(it, f_type):
"""Build results using the pairix iterator based on the filetype"""
if f_type == 'juicer':
Expand Down Expand Up @@ -389,6 +399,26 @@ def test_build_index_with_force_merged_nodups_with_no_preset(self): ## recogniz
self.assertEqual(self.result, pr2_result)


## 1D query on 2D indexed file
class PairixTest_1_on_2(unittest.TestCase):
f_type='4DN'
regions = read_pairs(TEST_FILE_2D_4DN_2, f_type)
chrom = 'chrY'
start = 1
end = 2000000
chrom2 = chrom
start2 = start
end2 = end
result = get_result_2D_4DN(regions, chrom, start, end, chrom2, 0, sys.maxsize)
pr = pypairix.open(TEST_FILE_2D_4DN_2)

def test_querys(self):
query = '{}:{}-{}'.format(self.chrom, self.start, self.end)
it = self.pr.querys2D(query)
pr_result = build_it_result(it, self.f_type)
self.assertEqual(self.result, pr_result)


class PairixTestBlocknames(unittest.TestCase):

def test_blocknames(self):
Expand Down
6 changes: 6 additions & 0 deletions test/test_c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ if [ ! -z "$(diff log1 log2)" ]; then
return 1;
fi

pairix samples/test_4dn.pairs.gz 'chrY:1-2000000' > log1
pairix samples/test_4dn.pairs.gz 'chrY:1-2000000|chrY:1-2000000' > log2
if [ ! -z "$(diff log1 log2)" ]; then
echo "test 1e failed"
return 1;
fi

pairix samples/merged_nodup.tab.chrblock_sorted.txt.gz '10:1-1000000|20:50000000-60000000' > log1
gunzip -c samples/merged_nodup.tab.chrblock_sorted.txt.gz | awk '$2=="10" && $3>=1 && $3<=1000000 && $6=="20" && $7>=50000000 && $7<=60000000' > log2
Expand Down

0 comments on commit 8d535ec

Please sign in to comment.