Beispiel #1
0
def flushDirectories(directoryList):
    suffix = 2
    usedNum = False
    for pos in range(len(directoryList)):
        flushDirectory = directoryList[pos].replace(' ', '')
        if len(flushDirectory) == 0:
            flushDirectory = "polyrun"
        print "Flushing directory %s: %s" % (pos, flushDirectory)
        if os.path.exists(flushDirectory):
            print "*** Warning, preparing to flush path:", flushDirectory, " - continue? (yes/no/num/quit) ***"
            print "-num will suffix the output directories with a number"
            print "-no will output over the prior directory without cleanup"
            while True:
                response = str(raw_input(":")).lower()
                if response == "n" or response == "no" or response == "y" or response == "yes" or response == "num" or response == "quit":
                    answer = RollVac.isYes(response, "null")
                    break
                else:
                    print "Invalid Response, please enter yes, no, or num"
            if answer == True:
                shutil.rmtree(flushDirectory)
                print " cleared succesfully"
            elif response == 'quit':
                print "Quitting now....\n\n"
                quit()
            elif response == 'num':
                copyNum = 2
                if os.path.exists(flushDirectory):
                    while os.path.exists(flushDirectory + str(copyNum)):
                        copyNum += 1
                    suffix = max(copyNum, suffix)
                    usedNum = True

        else:
            print "not found, skipping"

    suffix = str(suffix)
    if usedNum:
        print "Duplicate directories found, will append suffix '%s' to output directories" % (
            suffix)
        return str(suffix)
    else:
        return ""
Beispiel #2
0
def flushDirectories(directoryList):
    suffix = 2
    usedNum = False
    for pos in range(len(directoryList)):
        flushDirectory= directoryList[pos].replace(' ','')
        if len(flushDirectory) == 0:
            flushDirectory = "polyrun"
        print "Flushing directory %s: %s" % (pos, flushDirectory)
        if os.path.exists(flushDirectory):
            print "*** Warning, preparing to flush path:", flushDirectory, " - continue? (yes/no/num/quit) ***"
            print "-num will suffix the output directories with a number"
            print "-no will output over the prior directory without cleanup"
            while True:
                response = str(raw_input(":")).lower()
                if response == "n" or response == "no" or response == "y" or response == "yes" or response == "num" or response == "quit":
                    answer = RollVac.isYes(response, "null")
                    break
                else:
                    print "Invalid Response, please enter yes, no, or num"
            if answer == True:
                shutil.rmtree(flushDirectory)
                print " cleared succesfully"             
            elif response == 'quit':
                print "Quitting now....\n\n"
                quit()
            elif response == 'num':
                copyNum = 2
                if os.path.exists(flushDirectory):
                    while os.path.exists(flushDirectory + str(copyNum)):
                        copyNum += 1                 
                    suffix = max(copyNum, suffix)   
                    usedNum = True  
                    
        else:
            print "not found, skipping"
        
    suffix = str(suffix)
    if usedNum:
        print "Duplicate directories found, will append suffix '%s' to output directories" % (suffix)
        return str(suffix)
    else:
        return ""
Beispiel #3
0
def main():
    

# USED TO DEFINE LOADING POSITIONS, MUST BE CONSERVED IN SOURCE AND GDOC
        
    paramsStart = "Study Name Prefix (optional),Diagnosis Based"
    startWord = "Subpopulation,Day/'enum',Length of Spread"
    
    vacsRolled = 0
    
    totalVars = 0
    varList = []
    varSets = []
    suffixes = []
    directorySuffix = ""
    filteredIDs = [{"directory":'null','ids':[]}]
    popSizes = dict()
#    positions = []

# PARSING COMMAND LINE ARGUMENTS FOR PUBLIC/ PRIVATE FILE ACCESS        
    
                    
    if len(sys.argv) > 2:
        if len(sys.argv) == 3:
            sys.argv.insert(2,'null') 
        else:
            print "Ignoring", len(sys.argv) - 2, "excess arguments\n"
    elif len(sys.argv) == 2:
            sys.argv.insert(1,'null')
            sys.argv.insert(1,'null')

    script = gDocsImport.getScript(sys.argv[1], sys.argv[2], sys.argv[3], 0, -1, "default", False, [])
    directoryLines = gDocsImport.getScript(sys.argv[1], sys.argv[2], sys.argv[3], paramsStart, startWord, "default", False,[])
    sys.argv = None
    
# ERASES DIRECTORY NAMES GIVEN BY GDOC
    
    directories = []
    for directory in directoryLines:
        dirToFlush =(directory[2] + '/' + directory[0]).replace('//','/')
        if not dirToFlush in directories: 
            directories.append(dirToFlush)
    
    directorySuffix = flushDirectories(directories)
    
    
# CREATES LISTS OF ALL EXPERIMENTAL VARIABLES ITERATED OVER
            
    length = len(script)
    
    print "Searching list for experimentally iterated variables"
    
    for item in script:
        temp = getPoly(item)
        if temp[0] != 'null':
            if temp[0] not in varSets:
                totalVars += 1
                varList.append(temp[0])
            varSets.append(temp[0]) 
            suffixes.append(temp[1])    
            
    varList.sort()
    length = len(varSets)
    varMatrix = [[] for x in xrange(totalVars)]
    suffixMatrix = [[] for x in xrange(totalVars)]
#    positionMatrix = [[] for x in xrange(totalVars)]
    
    
# CREATES MATRICES OF SUFFIXES, VARIABLE ID, AND LIST POSITION FOR ITERATION  
      
    for pos2 in range(totalVars):              
        for pos1 in range(length):
            if varSets[pos1] == varList[pos2] and (suffixes[pos1] not in suffixMatrix[pos2]):
                varMatrix[pos2].append(varSets[pos1])
                suffixMatrix[pos2].append(suffixes[pos1])
#                positionMatrix[pos2].append(positions[pos1])
    

# SETS UP RUN BOUNDS
        
    runTracker = [0] * totalVars
    done = False
    totalRuns = 1
    ends = []
    for pos in range(totalVars):
        totalRuns *= len(varMatrix[pos])
        ends.append(len(varMatrix[pos])-1)
        if pos >= 1:
            ends[pos] += 1
        
    
# ITERATED RUN GENERATION, IF SCRIPT LINE CONTAINS CURRENT ITERATION RUN MARKERS OR NONE, SENT TO RollVac TO PARSE    
    
    while not done:      
            
        toRun  =  []
        for pos in range(totalVars):
            toRun.append(suffixMatrix[pos][runTracker[pos]])      
        
        length = len(script)
        rollScript = []
        print "Loading Script for line:", runTracker
        for item in script:
            if getPoly(item)[0] == 'null' or getPoly(item)[1] in toRun:
                rollScript.append(filterPoly(item))
                #if len(item.replace('"','').replace(',','').replace('\n','')) != 0:
                    
                
# SUPPORT ADDED FOR MULTIPLE DIRECTORIES/ RUN         
                
        params = gDocsImport.getLine('null', 'null','null', paramsStart, True, rollScript)
        folder = params[2] + '/' + params[0]
        directory = appendSuffix(folder,directorySuffix) 

# OUT DIRECTORY GENERATED VIA SUFFIX MATRIX
                                
        for pos in range(totalVars):
            directory += suffixMatrix[pos][runTracker[pos]] + '/'
            
        params = gDocsImport.loadNClean(False, rollScript, paramsStart, startWord, "single line")
        print params
        
        homeDir = appendSuffix(params[2] + '/' + params[0], directorySuffix)
        explicit =  appendSuffix(params[2], directorySuffix)
        
        needsReplace = len(params[5]) > 0
        noAVDiag = not RollVac.isYes(params[1],'null')
        fileString =  params[3]
        filesToCopy = len(fileString) > 0
            
        filteredIDs = RollVac.main('poly', directory, 'null', 'null', rollScript, filteredIDs, popSizes)
        sleep(0.05)
        
        qsubs = open(homeDir + 'qsublist', 'a+b')
        qsubs.write(("qsub " + directory + 'qsub\n').replace('//','/'))   
        qsubs.close()
        
        if noAVDiag: 
            extraCommands = ["Find = DiagnosisFile =",
                "Replace = ",
                "Find =  AntiviralFile = ",
                "Replace = "]
        else:
            extraCommands = 'null'
                
        if needsReplace:
            replaceFile = params[5]
        else:
            replaceFile = 'null'
               
        if needsReplace or noAVDiag:
            replaceScript = loadReplaceScript(replaceFile, extraCommands)    
            findNReplace(fileString, replaceScript, directory, vacsRolled, homeDir, explicit)
        
        if filesToCopy and not needsReplace:
            print fileString, directory       
            fileCopy(fileString, directory)
            
        vacsRolled += 1


# POLYRUN MULTIDIMENSIONAL LOOP ITERATOR

        if totalVars == 0:
            print "No PolyRun iteration operators found, running in singular mode."
            done = True
            break
            
        pos = 0 
        justRolled = False
 
        while runTracker[pos] == ends[pos] and pos < totalVars - 1:
            justRolled = True
            runTracker[pos] = 0
            runTracker[pos+1] += 1
            pos += 1
            
        if pos == totalVars - 1 and runTracker[pos] == ends[pos]:
            print "Interventions Iterated =", vacsRolled
            done = True
            break
         
        if not justRolled:
            runTracker[0] += 1   
            
    print "Intervention iteration succesfully complete!"
Beispiel #4
0
def main():

    # USED TO DEFINE LOADING POSITIONS, MUST BE CONSERVED IN SOURCE AND GDOC

    paramsStart = "Study Name Prefix (optional),Diagnosis Based"
    startWord = "Subpopulation,Day/'enum',Length of Spread"

    vacsRolled = 0

    totalVars = 0
    varList = []
    varSets = []
    suffixes = []
    directorySuffix = ""
    filteredIDs = [{"directory": 'null', 'ids': []}]
    popSizes = dict()
    #    positions = []

    # PARSING COMMAND LINE ARGUMENTS FOR PUBLIC/ PRIVATE FILE ACCESS

    if len(sys.argv) > 2:
        if len(sys.argv) == 3:
            sys.argv.insert(2, 'null')
        else:
            print "Ignoring", len(sys.argv) - 2, "excess arguments\n"
    elif len(sys.argv) == 2:
        sys.argv.insert(1, 'null')
        sys.argv.insert(1, 'null')

    script = gDocsImport.getScript(sys.argv[1], sys.argv[2], sys.argv[3], 0,
                                   -1, "default", False, [])
    directoryLines = gDocsImport.getScript(sys.argv[1], sys.argv[2],
                                           sys.argv[3], paramsStart, startWord,
                                           "default", False, [])
    sys.argv = None

    # ERASES DIRECTORY NAMES GIVEN BY GDOC

    directories = []
    for directory in directoryLines:
        dirToFlush = (directory[2] + '/' + directory[0]).replace('//', '/')
        if not dirToFlush in directories:
            directories.append(dirToFlush)

    directorySuffix = flushDirectories(directories)

    # CREATES LISTS OF ALL EXPERIMENTAL VARIABLES ITERATED OVER

    length = len(script)

    print "Searching list for experimentally iterated variables"
    print 'DEBOOO', script
    for item in script:
        temp = getPoly(item)
        if temp[0] != 'null':
            if temp[0] not in varSets:
                totalVars += 1
                varList.append(temp[0])
            varSets.append(temp[0])
            suffixes.append(temp[1])

    varList.sort()
    length = len(varSets)
    varMatrix = [[] for x in xrange(totalVars)]
    suffixMatrix = [[] for x in xrange(totalVars)]
    #    positionMatrix = [[] for x in xrange(totalVars)]

    # CREATES MATRICES OF SUFFIXES, VARIABLE ID, AND LIST POSITION FOR ITERATION

    for pos2 in range(totalVars):
        for pos1 in range(length):
            if varSets[pos1] == varList[pos2] and (suffixes[pos1]
                                                   not in suffixMatrix[pos2]):
                varMatrix[pos2].append(varSets[pos1])
                suffixMatrix[pos2].append(suffixes[pos1])
#                positionMatrix[pos2].append(positions[pos1])

# SETS UP RUN BOUNDS

    runTracker = [0] * totalVars
    done = False
    totalRuns = 1
    ends = []
    for pos in range(totalVars):
        totalRuns *= len(varMatrix[pos])
        ends.append(len(varMatrix[pos]) - 1)
        if pos >= 1:
            ends[pos] += 1

# ITERATED RUN GENERATION, IF SCRIPT LINE CONTAINS CURRENT ITERATION RUN MARKERS OR NONE, SENT TO RollVac TO PARSE

    while not done:

        toRun = []
        for pos in range(totalVars):
            toRun.append(suffixMatrix[pos][runTracker[pos]])

        length = len(script)
        rollScript = []
        print "Loading Script for line:", runTracker
        for item in script:
            if getPoly(item)[0] == 'null' or getPoly(item)[1] in toRun:
                rollScript.append(filterPoly(item))
                #if len(item.replace('"','').replace(',','').replace('\n','')) != 0:


# SUPPORT ADDED FOR MULTIPLE DIRECTORIES/ RUN

        params = gDocsImport.getLine('null', 'null', 'null', paramsStart, True,
                                     rollScript)
        folder = params[2] + '/' + params[0]
        directory = appendSuffix(folder, directorySuffix)

        # OUT DIRECTORY GENERATED VIA SUFFIX MATRIX

        for pos in range(totalVars):
            directory += suffixMatrix[pos][runTracker[pos]] + '/'

        params = gDocsImport.loadNClean(False, rollScript, paramsStart,
                                        startWord, "single line")
        print params

        homeDir = appendSuffix(params[2] + '/' + params[0], directorySuffix)
        explicit = appendSuffix(params[2], directorySuffix)

        needsReplace = len(params[5]) > 0
        noAVDiag = not RollVac.isYes(params[1], 'null')
        fileString = params[3]
        filesToCopy = len(fileString) > 0

        filteredIDs = RollVac.main('poly', directory, 'null', 'null',
                                   rollScript, filteredIDs, popSizes)
        sleep(0.05)

        qsubs = open(homeDir + 'qsublist', 'a+b')
        qsubs.write(("qsub " + directory + 'qsub\n').replace('//', '/'))
        qsubs.close()

        if noAVDiag:
            extraCommands = [
                "Find = DiagnosisFile =", "Replace = ",
                "Find =  AntiviralFile = ", "Replace = "
            ]
        else:
            extraCommands = 'null'

        if needsReplace:
            replaceFile = params[5]
        else:
            replaceFile = 'null'

        if needsReplace or noAVDiag:
            replaceScript = loadReplaceScript(replaceFile, extraCommands)
            findNReplace(fileString, replaceScript, directory, vacsRolled,
                         homeDir, explicit)

        if filesToCopy and not needsReplace:
            print fileString, directory
            fileCopy(fileString, directory)

        vacsRolled += 1

        # POLYRUN MULTIDIMENSIONAL LOOP ITERATOR

        if totalVars == 0:
            print "No PolyRun iteration operators found, running in singular mode."
            done = True
            break

        pos = 0
        justRolled = False

        while runTracker[pos] == ends[pos] and pos < totalVars - 1:
            justRolled = True
            runTracker[pos] = 0
            runTracker[pos + 1] += 1
            pos += 1

        if pos == totalVars - 1 and runTracker[pos] == ends[pos]:
            print "Interventions Iterated =", vacsRolled
            done = True
            break

        if not justRolled:
            runTracker[0] += 1

    print "Intervention iteration succesfully complete!"