def main(chrs, scale, step, meth_dir, cpg_dir, out_dir, sname):
    LOGFH = open('create_microarray_tracks.LOG', 'w')
    LOGFH.write('Start the program ...  %s\n' % datetime.datetime.now())
    # Create methylation tracks for each chromosome
    for chr in chrs:
        # 1. Build CpGs
        LOGFH.write('... Build CpG sites for [ %s ] ...  %s\n' % (chr, datetime.datetime.now()))
        try:
            cpgfile = check_file(chr+'_cpgs', PATH=cpg_dir)
        except MethError, e:
            print >> sys.stderr, e.value
            continue
        siteparser = SiteParser(chr)
        siteparser.parse_sites(cpgfile, 'CpGSimple')
        cpg_sites = siteparser.get_sites()
        for cpg in cpg_sites:  # define empty meth score
            cpg.meth_score = '-10000'
        # 2. Get methylation scores
        # note files are saved in 'methstatus_chrN'
        LOGFH.write('... Obtain methylation scores ...\n')
        try:
            mfile = check_file('methstatus_' + chr, PATH=meth_dir)
        except MethError, e:
            print >> sys.stderr, e.value
            sys.exit(2)
Exemple #2
0
def main(chrs, scale, step, meth_dir, cpg_dir, out_dir, sname):
    LOGFH = open('create_microarray_tracks.LOG', 'w')
    LOGFH.write('Start the program ...  %s\n' % datetime.datetime.now())
    # Create methylation tracks for each chromosome
    for chr in chrs:
        # 1. Build CpGs
        LOGFH.write('... Build CpG sites for [ %s ] ...  %s\n' %
                    (chr, datetime.datetime.now()))
        try:
            cpgfile = check_file(chr + '_cpgs', PATH=cpg_dir)
        except MethError, e:
            print >> sys.stderr, e.value
            continue
        siteparser = SiteParser(chr)
        siteparser.parse_sites(cpgfile, 'CpGSimple')
        cpg_sites = siteparser.get_sites()
        for cpg in cpg_sites:  # define empty meth score
            cpg.meth_score = '-10000'
        # 2. Get methylation scores
        # note files are saved in 'methstatus_chrN'
        LOGFH.write('... Obtain methylation scores ...\n')
        try:
            mfile = check_file('methstatus_' + chr, PATH=meth_dir)
        except MethError, e:
            print >> sys.stderr, e.value
            sys.exit(2)
def main(chr, seqfile, outname):
    # Initiate the SiteParser
    LOGFH = open('parse_sites.LOG', 'w')
    LOGFH.write('Start the program for [%s] ...  %s\n' % (chr, str(datetime.datetime.now())))
    LOGFH.flush()
    siteparser = SiteParser(chr)
    # Parse sites
    LOGFH.write('... Start to parse sites ...  %s\n' % str(datetime.datetime.now()))
    LOGFH.flush()
    siteparser.parse_seq(seqfile)
    # Write to the output files
    LOGFH.write('... Save annotation files ...  %s\n' % str(datetime.datetime.now()))
    LOGFH.flush()
    # 1. CpGs
    write2output(outname+'_cpgs', siteparser.sites, chr)
    # 2. RE
    write2output(outname+'_re', siteparser.re_sites, chr)
    # 3. McrBC
    write2output(outname+'_mcrbc', siteparser.mcrbc_sites, chr)
    LOGFH.write('Finish the program for [%s] ...  %s\n' % (chr, str(datetime.datetime.now())))
    LOGFH.close()
Exemple #4
0
 # Get annotation files: e.g., chr1_cpgs, chr1_re, chr1_mcrbc
 try:
     cpg_file = check_file(chr+'_cpgs', PATH=anno_dir)
     re_sitefile = check_file(chr+'_re', PATH=anno_dir)
     mcrbc_sitefile = check_file(chr+'_mcrbc', PATH=anno_dir)
 except MethError, e:
     print >> sys.stderr, e.value
     sys.exit(2)
 # 1. Read parameters
 LOGFH = open(os.path.join(out_dir, 'filter.LOG'), 'a')
 LOGFH.write('Start the program for [%s] ...  %s\n' % (chr, str(datetime.datetime.now())))
 LOGFH.flush()
 paras = parse_paras(parafile)
 # 2. Build CpGs
 LOGFH.write('... Build CpG sites ...  %s\n' % str(datetime.datetime.now()))
 siteparser = SiteParser(chr)
 siteparser.parse_sites(cpg_file, 'CpGFull')
 cpg_sites = siteparser.get_sites()
 # 3. Build RE sites first
 LOGFH.write('... Build RE sites ...  %s\n' % str(datetime.datetime.now()))
 siteparser = SiteParser(chr)
 siteparser.parse_sites(re_sitefile, 'RE')
 re_sites = siteparser.get_sites()
 del siteparser
 # 4. Build RE fragments
 LOGFH.write('... Build RE fragments ...  %s\n' % str(datetime.datetime.now()))
 fragparser = FragmentParser()
 # Split fragfile into subsets to avoid memory overflow
 re_linenum = count_file_lines(re_fragfile)
 refh = open(re_fragfile)
 re_fraglines = []