Example #1
0
 def test_count_to_transfac(self):
     """
     Test if the count_to_transfac function works.
     """
     ref_input = [
         "         a     b     c     d\n",  # header
         "1        0     0     0     0\n",
         "2        2   789 99999    89\n",  # one value is written
         # on 5 characters
         "3    99999  8888     2     2\n",  # the first value is
         # written on 5 characters
         "4       99     0 999999     0\n",  # one value is written
         # on more than 5
         # characters
         "5        0     0     0     0\n",
     ]
     identifier = "identifier"
     ref_output = (
         "ID identifier\n"
         "BF unknown\n"
         "P0       a     b     c     d\n"
         "00001     0     0     0     0    X\n"
         "00002     2   789 99999    89    X\n"
         "00003 99999  8888     2     2    X\n"
         "00004    99     0 999999     0    X\n"
         "00005     0     0     0     0    X\n"
         "XX\n"
         "//"
     )
     output = PB.count_to_transfac(identifier, ref_input)
     ref_output_lines = ref_output.split("\n")
     output_lines = output.split("\n")
     self.assertEqual(len(ref_output_lines), len(output_lines), "Not the right number of lines")
     for ref_line, line in zip(ref_output_lines, output_lines):
         print("ref:", ref_line)
         print("out:", line)
         self.assertEqual(ref_line, line)
Example #2
0
# G. E. Crooks, G. Hon, J.-M. Chandonia, and S. E. Brenner.
# 'WebLogo: A Sequence Logo Generator.'
# Genome Research 14:1188–90 (2004)
# doi:10.1101/gr.849004.
# http://weblogo.threeplusone.com/
#-------------------------------------------------------------------------------
if options.logo:
    # read count file
    #-------------------------------------------------------------------------------
    f_in = open(options.f, 'r')
    count_content = f_in.readlines()
    f_in.close()

    # convert a table of PB frequencies into transfac format as required by weblogo
    # http://meme.sdsc.edu/meme/doc/transfac-format.html
    transfac_content = PB.count_to_transfac(options.f, count_content)

    # write transfac file (debug only)
    #-------------------------------------------------------------------------------
    debug = False
    if debug:
        transfac_name = options.o + ".PB.transfac"
        f_out = open(transfac_name, 'w')
        f_out.write(transfac_content)
        f_out.close()
        print("wrote {0}".format(transfac_name))

    # define output file name
    #-------------------------------------------------------------------------------
    logo_file_name = options.o + ".PB.logo.pdf"
    if options.residue_min or options.residue_max:
Example #3
0
# G. E. Crooks, G. Hon, J.-M. Chandonia, and S. E. Brenner.
# 'WebLogo: A Sequence Logo Generator.'
# Genome Research 14:1188–90 (2004)
# doi:10.1101/gr.849004.
# http://weblogo.threeplusone.com/
# -------------------------------------------------------------------------------
if options.logo:
    # read count file
    # -------------------------------------------------------------------------------
    f_in = open(options.f, "r")
    count_content = f_in.readlines()
    f_in.close()

    # convert a table of PB frequencies into transfac format as required by weblogo
    # http://meme.sdsc.edu/meme/doc/transfac-format.html
    transfac_content = PB.count_to_transfac(options.f, count_content)

    # write transfac file (debug only)
    # -------------------------------------------------------------------------------
    debug = False
    if debug:
        transfac_name = options.o + ".PB.transfac"
        f_out = open(transfac_name, "w")
        f_out.write(transfac_content)
        f_out.close()
        print("wrote {0}".format(transfac_name))

    # define output file name
    # -------------------------------------------------------------------------------
    logo_file_name = options.o + ".PB.logo.pdf"
    if options.residue_min or options.residue_max: