Esempio n. 1
0
        dest="pdb_name",
        required=True,
        help="The path name to file location under PDB_Struct dir or the PDB ID"
    )

    args = parser.parse_args()

    return args


# Retrieve file the file object
cli_args = cli_options()
file_to_process = cli_args.filename
pdb_name = cli_args.pdb_name
# generate the group: [id, seq], ... dictionary
group_id_seq = ip.InputProcessor(file_to_process).process_input()
# extract sequence from PDB
pdb_ds = pp.PdbParser(pdb_name).pdb_processing()
# generate a list of fasta files for multiple alignment
multi_align_fasta_files = fg.FastaGen(group_id_seq, pdb_ds).process_seqs()
# perfrom multiple alignment for each file
all_aligned = OrderedDict()
for fasta in multi_align_fasta_files:
    aligned_key = fasta.split('.')[0]
    all_aligned[aligned_key] = ma.MultiAlign(
        clustal_input=fasta,
        clustal_output='out_{}'.format(fasta),
        clustalw='clustalw2').perform_alignment()
# print(all_aligned)
# OrderedDict([('group_1', {seq_id: seq}),
# ...
Esempio n. 2
0
    def writeToFile(self):
        file = open('user_input.txt', 'w')
        file.write(self.text_area.get("1.0",END+"-1c"))
        file.close()

        ##############################################################################

        # initialize variables
        input = "user_input.txt"
        fio = FileIo(input)
        ip = InputProcessor()
        bp = BlockProcessor()

        # initial setup, process input, tokenize, find parts of speech
        the2DArray = ip.processInput(fio.getFile())
        the2DArray = bp.removeCommas(the2DArray)
        tokenized = ip.tokenize(the2DArray)
        pos = bp.posTagger(the2DArray)


        ##############################################################################

        # noun and verb phrase chunking
        chunkPattern = """
                NP: {<DT|PP\$>?<CD>?(<JJ>|<JJR>|<JJS>)*(<NN>|<NNP>|<NNPS>|<NNS>|<POS>)+}
                {<NNP>+}
                {<NN>+}
                {<PRP>+}
                {<DT><JJ>}
            
                VP: {<MD|TO|RB>?<VB.*>+<RB>?<VB.*>?}
                {<VB.*>+}
                """
        phraseChunk = bp.phraseChunker(tokenized, chunkPattern)
        #for tree in phraseChunk:
        #    print tree

        ##############################################################################

        # count nouns per block and total, update the2DArray
        nounDict = bp.countNouns(pos)
        for key, value in nounDict.iteritems() :
            if key is 'total':
                totalNouns = value
            else:
                the2DArray = bp.updateArray(the2DArray,key,'nounCount',value)

        ##############################################################################

        # count verbs per block and total, update the2DArray
        verbDict = bp.countVerbs(pos)
        for key, value in verbDict.iteritems() :
            if key is 'total':
                totalVerbs = value
            else:
                the2DArray = bp.updateArray(the2DArray,key,'verbCount',value)

        ##############################################################################

        # count adjectives per block and total, update the2DArray
        adjectiveDict = bp.countAdjectives(pos)
        for key, value in adjectiveDict.iteritems() :
            if key is 'total':
                totalAdjectives = value
            else:
                the2DArray = bp.updateArray(the2DArray,key,'adjectiveCount',value)

        ##############################################################################

        # count pronouns per block and total, update the2DArray
        pronounDict = bp.countPronouns(pos)
        for key, value in pronounDict.iteritems() :
            if key is 'total':
                totalPronouns = value
            else:
                the2DArray = bp.updateArray(the2DArray,key,'pronounCount',value)

        ##############################################################################

        # count adverbs per block and total, update the2DArray
        adverbDict = bp.countAdverbs(pos)
        for key, value in adverbDict.iteritems() :
            if key is 'total':
                totalAdverbs = value
            else:
                the2DArray = bp.updateArray(the2DArray,key,'adverbCount',value)

        ##############################################################################

        # count other parts of speech per block and total, update the2DArray
        otherDict = bp.countOther(pos)
        for key, value in otherDict.iteritems() :
            if key is 'total':
                totalOther = value
            else:
                the2DArray = bp.updateArray(the2DArray,key,'otherCount',value)

        ##############################################################################

        # count words per block and total, update the2DArray
        wordCountDict = bp.wordCount(tokenized)
        for key, value in wordCountDict.iteritems() :
            if key is 'total':
                totalWordCount = value
            else:
                the2DArray = bp.updateArray(the2DArray,key,'totalWordCount',value)

        ##############################################################################

        # update the2DArray with totals
        the2DArray = bp.updateArray(the2DArray,len(the2DArray)-1,'nounCount',totalNouns)
        the2DArray = bp.updateArray(the2DArray,len(the2DArray)-1,'verbCount',totalVerbs)
        the2DArray = bp.updateArray(the2DArray,len(the2DArray)-1,'adjectiveCount',totalAdjectives)
        the2DArray = bp.updateArray(the2DArray,len(the2DArray)-1,'pronounCount',totalPronouns)
        the2DArray = bp.updateArray(the2DArray,len(the2DArray)-1,'adverbCount',totalAdverbs)
        the2DArray = bp.updateArray(the2DArray,len(the2DArray)-1,'otherCount',totalOther)
        the2DArray = bp.updateArray(the2DArray,len(the2DArray)-1,'totalWordCount',totalWordCount)

        ##############################################################################

        # process distinct word count and TF-IDF 
        distinctWordCountArray = bp.distinctWordCount(tokenized)
        tf_idfArray = bp.tf_idf_Count(tokenized)

        ##############################################################################

        # ask user for directory name where the output csv files will be saved to
        dirname = tkFileDialog.askdirectory(initialdir="/",title="Choose Directory Location for Results")
        outputDirBase = dirname + '/'
        
        # csv result files will be located in teamNLP file followed by a number
        # if one or more exist already in the user directory location
        count = 1
        baseName = 'teamNLP'
        outputFileName = outputDirBase + baseName
        while (os.path.exists(outputFileName)): # while the directory name exists
            count += 1 # increment the counter...
            outputFileName = outputDirBase + baseName + str(count) 
        os.mkdir(outputFileName) # create folder in user's chosen directory location
        
        numpy.savetxt(outputFileName + '/the2DArray.csv', the2DArray, delimiter=",", fmt="%s")
        numpy.savetxt(outputFileName + '/distinctWordCountArray.csv', distinctWordCountArray, delimiter=",", fmt="%s")
        numpy.savetxt(outputFileName + '/tf_idfArray.csv', tf_idfArray, delimiter=",", fmt="%s")
Esempio n. 3
0
currfloor = maze(5,5,difficulty)

#currfloor.display()
#JailCell = Environment([EnvironmentGenerator.genObject(2,difficulty)],"smelly dark room outside your jail cell",[Door(False,"Up",0)])
CurrEnv = currfloor.getVertex(player.getLocation()[1],player.getLocation()[0]).getEnv()
dprint(CurrEnv.toString())
#Testing RunCode
while(1):
    if not play_obj.is_playing():
        play_obj = wave_obj.play()
    #print("y:"+str(player.getLocation()[0])+" x:"+str(player.getLocation()[1]))
    print("\n")
    data = ""
    if(stot.lower() == 'n' or stot.lower() == 'no'):
        choice = input("What do you do..?\n\t")
        data = InputProcessor.processInput(choice,player,CurrEnv)
    else:
        text = RecognizeSpeech.recognize()
        data = InputProcessor.processInput(text,player,CurrEnv)
    if("Grab" in data):
        continue
    if("Inventory" in data):
        dprint("This is your inventory...\n")
        continue
    if("Equipment" in data):
        dprint("Those are your equipped items..\n")
        continue
    if("Equip" in data):
        dprint ("Equipping done.\n")
        continue
    if("Stairs" in data):
Esempio n. 4
0
from FileIo import *
from InputProcessor import *
from BlockProcessor import *
import nltk
from Switch import *
import sys
import os

if __name__ == "__main__":

    os.system('clear')
    input = "../input.txt"
    #input = "input2"
    fio = FileIo(input)
    ip = InputProcessor()
    bp = BlockProcessor()
    processInput = ip.processInput(fio.getFile())
    tokenized = ip.tokenize(processInput)
    pos = bp.posTagger(processInput)

    print "Original input text:"
    print "###################################################################################\n\n"
    fio.toString();

    print "\n###################################################################################\n\n"

    if (len(sys.argv) == 2):
        choice = str(sys.argv[1])	
    else:
        choice = raw_input("""
import InputProcessor
import SoftmaxLayer

'''
SemiEnd to end BOWIMG model (excluding preprocessing)
'''

if __name__ == "__main__":
	#files that depend on set
	
	#constant files
	mostFreqAnswersFile = '/home/jwong/Documents/LinuxWorkspace/Visual-Question-Answering/resources/1000MostFreqAnswers.csv'
	vocabBOWfile = '/home/jwong/Documents/LinuxWorkspace/Visual-Question-Answering/resources/BOWdimensions.csv'

	#1-25 train batches
	#miniBatchPath = '/media/jwong/Transcend/VQADataset/TrainSet/trainMiniBatches/TrainMiniBatch'
	print('Loading files...')
	
	questionFile = '/media/jwong/Transcend/VQADataset/TrainSet/Questions_Train_mscoco/Preprocessed/processedOpenEnded_trainQns.json'
	imageFile = '/media/jwong/Transcend/VQADataset/TrainSet/ExtractedImageFeatures/VQAImgFeatures_Train.json'
	trainProcessor = InputProcessor.InputProcessor(questionFile, vocabBOWfile, imageFile, mostFreqAnswersFile)

	testQnFile = '/media/jwong/Transcend/VQADataset/ValSet/Questions_Val_mscoco/preprocessedValQnsOpenEnded.json'
	testImgFile = '/media/jwong/Transcend/VQADataset/ValSet/VQAImgFeatures_Test.json'
	testProcessor = InputProcessor.InputProcessor(testQnFile, vocabBOWfile, testImgFile, mostFreqAnswersFile)
	
	Decider = SoftmaxLayer.SoftmaxLayer()
	Decider.runSoftmaxLayer(trainProcessor, testProcessor)
	print('Done.')
Esempio n. 6
0
    def startGame(self):
        n = Network()
        self.teamID = int(n.getData())
        playerString = "TEAMID: " + str(self.teamID)
        self.guiClient = self.gui.render(playerString, False, (225, 225, 250))
        interface = Interface.Interface(self.screen, self.teamID, self.gui)
        self.inProc = InputProcessor.InputProcessor(self.teamID,
                                                    interface.globalActions)
        self.resources = {'$': 50, 'ß': 0, '¶': 8}
        self.makeResText()

        buildingSpacing = (self.screenHeight * 2 / 3) / 8
        for b in range(7):
            xMod = -0.00065 * (
                (b * buildingSpacing) - self.screenHeight / 3)**2.0 + 96
            self.buildingList[0].append(
                Buildings.EmptySpace(0, xMod, b * buildingSpacing + 72,
                                     self.gui))
            self.buildingList[1].append(
                Buildings.EmptySpace(1, self.screenWidth - xMod,
                                     b * buildingSpacing + 72, self.gui))

        # dictionary formatting:
        # { unitID : [teamID, x, y, health, imageIndex, direction, targetX, currentState, healthMod, unitType] }
        # currentState: 0 is idle, 1 is moving, 2 is attacking

        depthSortTimer = 8
        moneyTimer = 60
        peopleTimer = 600
        while self.started:
            prevResources = self.resources.copy()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_t:
                        ssName = "screenshot.png"
                        pygame.image.save(self.screen, ssName)
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()

            # draw the background
            self.drawBG(self.screen)
            # per server communication or whatever:
            # signature = self.teamID

            # sent buildings list setup
            self.buildingsToSend = [
                b.sprID for b in self.buildingList[self.teamID]
            ]
            # sent unit making list setup
            unitsToSend = [
                b.queuedUnit for b in self.buildingList[self.teamID]
                if b.queuedUnit
            ]
            # reset queued units
            for b in self.buildingList[self.teamID]:
                b.queuedUnit = None

            selections = self.inProc.updateSelection(self.unitList,
                                                     self.screen)
            self.inProc.updateBuildingSelection(self.buildingList,
                                                pygame.mouse)
            self.inProc.checkButtonsClicked(pygame.mouse, self.resources)

            states = -1
            for i in range(len(interface.globalActions)):
                b = interface.globalActions[i]
                if b.clicked:
                    states = i

            self.inProc.drawSelection(self.screen, self.unitList)
            # print(selections)
            keys = pygame.key.get_pressed()
            # print([(i, v) for i, v in enumerate(keys) if v == 1]
            toSend = {
                "keys": keys,
                "selections": selections,
                "buildings": self.buildingsToSend,
                "units": unitsToSend,
                "moveState": states
            }
            n.send(self.jEncode(toSend))

            # ^ SEND STUFF v PROCESS RECEIVED STUFF

            self.receivedData = self.jDecode(n.getData())
            # print([(uID, params[3], params[4], params[7]) for uID, params in self.receivedData.items()])
            for unitID, paramList in self.receivedData['units'].items():
                unitID = int(unitID)
                found = False

                u = None
                for un in self.unitList:
                    if un.unitID == unitID:
                        found = True
                        u = un
                        break
                if not found:
                    u = self.spawnUnit(unitID, paramList[9], paramList[0],
                                       paramList[1], paramList[2],
                                       paramList[8])
                    # make spawning effect
                    self.fxList.append(
                        Effects.SpawnEffect(paramList[1], paramList[2]))

                u.x = paramList[1]
                u.y = paramList[2]
                u.health = paramList[3]
                u.imageIndex = paramList[4]
                u.direction = paramList[5]
                u.updateSprites(paramList[6])
                if paramList[7] == 0:
                    u.sprite = u.spriteIdle
                elif paramList[7] == 1:
                    u.sprite = u.spriteMoving
                elif paramList[7] == 2:
                    u.sprite = u.spriteAttack
                if u.health <= 0:
                    self.unitList.remove(u)
            for u in self.unitList:
                if str(u.unitID) not in self.receivedData['units']:
                    u.selected = False
                    self.unitList.remove(u)
            # this updates enemy building sprites based on their upgrades
            self.updateBuildings()

            # money gain timers here
            if moneyTimer > 0:
                moneyTimer -= 1
            else:
                moneyTimer = 60
                self.resources['$'] += 1
                self.makeResText()

            if peopleTimer > 0:
                peopleTimer -= 1
            else:
                peopleTimer = 600
                self.resources['¶'] += 1
                self.makeResText()

            if depthSortTimer > 0:
                depthSortTimer -= 1
            else:
                depthSortTimer = 8
                self.unitList.sort(key=lambda x: x.y * -1, reverse=True)

            for bL in self.buildingList:
                for b in bL:
                    b.action(self.screen)
            i = 0
            for b in self.buildingList[self.teamID]:
                # 'harvests' resources generated by buildings
                if b.generatedResources[1] > 0:
                    self.resources[
                        b.generatedResources[0]] += b.generatedResources[1]
                    b.generatedResources[1] = 0

                if b.markedForDelete:
                    self.buildingList[self.teamID][i] = b.upgradeBuilding
                    if self.inProc.selectedBuilding == b:
                        print("updating selection to new building")
                        b.selected = False
                        self.buildingList[self.teamID][i].selected = True
                        self.inProc.selectedBuilding = self.buildingList[
                            self.teamID][i]
                i += 1

            for u in self.unitList:
                u.draw(self.screen)

            for f in self.fxList:
                f.draw(self.screen)

            for f in self.fxList:
                if f.markedForDelete:
                    self.fxList.remove(f)
                    del f

            # updates rendered resources text of the player
            self.updateResText(prevResources)

            # self.inProc.draw(self.screen)
            self.screen.blit(self.guiClient, (22, 22))
            interface.draw(self.screen)
            self.inProc.drawSelectionInterface(self.screen)
            # draw the resources of the player ((somewhere))
            self.screen.blit(self.resourceGui,
                             (self.screenWidth - 280, self.screenHeight - 24))
            self.clock.tick(60)
            pygame.event.pump()
            if self.screenScalingEnabled:
                self.scaledScreen.blit(pygame.transform.scale2x(self.screen),
                                       (0, 0))
            else:
                self.scaledScreen.blit(self.screen, (0, 0))

            pygame.display.update()