Ejemplo n.º 1
0
def catch_all(path):

    usage = {}
    with open('report.txt', 'r') as f:
        text = f.read()

        specialKeyFound = False
        tempSpecialKey = ''
        for i in range(0, len(text)):

            if text[i] == '[':
                specialKeyFound = True
                tempSpecialKey = text[i]
            elif specialKeyFound:
                if text[i] == ']':
                    tempSpecialKey = tempSpecialKey + ']'
                    count(tempSpecialKey, usage)
                    specialKeyFound = False
                    tempSpecialKey = ''
                else:
                    tempSpecialKey = tempSpecialKey + text[i]
            else:
                count(text[i], usage)

    # Generando el reporte en JSON para visualizarlo en la página.
    with open('app/db.js', 'w') as f:

        cadena = json.dumps(usage)
        f.write("var db = " + cadena)

    return app.send_static_file(path)
Ejemplo n.º 2
0
def distribute_shape_data():
    # data_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/data700_3/ele_type_data/"
    # files_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/data700_3/bpmn/"
    # imgs_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/data700_3/imgs/"

    data_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/ele_type_data/"
    files_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/files/"
    imgs_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/images/"

    # data_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/admission/ele_type_data/"
    # files_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/admission/bpmn/"
    # imgs_dir = "E:/diagrams/bpmn-io/bpmn2image/data0423/admission/images/"

    # if not os.path.exists(data_dir):
    #     os.mkdir(data_dir)

    print("Start Counting ...")
    count.count(files_dir)
    print("Counting finished!")
    ele_type_list = count.statistic()
    make_type_dirs(ele_type_list, data_dir)

    all_shapes_label = count.all_shapes_label

    imgs = os.listdir(imgs_dir)
    # imgs.sort()

    i = 0
    file_id = get_file_id(imgs[i])
    # file_id = get_file_name(imgs[model_i])
    file_path = imgs_dir + imgs[i]
    cur_img = cv.imread(file_path, cv.COLOR_BGR2GRAY)
    for shape_id, shape_label in enumerate(all_shapes_label):
        while shape_label[0] != file_id:
            i += 1
            file_id = get_file_id(imgs[i])
            print(file_id)
            file_path = imgs_dir + imgs[i]
            cur_img = cv.imread(file_path)

        shape_rec = shape_label[2]
        if shape_rec[2] * shape_rec[3] == 0:
            print(file_id)
            continue
        shape_rec = rh.dilate(shape_rec, 5)
        # print("{}:{}".format(str(shape_id)+"_"+file_id, shape_rec))
        shape_img = rh.truncate(cur_img, shape_rec)
        shape_type = shape_label[1]
        shape_dir = ""
        for ele_type in ele_type_list:
            if ele_type.startswith(shape_type):
                shape_dir = ele_type
                break
        if len(shape_dir) > 0:
            shape_path = data_dir + shape_dir + "/" + str(
                shape_id) + "_" + file_id + ".png"
            cv.imwrite(shape_path, shape_img)
Ejemplo n.º 3
0
 def test_empty_9x9(self):
     chess_board = [
         [1,1,1],
         [1,0,1],
         [1,1,1]
     ]
     self.assertEqual(count(chess_board), {}, "Should be {}.")
Ejemplo n.º 4
0
    def test_big_list(self):
        test_list = list(range(5436891))
        result = count(test_list)
        expects = len(test_list)

        assert expects == result, 'Expected {} but got {}'.format(
            expects, result)
Ejemplo n.º 5
0
    def test_empty_list(self):
        test_list = []
        result = count(test_list)
        expects = len(test_list)

        assert expects == result, 'Expected {} but got {}'.format(
            expects, result)
Ejemplo n.º 6
0
 def test_stress_20x20(self):
     """This test is just designed to measure the efficiency of the algorithm."""
     chess_board = [
             [0 for i in range(20)] for j in range(20)
     ]
     for i in range(100):
         self.assertEqual(count(chess_board), {}, "Should be {}.")
Ejemplo n.º 7
0
 def test_count(self):
     lists = [[random.randint(1, 100) for _ in range(random.randint(1, 20))] for _ in range(random.randint(1, 20))]
     ans = _("The number of different elements of {} is {} and you returned {}.")
     for i in range(len(lists)):
         stu_ans = count.count(lists[i])
         corr_ans = corr.count(lists[i])
         self.assertEqual(corr_ans, stu_ans, ans.format(lists[i], corr_ans, stu_ans))
Ejemplo n.º 8
0
 def test_full_9x9(self):
     chess_board = [
         [1,1,1],
         [1,1,1],
         [1,1,1]
     ]
     self.assertEqual(count(chess_board), {2:4, 3:1}, "Should be {2:4, 3:1}.")
Ejemplo n.º 9
0
def test():
    filename = 'testfile1.c'
    correct_count = 8
    observed_count = count(filename)
    if correct_count == observed_count:
        print 'PASSED'
    else:
        print 'FAILED: Expected', correct_count, 'but got', observed_count
Ejemplo n.º 10
0
    def on_submit_button_clicked(self, widget):
        """
        draw result
        """
        ss = self.entry.get_text()
        if ss != '' and  ss in self.particle_lst and ss not in self.lst:
            self.lst.append(ss)

        n = len(self.lst)
        dic = frequency(self.lst)
        d = {'1':1, '2':2, '3':3.3}
        """ Here you shuld use dic After finished the func frequency"""
        picture(dic)

        if ss != '' and ss not in self.particle_lst:
            print(count.count(ss))
            picture({ss: count.count(ss)})
Ejemplo n.º 11
0
 def test(self):
     self.assertEqual(count(''), {},
                      'should give empty dictionary if string is empty')
     self.assertEqual(count('aa'), {'a': 2},
                      'should get as a result two A characters')
     self.assertEqual(
         count('aabb'), {
             'a': 2,
             'b': 2
         },
         'should get as a result of two a characters and two b characters')
     self.assertEqual(
         count('aabb'), {
             'b': 2,
             'a': 2
         },
         'should get as a result of two a characters and two b characters, showing that the result order does not matter'
     )
Ejemplo n.º 12
0
 def test_mixed_5x5(self):
     chess_board = [
         [0,1,1,1,1],
         [1,1,1,1,1],
         [1,1,1,1,1],
         [0,1,1,0,1],
         [1,1,1,1,1]
     ]
     self.assertEqual(count(chess_board), {3:2, 2:9}, "Should be {3:2, 2:9}.")
Ejemplo n.º 13
0
 def generate_hap_seq_sets(self, pheno_seq, hap_seq_sets):
   """ hap_list [[a1,a2,a3],[a1,a2,a3], ... last consistent haplotype]
       set      [h0 count,h1 count ... hn count]
       seq_set  [[a1,a2,a3],[a1,a2,a3] ... g_sizeth haplotype] """
       
   hap_list = self.generate_haps(pheno_seq)
   for set in count(len(hap_list), self.g_size + 1):
     if reduce(lambda c1, c2 : c1 + c2, set) == self.g_size:
       if phenotype.is_consistent(set, hap_list, pheno_seq):
         hap_seq_sets.append(phenotype.set_to_seq_set(set, hap_list))
Ejemplo n.º 14
0
    def seqpos(self, chip_regions, width=600, margin=50):
        """Score motif on how centrally located they are within each ChIP
        region.

        ChIP regions should be given as a ChipRegions object.
        The results of SeqPos will be stored as properties of
        self.seqpos_results.
        
        Adapted from Cliff Meyer's ChIP_region.CentralMotifScan() method."""
        ANTISENSE = 1
        MOTIFMIN = 1e-3

        if not chip_regions.preprocessed_regions:
            chip_regions.preprocess(width, margin)
            #process the chip-regions
            chip_regions.read_sequence(True)

        bgseqprob_mat = count.count(chip_regions.sequence)
        markov_order = 2
        prob_option = _seq.MAX_OPTION

        #GRR: THIS IS THE ONLY numpy dependency, and it is b/c seqscan
        #expects self.pssm to be a numpy array!
        pssm = numpy.array(self.pssm, float)
        s_idx, start, end, orient, score = \
               _seq.seqscan(chip_regions.sequence, pssm, bgseqprob_mat,
                            markov_order, prob_option)
        #adjust score
        adj_score = map(lambda s: math.log(s + MOTIFMIN), score)

        #calculate the seqpos_results (stats)
        self.seqpos_stat(start, end, adj_score, width + margin)

        #generating the observed pssm
        #fracpos is the fractional position of each site/hit
        fracpos = [
            abs(0.5 * (s + e) - (margin + width) / 2.0) / (width / 2.0)
            for (s, e) in zip(start, end)
        ]
        #retrieve sequences whose fracposition is in (0.0, 1.0]
        seq, dis = [], []
        for j, elem in enumerate(fracpos):
            if elem <= 1.0:
                t = list(chip_regions.sequence[int(s_idx[j])])
                dis.append(int(start[j]) - len(t) / 2)
                t = t[int(start[j]):int(end[j])]
                if orient[j] == ANTISENSE:
                    seq.append(revcomp(t))
                else:
                    seq.append(t)
        self.seqpos_results['pssm'] = calc_pssm(seq)
        self.seqpos_results['seq'] = ["".join(t) for t in seq]
        self.seqpos_results['dis'] = dis
Ejemplo n.º 15
0
 def testValidInput(self):
     self.assertEqual(count(0), 0)
     self.assertEqual(count(1), 1)
     self.assertEqual(count(10), 2)
     self.assertEqual(count(0x7FFFFFFF), 31)
     self.assertEqual(count(0xFFFFFFFF), 32)
     self.assertEqual(count(0x8000000), 1)
Ejemplo n.º 16
0
Archivo: motif.py Proyecto: cfce/chilin
    def seqpos(self, chip_regions, width=600, margin=50):
        """Score motif on how centrally located they are within each ChIP
        region.

        ChIP regions should be given as a ChipRegions object.
        The results of SeqPos will be stored as properties of
        self.seqpos_results.
        
        Adapted from Cliff Meyer's ChIP_region.CentralMotifScan() method."""
        ANTISENSE = 1
        MOTIFMIN = 1e-3
        
        if not chip_regions.preprocessed_regions:
            chip_regions.preprocess(width, margin)
            #process the chip-regions
            chip_regions.read_sequence(True)
            
        bgseqprob_mat = count.count(chip_regions.sequence)
        markov_order = 2
        prob_option = _seq.MAX_OPTION

        #GRR: THIS IS THE ONLY numpy dependency, and it is b/c seqscan
        #expects self.pssm to be a numpy array!
        pssm = numpy.array(self.pssm, float)
        s_idx, start, end, orient, score = \
               _seq.seqscan(chip_regions.sequence, pssm, bgseqprob_mat,
                            markov_order, prob_option)
        #adjust score
        adj_score = map(lambda s: math.log(s + MOTIFMIN), score)

        #calculate the seqpos_results (stats)
        self.seqpos_stat(start, end, adj_score, width + margin)

        #generating the observed pssm
        #fracpos is the fractional position of each site/hit
        fracpos = [abs(0.5*(s + e) - (margin + width)/2.0) / (width/2.0)
                   for (s,e) in zip(start, end)]
        #retrieve sequences whose fracposition is in (0.0, 1.0]
        seq,dis = [],[]
        for j,elem in enumerate(fracpos):
            if elem <= 1.0:
                t = list(chip_regions.sequence[int(s_idx[j])])
                dis.append(int(start[j])-len(t)/2)
                t = t[int(start[j]):int(end[j])]
                if orient[j] == ANTISENSE:
                    seq.append(revcomp(t))
                else:
                    seq.append(t)
        self.seqpos_results['pssm'] = calc_pssm(seq)
        self.seqpos_results['seq'] = ["".join(t) for t in seq]
        self.seqpos_results['dis'] = dis
Ejemplo n.º 17
0
def findmaxchar():
    f = open('w.log', 'r')
    s = f.read()
    str = s.replace("\t", "")
    str0 = str.replace("\n", "")
    str1 = unicode(str0.replace(" ", ""), 'UTF-8')
    print str1
    dict = {}
    str2 = substr.substr(str1)
    print str2
    str3 = list(str2)
    flag = count.count(str1, str3[0])
    for i in range(str3.__len__()):
        dict[str3[i]] = count.count(str1, str3[i])
    print json.dumps(dict, encoding="utf-8", ensure_ascii=False)
    for k, v in dict.items():
        if flag < v:
            flag = v
        else:
            pass
    for k, v in dict.items():
        if (v == flag):
            print k, v
Ejemplo n.º 18
0
def consensus(Motifs):

    k = len(Motifs[0])
    count_mot = count(Motifs)
    consensus_string = ""

    for j in range(k):
        m = 0
        frequentSymbol = ""
        for symbol in "ACGT":
            if count_mot[symbol][j] > m:
                m = count_mot[symbol][j]
                frequentSymbol = symbol
        consensus_string += frequentSymbol

    return consensus_string
def consensus(Motifs):

    k = len(Motifs[0])
    count_mot = count(Motifs)
    consensus_string = ""

    for j in range(k):
        m = 0
        frequentSymbol = ""
        for symbol in "ACGT":
            if count_mot[symbol][j] > m:
                m = count_mot[symbol][j]
                frequentSymbol = symbol
        consensus_string += frequentSymbol

    return consensus_string
Ejemplo n.º 20
0
def is_perfect(node):
    """Is this tree perfect?

    Math observation: a perfect tree always has a number of nodes
    that is equal to the 2 ** height - 1.

        >>> is_perfect(BNode(1))
        True

        >>> is_perfect(BNode(2, BNode(1), BNode(3)))
        True

        >>> is_perfect(bst)
        False
    """

    return count(node) == 2**height(node) - 1
Ejemplo n.º 21
0
    def motifscan(self, motif):
        """Scan sequences with a motif.

        Motif must be provided as a Motif object.
        Hits will be returned as a ChipRegions object.

        Directly calls [Somebody]'s _seq program.
        """
        SENSE = 0
        self.read_sequence(True)

        # LEN: BINOCH UPGRADE
        bgseqprob_mat = count.count(self.sequence)
        markov_order = 2
        prob_option = _seq.CUTOFF_OPTION

        #GRR: THIS IS THE ONLY numpy dependency, and it is b/c seqscan
        #expects self.pssm to be a numpy array!
        pssm = numpy.array(motif.pssm, float)
        s_idx, start, end, orient, score = \
               _seq.seqscan(self.sequence, pssm, bgseqprob_mat,
                            markov_order, prob_option)
        hits = ChipRegions(genome=self.genome,genome_dir=self.genome_dir)
        hits.genome = self.genome

        for i,idx in enumerate(s_idx):
            #sorry for the i vs idx confusion, but they're really different!
            hits.chrom.append(self.chrom[idx])
            hits.chromStart.append(int(self.chromStart[idx] + int(start[i])))
            hits.chromEnd.append(int(self.chromStart[idx] + int(end[i])))
            if int(orient[i]) == SENSE:
                hits.strand.append("+")
            else:
                hits.strand.append("-")
            #hits.hitscore.append(score[idx])--not sure if i should use i/idx
            hits.hitscore.append(score[i])

        # LEN: BINOCH UPGRADE END

        hits.read_sequence(True)

        return hits
Ejemplo n.º 22
0
    def motifscan(self, motif):
        """Scan sequences with a motif.
        
        Motif must be provided as a Motif object.
        Hits will be returned as a ChipRegions object.
        
        Directly calls [Somebody]'s _seq program.
        """
        SENSE = 0
        self.read_sequence(True)

        # LEN: BINOCH UPGRADE
        bgseqprob_mat = count.count(self.sequence)
        markov_order = 2
        prob_option = _seq.CUTOFF_OPTION

        #GRR: THIS IS THE ONLY numpy dependency, and it is b/c seqscan
        #expects self.pssm to be a numpy array!
        pssm = numpy.array(motif.pssm, float)
        s_idx, start, end, orient, score = \
               _seq.seqscan(self.sequence, pssm, bgseqprob_mat,
                            markov_order, prob_option)
        hits = ChipRegions()
        hits.genome = self.genome

        for i, idx in enumerate(s_idx):
            #sorry for the i vs idx confusion, but they're really different!
            hits.chrom.append(self.chrom[idx])
            hits.chromStart.append(int(self.chromStart[idx] + int(start[i])))
            hits.chromEnd.append(int(self.chromStart[idx] + int(end[i])))
            if int(orient[i]) == SENSE:
                hits.strand.append("+")
            else:
                hits.strand.append("-")
            #hits.hitscore.append(score[idx])--not sure if i should use i/idx
            hits.hitscore.append(score[i])

        # LEN: BINOCH UPGRADE END

        hits.read_sequence(True)

        return hits
Ejemplo n.º 23
0
def is_perfect_v2(node):
    """Is this tree perfect?

    Math observation: a perfect tree always has a number of nodes
    that is equal to the 2 ** height - 1. We don't need to get the
    height separately, though -- we can check if the # nodes is valid
    for any height:

        >>> is_perfect_v2(BNode(1))
        True

        >>> is_perfect_v2(BNode(2, BNode(1), BNode(3)))
        True

        >>> is_perfect_v2(bst)
        False
    """

    nnodes = count(node)

    return math.log(nnodes + 1, 2) == int(math.log(nnodes + 1, 2))
Ejemplo n.º 24
0
                with open('None_recommend_list', 'a') as f3:
                    f3.write(k + ':' + v + '\n')


if __name__ == '__main__':
    start_time = time.time()
    # 1. 获取推荐列表(人名)
    path1 = '/Users/zhangwei/Desktop/sina_job/recommend/oid_name_type/20180114.txt'  # 每次运行修改
    path2 = './res_container/res14'  # 每次运行修改
    # {starname:url}
    full = []
    full.append(star.get_mingxingurl_dict(path1))
    full.append(star.get_yinyueurl_dict(path1))
    # star_url = star.get_mingxingurl_dict(path)  # 明星
    # star_url = star.get_yinyueurl_dict(path)  # 音乐
    # star_url = star.getmingxingurl_test() # 测试用例
    for i in full:
        recomend(i, path2)

    # 2. 获取oid推荐列表

    path3 = mkdir.mkdir('./recommend_container/recommend8/')  # 每次运行修改
    print(type(path3))
    name_oid.name_oid(path1, path2, path3)
    # 3. 增加反向关系,得到最终的列表
    add.ad_re_relation(path3)
    # 4.统计结果
    count.count(path3)
    end_time = time.time()
    print('程序运行了:' + str((end_time - start_time) / 60) + '分钟')
Ejemplo n.º 25
0
def test_count_zeros():
    assert count.count([0, 0, 0], 0) == 3
def test_count_from_2_to_negative_5_should_give_2_1_0_1_2_3_4_5():

    assert_equal(count(start=2, stop=-5), "2,1,0,-1,-2,-3,-4,-5")
def test_count_from_3_to_5_should_give_3_4_5():

    assert_equal(count(start=3,stop=5), "3,4,5")
Ejemplo n.º 28
0
 def testCount3(self):
     self.assertEqual(hw.count("z", "zyzzyzus"), 4)
def test_count_from_1_to_1_should_give_1():

    assert_equal(count(start=1, stop=1), "1")
Ejemplo n.º 30
0
 def test_count_5(self):
     self.assertEqual(11, count.count(1000, 2000, 91))
Ejemplo n.º 31
0
 def testCount2(self):
     self.assertEqual(hw.count("z", "zyzzyva"), 3)
Ejemplo n.º 32
0
 def test_count_1(self):
     self.assertEqual(4, count.count(3, 20, 5))
Ejemplo n.º 33
0
 def test_count_3(self):
     self.assertEqual(25, count.count(1, 25, 1))
Ejemplo n.º 34
0
 def test_sub(self):
     j = count(2,3)
     self.assertEqual(j.sub(),-1)
Ejemplo n.º 35
0
 def test_sub2(self):
     j = count(71,46)
     self.assertEqual(j.sub(),25)
Ejemplo n.º 36
0
 def testCount1(self):
     self.assertEqual(hw.count("b", "biology terms with z"), 1)
Ejemplo n.º 37
0
def test_count_string():
    assert count.count(["a", "a", "a"], "a") == 3
Ejemplo n.º 38
0
 def test_add2(self):
     j = count(41,76)
     self.assertEqual(j.add(),117)
def test_count_takes_two_argument():
    count()
    count(start=3)
Ejemplo n.º 40
0
 def test_add(self):
     j = count(2,3)
     self.assertEqual(j.add(),7,msg='is wrong')
        a.align(pars)

        #        pars['alignerIndexDir'] = alignerIndexDir2
        #        pars['flavor'] = 'salmon'
        #        a.align(pars)

        # *** 05 quantify ***
        # cufflinks - generate quantifications from bams
        #        pars['flavor'] = 'cufflinks'
        pars['flavor'] = 'stringtie'
        q.quantify(pars)

        # *** count ***
        # featureCounts
        pars['flavor'] = 'featureCounts'
        co.count(pars)

        # *** 10 qc ***
        # qorts - generate in case qc problems later
        pars['flavor'] = 'qorts'
        qc.qc(pars)

        # *** 20 clean ***
        # get rid of fastq files
        pars['flavor'] = 'standard'
        cl.clean(pars)

        # *** check to make sure sample has not already been successfully run ***
#        pars['flavor'] = 'salmon-bias'
#        check.isCompleted(pars)
Ejemplo n.º 42
0
 def testCount5(self):
     self.assertEqual(
         hw.count(" ", "It has not escaped our notice that the specific pairing we have postulated"), 12
     )
Ejemplo n.º 43
0
 def test_count_2(self):
     self.assertEqual(111, count.count(1, 1000, 9))
Ejemplo n.º 44
0
def test_count_string():
    assert count.count(["a","a","a"], "a") == 3

#type 'pytest' in terminal to go through the tests (within the directory)
Ejemplo n.º 45
0
 def test_count_4(self):
     self.assertEqual(11, count.count(10, 90, 7))
Ejemplo n.º 46
0

EBOOKS_BASE_PATH = "/home/aleray/work/osp.work.annak/osp.work.annak.books/ebooks/txt/"


if __name__ == '__main__':
    graph = rdflib.Graph()

    ns_stats = rdflib.Namespace("http://kavan.land/vocab/stats#")
    graph.namespace_manager.bind('stats', ns_stats)

    for url, filename in BOOKS.items():
        subject = rdflib.URIRef(url)
        path = os.path.join(EBOOKS_BASE_PATH, filename)

        # generate bigrams
        bigrams = collocations(path)

        for bigram in bigrams:
            graph.add((subject, ns_stats.bigram, rdflib.Literal(" ".join(bigram))))

        # generate stats
        stats = count(path)

        graph.add((subject, ns_stats.hasCharacterCount, rdflib.Literal(stats['cc'])))
        graph.add((subject, ns_stats.hasWordCount, rdflib.Literal(stats['wc'])))
        graph.add((subject, ns_stats.hasUniqueWordCount, rdflib.Literal(stats['uwc'])))
        graph.add((subject, ns_stats.hasDiversityIndice, rdflib.Literal(stats['idx'])))

        print(graph.serialize(format="turtle"))
    path_res = mk.res_name_path('.\\res_container')
    path_recommend = mk.recommed_file_path('.\\recommend_container')
    # {starname:url}
    full = []
    full.append(star.get_mingxingurl_dict(path))
    full.append(star.get_yinyueurl_dict(path))

    for i in full:
        p.apply_async(recomend, args=(
            i,
            path1,
            path2,
            path3,
            path_res,
        ))
        # recomend(i, path1, path2, path3, path_res)
    p.close()
    p.join()
    name_topic.name_oid(path, path_res, path_recommend)

    ad_re_relation.add_re(path_recommend)

    count.count(path_recommend)

    end_time = time.time()
    time = (end_time - start_time) / 60
    print('0201号蜘蛛运行了:' + str(time) + '分钟')
    print('大概' + str(time / 60) + '小时')
    with open(path_recommend + 'recommend_count', 'a', encoding='utf-8') as f:
        f.write('0119号蜘蛛运行了:' + str(time) + '分钟')
Ejemplo n.º 48
0
'''
Created on Jun 30, 2015

@author: nathaniel
'''
import count

print count.count()
print count.count()