Ejemplo n.º 1
0
def write_align_makeflow(samples,genome_dir,makeflow,input_d,output_d):
    if not os.path.exists(genome_dir):
        print "%s dir not exists, please check!" %genome_dir
        sys.exit(0)
    gtf = glob.glob(os.path.join(genome_dir,"*.gtf"))[0]
    fa = glob.glob(os.path.join(genome_dir,"*.fa"))[0]
    if not fa or not gtf:
        print "please check the fa and gtf file in %s" %genome_dir
        sys.exists(0)
    genome_prefix = os.path.splitext(fa)[0]
    fo =open(makeflow,"a+")
    fo.write("CATEGORY=Bowtie2-build\n")
    fo.write("%s : %s\n"%(genome_dir+"/build-genome.log",fa))
    fo.write("\t/lustre/work/yongdeng/software/protokaryon/soft/Align/bowtie2-2.3.3.1/bowtie2-build --threads 8 %s %s &> %s\n\n" %(fa,genome_prefix,genome_dir+"/build-genome.log"))
    fo.write("CATEGORY=create_refFlat\n")
    fo.write(gtf + ".refFlat : " + gtf + "\n")
    fo.write("\tperl /lustre/work/yongdeng/software/protokaryon/soft/Align/create_refFlat.pl %s %s &> %s\n\n"%(gtf,gtf + ".refFlat",genome_dir+"/refflat.err"))
    for sn in samples:
        r1 = os.path.join(input_d,sn,"R1.clean.fq.gz")
        r2 = os.path.join(input_d,sn,"R2.clean.fq.gz")
        od = os.path.join(output_d,sn)
        fo.write("CATEGORY=Bowtie2-align_%s\n"%sn)
        fo.write(os.path.join(od,"bowtie.err ") + os.path.join(od,"accepted_hits.sam : ") + r1 + " " + r2 + " " + genome_dir + "/build-genome.log\n")
        fo.write("@BATCH_OPTIONS = -l h_vmem=50G\n")
        fo.write("\t/lustre/work/yongdeng/software/protokaryon/soft/Align/bowtie2-2.3.3.1/bowtie2 -p 8 -x %s -1 %s -2 %s -S %s "%(genome_prefix,r1,r2,os.path.join(od,"accepted_hits.sam")))
        fo.write("> %s 2> %s\n\n" %(os.path.join(od,"bowtie.out"),os.path.join(od,"bowtie.err")))
    fo.close()
Ejemplo n.º 2
0
def main():
    if len(sys.argv) != 2:
        print "We need ONE keyword to search!"
        sys.exists(1)

    #create a new folder and cd to it
    path = r'/Users/yzhang250/Desktop/计算机学习/Staff/' + sys.argv[1]
    if not os.path.exists(path):
        os.makedirs(path)
    os.chdir(path)
    #scrolling the pages in search results
    for page in range(1, 200):
        #start to parse the search result of the key word----sys.argv[1]
        url_kw = 'http://www.everyonepiano.cn/Music-search/?word=' + sys.argv[
            1] + '&come=web&p=' + str(page)
        r_kw = requests.get(url_kw)
        soup_kw = BeautifulSoup(r_kw.content, 'lxml')

        if soup_kw.find('span', {"class": "current"}).text != str(page):
            break
        else:

            #list out all the musics from the key word and put into a list of links
            tags = soup_kw.find_all("a",
                                    {"class": "Title"})  # this find all the
            links = []
            for i in range(0, len(tags)):
                links.append(tags[i].get('href'))

            #get and print out the stave from EACH link in links list
            for i in range(0, len(links)):
                #get the soup_music, which is the page for each music
                url_music = url_basic + links[i]
                r_music = requests.get(url_music)
                soup_music = BeautifulSoup(r_music.content, 'lxml')
                num_match = re.search(
                    "\d+", str(soup_music.find("div",
                                               {"class": "EOPRTRight"})))
                if num_match != None:
                    music_num = num_match.group()
                    url_img = "http://www.everyonepiano.cn/Stave-" + music_num + ".html"
                    r_img = requests.get(url_img)
                    soup_img = BeautifulSoup(r_img.content, 'lxml')
                    # this is to determine the name of the music
                    name = soup_music.h1.text
                    if not os.path.exists(path + '/' + name.encode("utf8")):
                        os.makedirs(path + "/" + name.encode("utf8"))
                        os.chdir(path + "/" + name.encode("utf8"))
                        print_staff_from_soup_img(soup_img, name)
                    os.chdir(path)
                else:
                    continue
Ejemplo n.º 3
0
def judgeImageExists(image):
    i = 0
    ok = "再找一次"
    cancel = "中断程序"
    while ai.locateOnScreen(image) == None:
        i += 1
        if i >= 10:
            res = ai.confirm(text="找了%s次找到%s" % (i, image),
                             buttons=("%s" % ok, "%s" % cancel))
            if res == ok:
                continue
            else:
                sys.exists()
Ejemplo n.º 4
0
def run_remote_backup(config, connection):
    day_cron = date.today().isoweekday()
    for command in config['backup_command']:
        cron = command[0].split(',')
        if command:
            logging.info('***Run remote commands')
            try:
                if str(day_cron) in cron:
                    logging.info('***Run cron %s command: %s' % (day_cron, command[1]))
                    stdin, stdout, stderr = connection.exec_command(command[1], bufsize=1024)
                    if stderr.read():
                        logging.error('***Error to run remote command: %s' % stderr.read())
                    if stdout.read():
                        logging.info("***Stdout: %s" % stdout.read())
            except IOError:
                logging.error('***Error to run remote command, system exist.')
                try:
                    connection.close()
                    logging.info('***Disconnected.')
                except:
                    pass
                sys.exists()
Ejemplo n.º 5
0
def write_align_makeflow(samples, genome_dir, makeflow, input_d, output_d,
                         thread, strand):
    gff2gtf = RNA.get_bin_abspath("gff2gtf.for.NCBIgff.pl")
    build_index = RNA.get_soft_abspath("bowtie2-build")
    bowtie = RNA.get_soft_abspath("bowtie2")
    reflat = RNA.get_bin_abspath("create_refFlat.pl")
    if not os.path.exists(genome_dir):
        print "%s dir not exists, please check!" % genome_dir
        sys.exit(0)
    gtf = glob.glob(os.path.join(genome_dir, "*.gtf"))
    gff = glob.glob(os.path.join(genome_dir, "*.gff"))
    fa = glob.glob(os.path.join(genome_dir, "*.fa"))
    if gtf and fa:
        fa = fa[0]
        gtf = gtf[0]
    elif not gtf and gff and fa:
        fa = fa[0]
        gff = gff[0]
        gtf = os.path.splitext(gff) + ".gtf"
        fo.write('CATEGORY=gff2gtf\n')
        fo.write(os.path.splitext(gff) + ".gtf : " + gff + "\n")
        fo.write("\tperl %s %s %s &> %s\n\n" %
                 (gff2gtf, gff, gtf,
                  os.path.join(os.path.dirname(gff) + "gff2gtf.log")))
    else:
        print "Error: No gtf or gff file in %s dir" % genome_dir
        sys.exit(1)

    if not fa:
        print "please check the fa and gtf file in %s" % genome_dir
        sys.exists(1)

    genome_prefix = os.path.splitext(fa)[0] + '.bowtie'
    fo = open(makeflow, "a+")
    if not os.path.exists(genome_dir + "/bowtie_build-genome.log"):
        fo.write("CATEGORY=Bowtie2-build\n")
        fo.write("%s : %s\n" % (genome_dir + "/bowtie_build-genome.log", fa))
        fo.write("\t%s --threads %d %s %s &> %s\n\n" %
                 (build_index, thread, fa, genome_prefix,
                  genome_dir + "/bowtie_build-genome.log"))
    if not os.path.exists(gtf + ".refFlat"):
        fo.write("CATEGORY=create_refFlat\n")
        fo.write(gtf + ".refFlat : " + gtf + "\n")
        fo.write("\tperl %s %s %s &> %s\n\n" %
                 (reflat, gtf, gtf + ".refFlat", genome_dir + "/refflat.err"))
    for sn in samples:
        r1 = os.path.join(input_d, sn, "R1.clean.fq.gz")
        r2 = os.path.join(input_d, sn, "R2.clean.fq.gz")
        od = os.path.join(output_d, sn)
        fo.write("CATEGORY=Bowtie2-align_%s\n" % sn)
        fo.write(
            os.path.join(od, "bowtie.err ") +
            os.path.join(od, "accepted_hits.sam : ") + r1 + " " + r2 + " " +
            genome_dir + "/bowtie_build-genome.log\n")
        fo.write("@BATCH_OPTIONS = -l h_vmem=50G\n")
        if strand:
            fo.write("\t%s --ff -p %d -x %s -1 %s -2 %s -S %s " %
                     (bowtie, thread, genome_prefix, r1, r2,
                      os.path.join(od, "accepted_hits.sam")))
        else:
            fo.write("\t%s --fr -p %d -x %s -1 %s -2 %s -S %s " %
                     (bowtie, thread, genome_prefix, r1, r2,
                      os.path.join(od, "accepted_hits.sam")))
        fo.write(
            "> %s 2> %s\n\n" %
            (os.path.join(od, "bowtie.out"), os.path.join(od, "bowtie.err")))
    fo.close()
Ejemplo n.º 6
0
        # write .ra2, .uv and .n file for each material
        for m in mats:

            if m.users == 0: continue

            mfilename = m.name.replace("/", "_")

            curr_mat = 0
            for i in range(0, len(materials)):
                if m.name == materials[i]:
                    curr_mat = mat_num[i]

            # basefilename = filename[:-5] + "/" + sys.basename(filename)[:-5] + mfilename
            basefilename = sys.dirname(filename) + "/" + mfilename
            if not sys.exists(basefilename + ".ra2"):
                # matfile.write(str(curr_mat) + ' ' + filename[:-5] + mfilename + '.ra2\n')
                file_str.write(str(curr_mat) + ' ' + mfilename + '.ra2\n')
                numObjects = numObjects + 1

            # append the data to files
            meshfile = open(basefilename + ".ra2", "ab")
            normfile = open(basefilename + ".n", "ab")
            uvfile = open(basefilename + ".uv", "ab")

            for face in tmpMesh.faces:

                if mats[face.mat] != m: continue
                for lfn in range(2, len(face.v)):
                    for i in [0, lfn - 1, lfn]:
                        meshfile.write(
Ejemplo n.º 7
0
    blank_rect = plt.bar(index + bar_width, blank_line, bar_width,
                         alpha=opacity,
                         color='r',

                         error_kw=error_config,
                         label='Blanklines')

    plt.xlabel('Language')
    plt.ylabel('Line')
    plt.title('COUNTING_CODE')
    plt.xticks(
        index + bar_width, tuple(map(lambda s: s[1:], CODE_FILE_SUFFIXES)))
    plt.legend()

    plt.tight_layout()
    plt.show()


os.chdir(args.directory)
counting_code()
if args.graphic:
    try:
        import numpy as np
        import matplotlib.pyplot as plt
    except ImportError:
        print "numpy or matplotlib may not be installed! cannot use -g argument"
        sys.exists()
    paint_chart()
else:
    print detail