Beispiel #1
0
def check(*args,**kw):
    if len(args) < 1: raise Usage("No input file provided")
    if kw['output'] is None: output = sys.stdout
    else: output = open(kw['output'],'w')
    chrmeta = _get_chrmeta(**kw)
    if kw['no_overlaps'] and not kw['sorted']:
        output.write("--disjoint option was ignored: --sorted is required.\n")
    for infile in args:
        intrack = track.track(infile, format=kw['format'], chrmeta=chrmeta)
        cf = track.check(intrack, output,
                         check_sorted=kw['sorted'],
                         check_noduplicates=kw['no_duplicates'],
                         check_positive=kw['positive'],
                         check_nooverlaps=kw['no_overlaps'])
        if cf: output.write("File %s: file is correctly formatted.\n" % (infile,))
        intrack.close()
    return 0
Beispiel #2
0
def check(*args, **kw):
    if len(args) < 1: raise Usage("No input file provided")
    if kw['output'] is None: output = sys.stdout
    else: output = open(kw['output'], 'w')
    chrmeta = _get_chrmeta(**kw)
    if kw['no_overlaps'] and not kw['sorted']:
        output.write("--disjoint option was ignored: --sorted is required.\n")
    for infile in args:
        intrack = track.track(infile, format=kw['format'], chrmeta=chrmeta)
        cf = track.check(intrack,
                         output,
                         check_sorted=kw['sorted'],
                         check_noduplicates=kw['no_duplicates'],
                         check_positive=kw['positive'],
                         check_nooverlaps=kw['no_overlaps'])
        if cf:
            output.write("File %s: file is correctly formatted.\n" %
                         (infile, ))
        intrack.close()
    return 0
Beispiel #3
0
    def test_check(self):
        self.assertTrue(check(self.bed))

        # All sorted
        tempfile = os.path.join(path, 'temp2.txt')
        with open(tempfile, 'wb') as g:
            g.writelines(["chrX\t1\t2\n", "chrX\t3\t4\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_sorted=True), True)

        # Chromosomes unsorted
        tempfile = os.path.join(path, 'temp3.txt')
        with open(tempfile, 'wb') as g:
            g.writelines(["chrX\t1\t2\n", "chrV\t1\t2\n", "chrX\t3\t4\n"])
        self.assertEqual(check(tempfile, check_sorted=True), False)

        # Starts unsorted
        tempfile = os.path.join(path, 'temp4.txt')
        with open(tempfile, 'wb') as g:
            g.writelines(["chrX\t3\t4\n", "chrX\t1\t2\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_sorted=True), False)

        # Ends unsorted
        tempfile = os.path.join(path, 'temp5.txt')
        with open(tempfile, 'wb') as g:
            g.writelines(["chrX\t1\t4\n", "chrX\t1\t3\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_sorted=True), False)

        # Duplicates
        tempfile = os.path.join(path, 'temp5.txt')
        with open(tempfile, 'wb') as g:
            g.writelines(["chrX\t1\t4\n", "chrX\t1\t4\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_duplicates=True), False)

        # Empty regions
        tempfile = os.path.join(path, 'temp5.txt')
        with open(tempfile, 'wb') as g:
            g.writelines(["chrX\t1\t4\n", "chrX\t3\t3\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_zerosize=True), False)
Beispiel #4
0
    def test_check(self):
        self.assertTrue(check(self.bed))

        # All sorted
        tempfile = os.path.join(path,'temp2.txt')
        with open(tempfile,'wb') as g:
            g.writelines(["chrX\t1\t2\n", "chrX\t3\t4\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_sorted=True),True)

        # Chromosomes unsorted
        tempfile = os.path.join(path,'temp3.txt')
        with open(tempfile,'wb') as g:
            g.writelines(["chrX\t1\t2\n", "chrV\t1\t2\n", "chrX\t3\t4\n"])
        self.assertEqual(check(tempfile, check_sorted=True),False)

        # Starts unsorted
        tempfile = os.path.join(path,'temp4.txt')
        with open(tempfile,'wb') as g:
            g.writelines(["chrX\t3\t4\n", "chrX\t1\t2\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_sorted=True),False)

        # Ends unsorted
        tempfile = os.path.join(path,'temp5.txt')
        with open(tempfile,'wb') as g:
            g.writelines(["chrX\t1\t4\n", "chrX\t1\t3\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_sorted=True),False)

        # Duplicates
        tempfile = os.path.join(path,'temp5.txt')
        with open(tempfile,'wb') as g:
            g.writelines(["chrX\t1\t4\n", "chrX\t1\t4\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_duplicates=True),False)

        # Empty regions
        tempfile = os.path.join(path,'temp5.txt')
        with open(tempfile,'wb') as g:
            g.writelines(["chrX\t1\t4\n", "chrX\t3\t3\n", "chrV\t1\t2\n"])
        self.assertEqual(check(tempfile, check_zerosize=True),False)