Esempio n. 1
0
def getPopURL(pop, karyo, hash=None, onlyPop=False, onlyKaryo=False):
    if not hash:
        hash = MEGA.getHash(MEGA.getIndivs(pop))
    if onlyPop:
        return '<a href="pop.py?md5=%s&k=%s">%s<a>' % (hash, karyo, pop)
    elif onlyKaryo:
        return '<a href="pop.py?md5=%s&k=%s">%s<a>' % (hash, karyo, karyo)
    else:
        return '<a href="pop.py?md5=%s&k=%s">%s (%s)<a>' % (hash, karyo, pop, karyo)
Esempio n. 2
0
 def getIndivs(self, pop):
     try:
         if pop not in self.indsPop:
             self.indsPop[pop] = [ind for ind in MEGA.getIndivs(pop)
                                  if ind not in self.alwaysRemove]
             for addPop in self.addPops.get(pop, []):
                 popInds = MEGA.getIndivs(addPop)
                 self.indsPop[pop].extend([ind for ind in popInds
                                           if ind not in self.alwaysRemove])
             for i, ind in enumerate(self.addInds.get(pop, [])):
                 if ind not in self.alwaysRemove:
                     self.indsPop[pop].append(ind)
             for ind in self.delInds.get(pop, []):
                 self.indsPop[pop].remove(ind)
     except ValueError:
         logging.error("pop getIndivs %s %s %s" % (
                       self.study.name, pop, ind))
     return self.indsPop[pop]
Esempio n. 3
0
def doBundle(bundle, pops, sizes):
    myIndivs = []
    for i in range(len(pops)-1):
        myIndivs.extend(MEGA.getIndivs(pops[i]))
        doPop(pops[i], sizes[i], MEGA.getIndivs(pops[i]))
    try:
        os.mkdir(os.sep.join([MEGA.cacheDB, "bundles"]))
    except OSError:
        pass #Already exists, OK
    bundleDir = os.sep.join([MEGA.cacheDB, "bundles", pop])
    try:
        os.mkdir(bundleDir)
    except OSError:
        pass #Already exists, OK
    w = open(bundleDir + os.sep + "basic", "w")
    w.write(str(sizes[-1]) + "\n")
    for i in range(len(pops)-1):
        w.write("\t".join([pops[i], str(sizes[i])]))
        w.write("\n")
    w.close()
    w = open(bundleDir + os.sep + "indivs", "w")
    w.write("\n".join(map(lambda x:str(x), myIndivs)) + "\n")
    w.close()
Esempio n. 4
0
def doBundle(bundle, pops, sizes):
    myIndivs = []
    for i in range(len(pops) - 1):
        myIndivs.extend(MEGA.getIndivs(pops[i]))
        doPop(pops[i], sizes[i], MEGA.getIndivs(pops[i]))
    try:
        os.mkdir(os.sep.join([MEGA.cacheDB, "bundles"]))
    except OSError:
        pass  #Already exists, OK
    bundleDir = os.sep.join([MEGA.cacheDB, "bundles", pop])
    try:
        os.mkdir(bundleDir)
    except OSError:
        pass  #Already exists, OK
    w = open(bundleDir + os.sep + "basic", "w")
    w.write(str(sizes[-1]) + "\n")
    for i in range(len(pops) - 1):
        w.write("\t".join([pops[i], str(sizes[i])]))
        w.write("\n")
    w.close()
    w = open(bundleDir + os.sep + "indivs", "w")
    w.write("\n".join(map(lambda x: str(x), myIndivs)) + "\n")
    w.close()
Esempio n. 5
0
import sys
import MEGA

if len(sys.argv)!=2:
    print "python %s pop" % (sys.argv[0],)
    sys.exit(-1)

pop=sys.argv[1]

if pop in MEGA.bundles:
    print "BUNDLE"
    myPops = MEGA.bundles[pop]
    cnt = 0
    for myPop in myPops:
        myLen = len(MEGA.getIndivs(myPop))
        print "%20s\t%5d" % (myPop, myLen)
        cnt += myLen
    print "%20s\t%5d" %("All", cnt)
else:
    print "CORE POP"
    print len(MEGA.getIndivs(pop))
Esempio n. 6
0
    except OSError:
        pass #Already exists, OK
    bundleDir = os.sep.join([MEGA.cacheDB, "bundles", pop])
    try:
        os.mkdir(bundleDir)
    except OSError:
        pass #Already exists, OK
    w = open(bundleDir + os.sep + "basic", "w")
    w.write(str(sizes[-1]) + "\n")
    for i in range(len(pops)-1):
        w.write("\t".join([pops[i], str(sizes[i])]))
        w.write("\n")
    w.close()
    w = open(bundleDir + os.sep + "indivs", "w")
    w.write("\n".join(map(lambda x:str(x), myIndivs)) + "\n")
    w.close()



if len(lines)==2: #CORE POP
    size = int(lines[1])
    doPop(pop, size, MEGA.getIndivs(pop))
else:
    pops = []
    sizes = []
    for line in lines[1:]:
        toks = line.rstrip().split("\t")
        pops.append(toks[0].lstrip().rstrip())
        sizes.append(int(toks[1]))
    doBundle(pop, pops, sizes)
Esempio n. 7
0
for path in paths:
    sys.path.insert(0, os.path.expanduser(path))

import MEGA
from MEGA import web

web.sendPreamble(None, None, "Populations")

print("<h2>Populations</h2>")

pops = MEGA.pops
karyos = os.listdir(MEGA.cacheDB + "/sets/")
print('<table border="1">')
curr = 1
print("<tr>")
for pop in pops:
    indivs = MEGA.getIndivs(pop)
    hash = MEGA.getHash(indivs)
    print('<td>')
    print(pop)
    start = False
    for myKaryo in karyos:
        if os.path.isdir('%s/sets/%s/%s' % (MEGA.cacheDB, myKaryo, hash)):
            print("%s" % web.getPopURL(pop, myKaryo, hash, onlyKaryo=True))
    print('</td>')
    if curr % 6 == 0:
        print("</tr><tr>")
    curr += 1
print("</tr>")
print("</table>")
Esempio n. 8
0
        os.mkdir(os.sep.join([MEGA.cacheDB, "bundles"]))
    except OSError:
        pass  #Already exists, OK
    bundleDir = os.sep.join([MEGA.cacheDB, "bundles", pop])
    try:
        os.mkdir(bundleDir)
    except OSError:
        pass  #Already exists, OK
    w = open(bundleDir + os.sep + "basic", "w")
    w.write(str(sizes[-1]) + "\n")
    for i in range(len(pops) - 1):
        w.write("\t".join([pops[i], str(sizes[i])]))
        w.write("\n")
    w.close()
    w = open(bundleDir + os.sep + "indivs", "w")
    w.write("\n".join(map(lambda x: str(x), myIndivs)) + "\n")
    w.close()


if len(lines) == 2:  #CORE POP
    size = int(lines[1])
    doPop(pop, size, MEGA.getIndivs(pop))
else:
    pops = []
    sizes = []
    for line in lines[1:]:
        toks = line.rstrip().split("\t")
        pops.append(toks[0].lstrip().rstrip())
        sizes.append(int(toks[1]))
    doBundle(pop, pops, sizes)
Esempio n. 9
0
def doPop(pop):
    indivs = MEGA.getIndivs(pop)
    popHash = stats.doBasicInfoSet(indivs)
    sql.addId("pop/" + pop, popHash)