예제 #1
0
def main(args):
    a_file = open("../doc/pickle/alignment.pickle", "r")

    # Load the 5-way alignment
    alignment = pickle.load(a_file)

    # Close relevant files
    a_file.close()

    skip = [1, 2, 3, 4, 5, 6]
    pvals = [-9, -10]
    len1 = 0
    len2 = 0
    f1 = ""
    f2 = ""
    offset = 0
    for j in pvals:
        #if j == -9: offset = 60
        #else: offset = 0
        print "Doing pval " + str(j)
        pwms = []
        pwmsShuffled = []
        for i in range(111):
            if i+1 < 10:                
                pwms.append("MA000" + str(i+1) + "(p " + str(j) + ").gff")
                pwmsShuffled.append("MA000" + str(i+1) + "random(p " + str(j) + ").gff")
            elif i+1 < 100:
                pwms.append("MA00" + str(i+1) + "(p " + str(j) + ").gff")
                pwmsShuffled.append("MA00" + str(i+1) + "random(p " + str(j) + ").gff")
            else:
                pwms.append("MA0" + str(i+1) + "(p " + str(j) + ").gff")
                pwmsShuffled.append("MA0" + str(i+1) + "random(p " + str(j) + ").gff")            
        for i in range(len(pwms)-offset):            
            f1 = open("../doc/fasta/" + pwms[i+offset], "r")
            f2 = open("../doc/fasta/" + pwmsShuffled[i+offset], "r")
            m1 = cm_scan3.buildMotifs(f1, alignment)
            m2 = cm_scan3.buildMotifs(f2, alignment)
            len1 = len(m1)
            len2 = len(m2)
            f1.close()
            f2.close()
            try:
                print len1, len2
                if len1 != 0 and len2 != 0:
                    print pwms[i+offset]
                    cm_scan3NA.mainRunner(pwms[i+offset], m1, min([len1, len2]), "LL all PWM pval " + str(j) + "/")
                    print pwmsShuffled[i+offset]
                    cm_scan3NA.mainRunner(pwmsShuffled[i+offset], m2, min([len1, len2]), "LL all PWMRandom pval " + str(j) + "/")
                else: print "NO HITS"
            except KeyError:
                print "\t\tkey problem", pwms[i+offset]               
    sys.exit(0)
예제 #2
0
def main(args):
    # Create the tree structure
    supertree = Tree([])
    root = TreeNode("r")
    rodent = TreeNode("")
    primate = TreeNode("")
    highermammal = TreeNode("")
    mouse = TreeNode("3")
    rat = TreeNode("4")
    human = TreeNode("1")
    chimp = TreeNode("2")
    dog = TreeNode("5")
    root.children = [ rodent, highermammal ]
    rodent.children = [ mouse, rat ]
    highermammal.children = [ dog, primate ]
    primate.children = [ human, chimp ]
    supertree.r = root
    supertree.node = [ root, highermammal, rodent, mouse,
                       rat, primate, human, chimp ]
    a = ["A", "C", "T", "G"]
    
    #first I need to make all the trees
    trees = dict()
    for n1 in a:
        for n2 in a:
            for n3 in a:
                for n4 in a:
                    for n5 in a:
                        trees[n1+n2+n3+n4+n5] = color(supertree, [n1, n2, n3, n4, n5])

    a_file = open("../doc/pickle/alignment.pickle", "r")

    # Load the 5-way alignment
    alignment = pickle.load(a_file)

    # Close relevant files
    a_file.close()

    skip = [0]#, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    pvals = [-9]
    len1 = 0    
    f1 = ""    
    for j in pvals:        
        print "Doing pval " + str(j)      
        
        for s in skip:                   
            f1 = open("../doc/fasta/MA0112(p " + str(j) + ").gff", "r")            
            m1 = cm_scan3.buildMotifs(f1, alignment)            
            len1 = findLength("MA0112.pwm")            
            f1.close()
            print len(m1)
            if len1 > s+1:
                if len(m1) != 0:                                                
                    scanNonAdj2.mainRunner("MA0112(p " + str(j) + ").gff", m1, len(m1), "LL all PWM pval " + \
                                           str(j) + " NA " + str(s) + "/", s, trees)                    
                else: print "NO HITS"                    
            #makeGraphs.make("LL all PWM pval " + str(j) + " NA " + str(s) + "/", j, s)
            #randomScanNonAdj2.mainRunner(s, j, trees)
    sys.exit(0)
예제 #3
0
def main(args):
    a_file = open("../doc/pickle/alignment.pickle", "r")

    # Load the 5-way alignment
    alignment = pickle.load(a_file)

    # Close relevant files
    a_file.close()

    skip = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    pvals = [-9, -10]
    len1 = 0    
    f1 = ""    
    for j in pvals:        
        print "Doing pval " + str(j)
        pwms = []
        
        for i in range(111):
            if i+1 < 10:                
                pwms.append("MA000" + str(i+1))                
            elif i+1 < 100:
                pwms.append("MA00" + str(i+1))                
            else:
                pwms.append("MA0" + str(i+1))
        for s in skip:                    
            for i in range(len(pwms)):                
                f1 = open("../doc/fasta/" + pwms[i] + "(p " + str(j) + ").gff", "r")            
                m1 = cm_scan3.buildMotifs(f1, alignment)            
                len1 = findLength(pwms[i] + ".pwm")            
                f1.close()
                print len(m1)
                if len1 > s+1:
                    try:                
                        if len(m1) != 0:
                            print pwms[i]
                            cm_scan3NA.mainRunner(pwms[i] + "(p " + str(j) + ").gff", m1, len(m1), "LL all PWM pval " + str(j) + " NA " + str(s) + "/", s)                    
                        else: print "NO HITS"
                    except KeyError:
                        print "\t\tkey problem", pwms[i]
            makeGraphs.make("LL all PWM pval " + str(j) + " NA " + str(s) + "/", j, s)
            cm_scanTester2.mainRunner(s, j)
    sys.exit(0)
예제 #4
0
"""Take PWM gff hits, and make aligned PWM hits. This was done b/c Rithun needs hits for the controls."""
import cm_scan3, pickle, os

gff_file = '../Doc/fasta/human1ku-corrected.fasta.MA0001random.gff'
alignment_file = '../Doc/pickle/alignment.pickle'
with open(alignment_file) as f:
    alignment = pickle.load(f)

species = ('human', 'chimp', 'mouse', 'rat', 'dog')
pval = '-9'
print 'ControlType\tPWM\tPWMhit\tSpecies\tSeq'
for gff_file in os.listdir('../Doc/fasta/'):
    pwm_type = ''
    if 'shuffle' in gff_file and pval in gff_file:
        pwm_type = 'shuffle'
    elif 'random' in gff_file and pval in gff_file:
        pwm_type = 'random'
    if pwm_type:
        with open('../Doc/fasta/' + gff_file) as f:
            motif_hits = cm_scan3.buildMotifs(f, alignment)
            for idx, hit in enumerate(motif_hits):
                for org, seq in zip(species, hit):
                    pwm = gff_file.split(pwm_type)[0]
                    print pwm_type + '\t' + pwm + '\t' + str(idx+1) + '\t' + org + '\t' + seq
            
예제 #5
0
def main(args):
    # Create the tree structure
    supertree = Tree([])
    root = TreeNode("r")
    rodent = TreeNode("")
    primate = TreeNode("")
    highermammal = TreeNode("")
    mouse = TreeNode("3")
    rat = TreeNode("4")
    human = TreeNode("1")
    chimp = TreeNode("2")
    dog = TreeNode("5")
    root.children = [ rodent, highermammal ]
    rodent.children = [ mouse, rat ]
    highermammal.children = [ dog, primate ]
    primate.children = [ human, chimp ]
    supertree.r = root
    supertree.node = [ root, highermammal, rodent, mouse,
                       rat, primate, human, chimp ]
    a = ["A", "C", "T", "G"]
    
    #first I need to make all the trees
    trees = dict()
    for n1 in a:
        for n2 in a:
            for n3 in a:
                for n4 in a:
                    for n5 in a:
                        trees[n1+n2+n3+n4+n5] = color(supertree, [n1, n2, n3, n4, n5])

    a_file = open("../../Doc/pickle/alignment.pickle", "r")

    # Load the 5-way alignment
    alignment = pickle.load(a_file)

    # Close relevant files
    a_file.close()
    pwmFile = open("../../Doc/Vertebrate PWM/PWMlist.txt", "r")
    pwms = pickle.load(pwmFile)
    pwmFile.close()
    skip = range(1)
    pvals = [-9]
    len1 = 0    
    f1 = ""    
    for j in pvals:        
        print "Doing pval " + str(j)        
        for s in skip:            
            for i in range(len(pwms)):                
                #f1 = open("../doc/fasta/" + pwms[i] + "random(p " + str(j) + ").gff", "r")
                f1 = open("../../Doc/fasta/sortedhuman1ku-corrected.fasta." + pwms[i] + "cc.gff", "r")
                m1 = cm_scan3.buildMotifs(f1, alignment)            
                len1 = findLength(pwms[i] + "cc.pwm")            
                f1.close()
                print len(m1)
                if len1 > s+1:
                    if len(m1) != 0:
                        print pwms[i]
                        scanNonAdj2.mainRunner("sortedhuman1ku-corrected.fasta." + pwms[i] + "cc.gff", m1, len(m1), \
                                               "../../Results/Controls/Comp Permuted PWMs/Raw Data/Gap " + \
                                               str(s) + "/", s, trees)
                        #scanNonAdj2.mainRunner(pwms[i] + "(p " + str(j) + ").gff", m1, len(m1), "LL all PWM pval " + \
                        #                       str(j) + " NA " + str(s) + "/", s, trees)                    
                    #else: print "NO HITS"
            #randomScanNonAdj2.mainRunner(s, j, trees)
    sys.exit(0)