Changeset 1021 for framspy


Ignore:
Timestamp:
07/28/20 16:00:06 (4 years ago)
Author:
Maciej Komosinski
Message:

Checking for genotype validity can now handle multiple genotypes at once

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksCLI.py

    r1019 r1021  
    3838        DISSIMIL_CMD = "dissimil"
    3939        DISSIMIL_FILE = "dissimilarity_matrix.tsv"  # tab-separated values
    40         ISVALID_CMD = "isvalid"
     40        ISVALID_CMD = "arevalid"
    4141        ISVALID_FILE = "validity.txt"
    4242        MUTATE_CMD = "mutate"
     
    9090
    9191                self.__readFromFramsCLIUntil("UserScripts.autoload")
    92                 print('Performing a basic test 1/3... ', end='')
     92                print('Performing a basic test 1/2... ', end='')
    9393                assert self.getSimplest("1") == "X"
    9494                print('OK.')
    95                 print('Performing a basic test 2/3... ', end='')
    96                 assert self.isValid("X[0:0]") is True
    97                 print('OK.')
    98                 print('Performing a basic test 3/3... ', end='')
    99                 assert self.isValid("X[0:0],") is False
     95                print('Performing a basic test 2/2... ', end='')
     96                assert self.isValid(["X[0:0],", "X[0:0]", "X[1:0]"]) == [False, True, False]
    10097                print('OK.')
    10198                if not self.DETERMINISTIC:
     
    249246                        A square array with dissimilarities of each pair of genotypes.
    250247                """
     248                assert isinstance(genotype_list, list)  # because in python str has similar capabilities as list and here it would pretend to work too, so to avoid any ambiguity
    251249                files = self.__runCommand(self.DISSIMIL_CMD, genotype_list, self.DISSIMIL_FILE, self.GENO_SAVE_FILE_FORMAT["NATIVEFRAMS"])
    252250                with open(files[-1]) as f:
     
    265263
    266264
    267         def isValid(self, genotype: str) -> bool:
    268                 files = self.__runCommand(self.ISVALID_CMD, [genotype], self.ISVALID_FILE, self.GENO_SAVE_FILE_FORMAT["RAWGENO"])
    269                 with open(files[-1]) as f:
    270                         valid = f.readline() == "1"
    271                 self.__cleanUpCommandResults(files)
     265        def isValid(self, genotype_list: List[str]) -> List[bool]:
     266                assert isinstance(genotype_list, list)  # because in python str has similar capabilities as list and here it would pretend to work too, so to avoid any ambiguity
     267                files = self.__runCommand(self.ISVALID_CMD, genotype_list, self.ISVALID_FILE, self.GENO_SAVE_FILE_FORMAT["NATIVEFRAMS"])
     268                valid = []
     269                with open(files[-1]) as f:
     270                        for line in f:
     271                                valid.append(line.strip() == "1")
     272                self.__cleanUpCommandResults(files)
     273                assert len(genotype_list) == len(valid), "Submitted %d genotypes, received %d validity values" % (len(genotype_list), len(valid))
    272274                return valid
    273275
     
    319321        print('\tDissimilarity of Parent1 and Offspring:', framsCLI.dissimilarity([parent1, offspring])[0, 1])
    320322        print('\tPerformance of Offspring:', framsCLI.evaluate(offspring))
    321         print('\tValidity of Offspring:', framsCLI.isValid(offspring))
     323        print('\tValidity of Parent1, Parent 2, and Offspring:', framsCLI.isValid([parent1, parent2, offspring]))
    322324
    323325        framsCLI.closeFramsticksCLI()
Note: See TracChangeset for help on using the changeset viewer.