Beispiel #1
0
    async def color_command(self, ctx: Context, color):
        """
        Control your Discord color.
        """

        color_choice_string = ', '.join(k for k in COLOR_ROLES)
        color = pydash.chain(ctx.message.content) \
            .replace(ctx.prefix + 'mycolor', '') \
            .trim() \
            .title_case() \
            .value()
        role_id = COLOR_ROLES.get(color, None)
        server = self.bot.get_server(ZEN_SERVER)

        if role_id is None:
            await self.bot.say('Try again with one of these colors'
                               f': {color_choice_string}')
            return

        new_roles = [r for r in ctx.message.author.roles] + \
                    [self.get_role(server, role_id)]
        new_roles = pydash.uniq(new_roles)

        await self.bot.replace_roles(
            ctx.message.author, *[
                r for r in new_roles
                if r.name not in COLOR_ROLES or r.id == role_id
            ])
Beispiel #2
0
def parse_addresses(data: str) -> list[str]:
    data = data.lower()
    result = []
    for word in data.split():
        if len(word) == 42 and re.match("0x[a-f0-9]{40}", word):
            result.append(word)
    return pydash.uniq(result)
    def list_devices(self, requirements: dict, fields: str = "") -> list:
        """
        Get list of devices filtered by given requirements and optional extra fields
        :param requirements: filter dictionary
        :param fields: extra fields to include
        :return: list of objects that represent devices
        """
        req_keys = list(requirements.keys())
        req_keys.extend(['present', 'ready', 'using', 'owner'])
        req_keys.extend([
            'serial', 'manufacturer', 'model',
            'platform', 'sdk', 'version', 'note', 'group.name'
        ])
        req_keys.extend(fields.split(','))
        fields = uniq(req_keys)

        predicate = requirements.copy()

        predicate.update(
            dict(
                present=True,
                ready=True,
                using=False,
                owner=None,
                status=3)  # 3=Online 
        )

        self.logger.debug(
            f"Find devices with requirements: {json.dumps(requirements)}, using fields: {','.join(fields)}")

        devices = self.get_devices(fields=fields)

        return filter_(devices, predicate)
Beispiel #4
0
def get_expected_ack_slot_types(intents_info, context=None) -> List:
    """
    :return: all the slot types (i.e. ["location", "time", "people"] etc.) based on expected and ack slots
    """

    return py_.uniq(
        get_slot_types(intents_info, context, key="expected_slots") +
        get_slot_types(intents_info, context, key="ack_slots"))
Beispiel #5
0
def mergeWordToIndex(listOfWordToIndex: List[Dict[str, int]]) -> Tuple[Dict[int, str], Dict[str, int]]:
    vocabList = []
    for wordToIndex in listOfWordToIndex:
        vocabList += wordToIndex.keys()
    vocabList = uniq(vocabList)
    wordToIndex = {vocab: idx for idx, vocab in enumerate(vocabList)}
    indexToWord = {idx: vocab for idx, vocab in enumerate(vocabList)}

    return indexToWord, wordToIndex
Beispiel #6
0
    def single_file_handler(self, single_chunk_files):
        '''单分片文件处理方法
        '''
        succ_list = []
        err_list = []
        wait_add_tasks = []
        wait_update_tasks = []
        taskdao = TaskDAO()

        tenant_id = g.tenant_id if hasattr(g, 'tenant_id') else 0
        batches = _.uniq(
            [Utils.get_batch(i.get('dir_path')) for i in single_chunk_files])
        task_ids = [i.get('file_key') for i in single_chunk_files]
        exist_tasks = taskdao.get_tasks(tenant_id, batches, task_ids)
        exist_tasks_map = {}
        for exist_task in exist_tasks:
            exist_tasks_map[exist_task.task_id] = exist_task.id

        for single_chunk_file in single_chunk_files:
            try:
                file_key = single_chunk_file.get('file_key')
                dir_path = single_chunk_file.get('dir_path')
                file_name = single_chunk_file.get('file_name')
                tenant_id = single_chunk_file.get('tenant_id')
                user_id = single_chunk_file.get('user_id')

                merged_file = os.path.join(dir_path, file_name)
                final_merged_file = os.path.join(dir_path, f'{file_key}.1')
                shutil.move(final_merged_file, merged_file)

                task_json = {
                    'created_by': user_id,
                    'tenant_id': tenant_id,
                    'task_id': file_key,
                    'chunks': '1',
                    'status': TASK_STATUS_MERGED,
                    'size': os.path.getsize(merged_file),
                    'link': {
                        'host': Utils.get_host(dir_path)
                    },
                    'batch': Utils.get_batch(dir_path)
                }
                if exist_tasks_map.get(file_key):
                    task_json['id'] = exist_tasks_map.get(file_key)
                    wait_update_tasks.append(task_json)
                else:
                    wait_add_tasks.append(task_json)
                succ_list.append({'file_key': file_key, 'curr_chunk': 1})
            except Exception as err:
                err_list.append({'file_key': file_key, 'curr_chunk': 1})

        if len(wait_add_tasks):
            taskdao.bulk_add(wait_add_tasks)
        if len(wait_update_tasks):
            taskdao.bulk_update(wait_update_tasks)
        return succ_list, err_list
Beispiel #7
0
 def unique(self):
     """Get an array of unique list items
     
     Raises:
         StateNotList: If state is not a list
     
     Returns:
         Chepy: The Chepy object.
     """
     assert isinstance(self.state, list), StateNotList()
     self.state = pydash.uniq(self.state)
     return self
Beispiel #8
0
 def to_csv_line(cls, task: 'Task') -> str:
     csv = []
     for index, problemset in enumerate(task['solutions']):
         solutions = pydash.uniq(
             list(
                 cls.grid_to_csv_string(problem['output'])
                 for problem in problemset))
         solution_str = " ".join(solutions[:3]) if len(
             solutions) else cls.default_csv_line(task)
         line = ",".join(
             [cls.object_id(task.filename, index), solution_str])
         csv.append(line)
     return "\n".join(csv)
Beispiel #9
0
    def feature_combinations(cls, features: List, depth=0) -> List:
        depth = depth or len(features)
        # depth = np.min( np.max(0, depth), len(features) )

        combinations = pydash.flatten([
            list(itertools.combinations(features, n))
            for n in range(0, depth + 1)
        ])
        combinations += [tuple(features)]
        combinations = pydash.uniq(combinations)

        # DEBUG: print( type(combinations), combinations )
        return combinations
Beispiel #10
0
def get_slot_types(intents_info, context=None, key="expected_slots") -> List:
    """
    :return: all the slot types (i.e. ["location", "time", "people"] etc.) based on key
    Valid keys: expected_slots, ack_slots
    """
    slot_types: List = []
    if context.get(key):
        for exp_slot in context.get(key):
            for intent in intents_info:
                for slot in intent["slots"]:
                    if slot.get("name") == exp_slot:
                        slot_types.extend(slot.get("type", []))
                        break
    return py_.uniq(slot_types)
Beispiel #11
0
 def unique(self):
     """Get an array of unique list items
     
     Raises:
         TypeError: If state is not a list
     
     Returns:
         Chepy: The Chepy object.
     """
     if isinstance(self.state, list):
         self.state = pydash.uniq(self.state)
         return self
     else:  # pragma: no cover
         raise TypeError("State is not a list")
Beispiel #12
0
def str_to_list(data: str,
                lower=False,
                remove_comments=False,
                unique=False) -> list[str]:
    if lower:
        data = data.lower()
    arr = [line.strip() for line in data.split("\n") if line.strip()]
    if remove_comments:
        arr = [line.split("#")[0].strip() for line in arr]
        arr = [line for line in arr if line]
    if unique:
        arr = pydash.uniq(arr)

    return arr
Beispiel #13
0
def cli(path):
    path = Path(path)
    addresses: list = []
    if path.is_file():
        _parse_file(path, addresses)
    elif path.is_dir():
        _parse_dir(path, addresses)
    else:
        fatal("can't open path")

    if addresses:
        for a in pydash.uniq(addresses):
            click.echo(a)
    else:
        click.echo("nothing found")
def public_members(cpp_ast_json, class_name):
    '''
    Parameters
    ----------
    cpp_ast_json : dict
        Root of json-formatted C++ abstract syntax tree.
    class_name : str
        Class name, e.g., `foo::bar::FooBar`.

    Returns
    -------
    list
        List of publicly exposed members from specified class and all base
        classes, sorted by member name.

    Notes
    -----
        Multiple methods with the same signature are overridden based on order
        of inheritance.

        Behaviour for overloaded methods (i.e., multiple methods with different
        call signatures) is currently **undefined**.
    '''
    get_class_json = get_class_factory(cpp_ast_json)
    f_public_members = (py_.curry_right(py_.pick_by)
                        (lambda v, k: (v.get('access_specifier') in
                                       ('PUBLIC', None))))

    def _public_members(class_name, members):
        class_ = get_class_json(class_name)
        class_members = [dict(mergedicts({'class': class_name, 'name': name_i},
                                         method_i))
                         for name_i, method_i in
                         f_public_members(class_.get('members', {})).items()]
        members.extend(sorted(class_members, key=lambda v: v['name']))

        for name_i, base_i in reversed(list(class_.get('base_specifiers',
                                                       {}).items())):
            if base_i.get('access_specifier') in (None, 'PUBLIC'):
                _public_members(name_i, members)
    members = []
    _public_members(class_name, members)
    return sorted(py_.uniq(members, 'name'), key=lambda v: v['name'])
Beispiel #15
0
 def _collect(self,
              func,
              filter=None,
              reactions=None,
              unique=False,
              flatten=True):
     if reactions is None:
         reactions = self.reactions
     if filter is not None:
         reactions = [r for r in reactions if filter(r)]
     collected = []
     for r in reactions:
         c = func(r)
         collected.append(c)
     if flatten:
         collected = pydash.flatten(collected)
     if unique:
         collected = pydash.uniq(collected)
     return collected
Beispiel #16
0
    def get_possible_moves(self,
                           initial_x,
                           initial_y,
                           current_board=None,
                           visited=None,
                           level=0):
        if current_board is None:
            current_board = deepcopy(self.game_board)
        if visited is None:
            visited = [[initial_x, initial_y]]
        else:
            visited.append([initial_x, initial_y])
        adjacent_options = []
        all_options = []
        for row in range(len(self.game_board)):
            for cell in range(len(self.game_board[row])):
                if self.is_legal(initial_x, initial_y, cell + 1, row + 1,
                                 current_board) and self.is_a_first_grade_move(
                                     initial_x, initial_y, cell + 1, row + 1):
                    all_options.append([cell + 1, row + 1])
                if level == 0 and self.is_legal(
                        initial_x, initial_y, cell + 1, row + 1,
                        current_board) and self.is_adjacent(
                            initial_x, initial_y, cell + 1, row + 1):
                    adjacent_options.append([cell + 1, row + 1])

        for pair in all_options:
            if len(pair) > 0 and [pair[0], pair[1]] not in visited:
                current_board = self.move_pretend(initial_x, initial_y,
                                                  pair[0], pair[1],
                                                  current_board)
                level += 1
                all_options = all_options + self.get_possible_moves(
                    pair[0], pair[1], current_board, visited, level=level)
                #all_options.remove([initial_x, initial_y])
        return uniq(all_options + adjacent_options)
Beispiel #17
0
def fetch(filters, queries, locations, numberOfPages, maxRate, numBedrooms=None, tries=5):
    # base url for the craigslist catogory
    base_url = 'http://losangeles.craigslist.org/search/apa?'

    api_key="6ry0OW6wJFglXoNKrDSaxOSbeni9i9hlvQ8AeTSwy3qmfzNd2w0LdzLWSBYt5RADq+OKUF840wRzj7/HWBLMJQ=="

    pageInc = 100

    apts = []
    for query in queries:
        for page in range(numberOfPages):

            params = list(filters)
            params.append(('query',query))
            params.append(('s',page*pageInc))

            plainUrl = base_url + urllib.urlencode(params,'')
            url = urllib.quote(plainUrl)

            # Setup your REST GET request URL here
            getUrl = 'https://api.import.io/store/data/ae9b3481-fd34-4f31-88dc-ab2c18edde46/_query?input/webpage/url='+url+'&_user=43864eeb-fab1-4163-94ab-29ce26a543e5&_apikey='+urllib.quote(api_key,'')

            print 'FETCHING:'
            print ''
            print 'search:', query
            print ''
            print 'paging:', str(page*pageInc) + "-" + str((page+1)*pageInc)
            print ''
            print 'craigslist url:', plainUrl
            print ''
            print 'import.io API url:', getUrl
            print ''

            noResponse = True
            t = 0
            response = ''
            data = {}
            while ('results' not in data) and (t < tries):
                response = urllib.urlopen(getUrl).read()
                data = json.loads(response)
                t = t+1

            if 'results' in data:
                results = data['results']
                print str(len(results)) + ' results'
                for result in results:
                    # Gather the information you want from your API request
                    if all(key in result for key in ['title/_text', 'title', 'price', 'bedrooms', 'location']):
                        title = result['title/_text']
                        url = result['title']
                        price = float(result['price'].replace(',','').replace('$',''))
                        bedrooms = float(result['bedrooms'].replace('br',''))
                        location = result['location'].lower()
                        apt = {'title':title, 'url':url, 'price':price, 'bedrooms':bedrooms, 'ratio':price/bedrooms, 'location':location}
                        apts.append(apt)
            else:
                print 'FAILURE'
                print data

            print ''
            print '-'*79
            print ''

    def validLoaction(string):
        found = map(lambda loc: string.find(loc) != -1, locations)
        if 1 in found:
            return True
        else:
            return False

    totalResults = len(apts)

    if numBedrooms:
        apts = pydash.select(apts, lambda x: x['bedrooms'] == 1.)

    # sort based on ratio
    sortedApts = pydash.sort_by(apts, lambda x: x['ratio'])

    # filter based on ratio
    filteredApts = pydash.select(sortedApts, lambda x: x['ratio'] <= maxRate and x['ratio'] > 1)

    # filter location strings
    locationApts = pydash.select(filteredApts, lambda x: validLoaction(x['location']))

    # only show the unique results!
    uniqApts = pydash.uniq(locationApts)

    return uniqApts
Beispiel #18
0
def test_uniq(case, filter_by, expected):
    assert _.uniq(case, filter_by) == expected
 def ebl_atf_text_line__normalized_modifiers(
     self, modifiers: Iterable[Flag]
 ) -> Sequence[Flag]:
     return tuple(pydash.uniq(modifiers))
 def private_keys_validator(cls, v):
     return pydash.uniq(v)
Beispiel #21
0
 def addGroups(self, groups: Union[GroupMetadata, List[GroupMetadata]]):
     """
     After we build a concanated automata, we can add group metadata of child automata into it.
     """
     self.groups = uniq(self.groups + flatten([groups]))
Beispiel #22
0
def test_uniq(case, expected):
    assert _.uniq(case) == expected
Beispiel #23
0
def get_df_aeb_list(session_df):
    '''Get the aeb list for session_df for iterating.'''
    aeb_list = sorted(
        ps.uniq([(a, e, b) for a, e, b, col in session_df.columns.tolist()]))
    return aeb_list
Beispiel #24
0
def copyNumberAnalysis(name, geneList, gainLossTree, geneTree):

    # Initialise variables

    independentGenes = []
    affectedGenes = []
    affectedOrthologs = {}

    hsapProteins = re.findall(r"(ENSP\d+)", geneTree)
    ptroProteins = re.findall(r"(ENSPTRP\d+)", geneTree)
    ggorProteins = re.findall(r"(ENSGGOP\d+)", geneTree)
    mmulProteins = re.findall(r"(ENSMMUP\d+)", geneTree)
    cjacProteins = re.findall(r"(ENSCJAP\d+)", geneTree)
    rnorProteins = re.findall(r"(ENSRNOP\d+)", geneTree)
    mmusProteins = re.findall(r"(ENSMUSP\d+)", geneTree)
    ocunProteins = re.findall(r"(ENSOCUP\d+)", geneTree)
    cfamProteins = re.findall(r"(ENSCAFP\d+)", geneTree)
    fcatProteins = re.findall(r"(ENSFCAP\d+)", geneTree)
    ecabProteins = re.findall(r"(ENSECAP\d+)", geneTree)
    oariProteins = re.findall(r"(ENSOARP\d+)", geneTree)
    btauProteins = re.findall(r"(ENSBTAP\d+)", geneTree)
    sscrProteins = re.findall(r"(ENSSSCP\d+)", geneTree)

    hsapCopyNumber = len(hsapProteins)
    ptroCopyNumber = len(ptroProteins)
    ggorCopyNumber = len(ggorProteins)
    mmulCopyNumber = len(mmulProteins)
    cjacCopyNumber = len(cjacProteins)
    rnorCopyNumber = len(rnorProteins)
    mmusCopyNumber = len(mmusProteins)
    ocunCopyNumber = len(ocunProteins)
    cfamCopyNumber = len(cfamProteins)
    fcatCopyNumber = len(fcatProteins)
    ecabCopyNumber = len(ecabProteins)
    oariCopyNumber = len(oariProteins)
    btauCopyNumber = len(btauProteins)
    sscrCopyNumber = len(sscrProteins)

    ptroOrthologsFamily = []
    ggorOrthologsFamily = []
    mmulOrthologsFamily = []
    cjacOrthologsFamily = []
    rnorOrthologsFamily = []
    mmusOrthologsFamily = []
    ocunOrthologsFamily = []
    cfamOrthologsFamily = []
    fcatOrthologsFamily = []
    ecabOrthologsFamily = []
    oariOrthologsFamily = []
    btauOrthologsFamily = []
    sscrOrthologsFamily = []

    contractionPValueRegexMatches = re.findall("(?:40093268|40093269|40093275|40093291|40093295|40093297|40093299|40093301|40093302|40093303|40093305|Hsap) => \d+ \(([01]\.\d+)\) \[contraction\]", gainLossTree)

    # if contractionPValueRegexMatches:
    #     print("contractionPValueRegexMatches " + str(len(contractionPValueRegexMatches)))

    for gene in geneList:
        with open('datasets/ensemblHomologiesGrch37/' + gene + '.json',
                  'r') as geneFile:
            homologyData = json.load(geneFile)
            homologies = homologyData['data'][0]['homologies']

            numOneToOne = 0
            oneToOne = []
            oneToMany = []
            manyToMany = []
            affected = False
            ptroOrthologs = []
            ggorOrthologs = []
            mmulOrthologs = []
            cjacOrthologs = []
            rnorOrthologs = []
            mmusOrthologs = []
            ocunOrthologs = []
            cfamOrthologs = []
            fcatOrthologs = []
            ecabOrthologs = []
            oariOrthologs = []
            btauOrthologs = []
            sscrOrthologs = []

            for homolog in homologies:
                if (homolog['type'] == 'within_species_paralog' or
                        homolog['type'] == 'other_paralog' or
                        homolog['type'] == 'gene_split' or
                        homolog['type'] == 'between_species_paralog') and any(
                            homolog['taxonomy_level'] in s
                            for s in taxonomyLevels):
                    affected = True
                else:
                    if homolog['target']['species'] == 'bos_taurus':
                        btauOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'callithrix_jacchus':
                        cjacOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'canis_familiaris':
                        cfamOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'equus_caballus':
                        ecabOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'felis_catus':
                        fcatOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'gorilla_gorilla':
                        ggorOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'macaca_mulatta':
                        mmulOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'mus_musculus':
                        mmusOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'oryctolagus_cuniculus':
                        ocunOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'ovis_aries':
                        oariOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'pan_troglodytes':
                        ptroOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'rattus_norvegicus':
                        rnorOrthologs.append(homolog['target']['protein_id'])
                    elif homolog['target']['species'] == 'sus_scrofa':
                        sscrOrthologs.append(homolog['target']['protein_id'])

                    if (homolog['type'] == 'ortholog_one2one' or homolog['type'] == 'apparent_ortholog_one2one') and any(homolog['target']['species'] in s for s in speciesSubset):
                        numOneToOne += 1
                        oneToOne.append(homolog['target']['species'])
                    elif (homolog['type'] == 'ortholog_one2many' or homolog['type'] == 'apparent_ortholog_one2many') and any(homolog['target']['species'] in s for s in speciesSubset):
                        oneToMany.append(homolog['target']['species'])
                    elif (homolog['type'] == 'ortholog_many2many' or homolog['type'] == 'apparent_ortholog_many2many') and any(homolog['target']['species'] in s for s in speciesSubset):
                        manyToMany.append(homolog['target']['species'])

            if affected:
                affectedGenes.append(gene)
                orthologs = ptroOrthologs + ggorOrthologs + mmulOrthologs + cjacOrthologs + rnorOrthologs + mmusOrthologs + ocunOrthologs + cfamOrthologs + fcatOrthologs + ecabOrthologs + oariOrthologs + sscrOrthologs + btauOrthologs
                orthologs.sort()
                affectedOrthologs[gene] = orthologs
            else:
                ptroOrthologsFamily.append(ptroOrthologs)
                ggorOrthologsFamily.append(ggorOrthologs)
                mmulOrthologsFamily.append(mmulOrthologs)
                cjacOrthologsFamily.append(cjacOrthologs)
                rnorOrthologsFamily.append(rnorOrthologs)
                mmusOrthologsFamily.append(mmusOrthologs)
                ocunOrthologsFamily.append(ocunOrthologs)
                cfamOrthologsFamily.append(cfamOrthologs)
                fcatOrthologsFamily.append(fcatOrthologs)
                ecabOrthologsFamily.append(ecabOrthologs)
                oariOrthologsFamily.append(oariOrthologs)
                sscrOrthologsFamily.append(sscrOrthologs)
                btauOrthologsFamily.append(btauOrthologs)

                independentGenes.append(gene)

                oneToMany = list(set(oneToMany))
                manyToMany = list(set(manyToMany))
                numOneToMany = len(oneToMany)
                numManyToMany = len(manyToMany)
                numDup = numOneToMany + numManyToMany
                numNoOrtho = 13 - (numOneToMany + numOneToOne + numManyToMany)
                print(gene + '\t' + str(numOneToOne) + '\t' + str(numDup) + '\t' + str(numNoOrtho) + '\tindependent\t' + name)

    if affectedGenes:
        independentAndAffectedGroup = len(independentGenes) + 1
        significantContraction = False
        for pvalue in contractionPValueRegexMatches:
            if pvalue < 0.01:
                significantContraction = True
        ptroCopyNumber -= len(pydash.uniq(ptroOrthologsFamily))
        ggorCopyNumber -= len(pydash.uniq(ggorOrthologsFamily))
        mmulCopyNumber -= len(pydash.uniq(mmulOrthologsFamily))
        cjacCopyNumber -= len(pydash.uniq(cjacOrthologsFamily))
        rnorCopyNumber -= len(pydash.uniq(rnorOrthologsFamily))
        mmusCopyNumber -= len(pydash.uniq(mmusOrthologsFamily))
        ocunCopyNumber -= len(pydash.uniq(ocunOrthologsFamily))
        cfamCopyNumber -= len(pydash.uniq(cfamOrthologsFamily))
        fcatCopyNumber -= len(pydash.uniq(fcatOrthologsFamily))
        ecabCopyNumber -= len(pydash.uniq(ecabOrthologsFamily))
        oariCopyNumber -= len(pydash.uniq(oariOrthologsFamily))
        sscrCopyNumber -= len(pydash.uniq(sscrOrthologsFamily))
        btauCopyNumber -= len(pydash.uniq(btauOrthologsFamily))

        if significantContraction:
            #print('significant contraction ' + name)
            pass
        else:

            groups = []

            for key1, value1 in affectedOrthologs.iteritems():
                added = False
                for groupIndex, groupValue in enumerate(groups):
                    if len(intersection(value1, groupValue['orthologs'])):
                        groupGenes = union(groupValue['genes'],[key1])
                        groupOrthologs = union(value1, groupValue['orthologs'])

                        del groups[groupIndex]

                        for groupIndex2, groupValue2, in enumerate(groups):

                            if len(intersection(groupOrthologs, groupValue2['orthologs'])):
                                groupGenes = union(groupGenes,groupValue2['genes'])
                                groupOrthologs = union(groupOrthologs, groupValue2['orthologs'])

                                del groups[groupIndex2]

                                groups.append({'genes': groupGenes, 'orthologs': groupOrthologs})
                                added = True
                        if not added:
                            groups.append({'genes': groupGenes, 'orthologs': groupOrthologs})
                            added = True
                if not added:
                    groups.append({'genes':[key1], 'orthologs': value1})

            for group in groups:
                groupGenes = group['genes']
                groupOrthologs = group['orthologs']
                ptroCopyNumber -= len(pydash.uniq(ptroOrthologsFamily))
                ggorCopyNumber -= len(pydash.uniq(ggorOrthologsFamily))
                mmulCopyNumber -= len(pydash.uniq(mmulOrthologsFamily))
                cjacCopyNumber -= len(pydash.uniq(cjacOrthologsFamily))
                rnorCopyNumber -= len(pydash.uniq(rnorOrthologsFamily))
                mmusCopyNumber -= len(pydash.uniq(mmusOrthologsFamily))
                ocunCopyNumber -= len(pydash.uniq(ocunOrthologsFamily))
                cfamCopyNumber -= len(pydash.uniq(cfamOrthologsFamily))
                fcatCopyNumber -= len(pydash.uniq(fcatOrthologsFamily))
                ecabCopyNumber -= len(pydash.uniq(ecabOrthologsFamily))
                oariCopyNumber -= len(pydash.uniq(oariOrthologsFamily))
                sscrCopyNumber -= len(pydash.uniq(sscrOrthologsFamily))
                btauCopyNumber -= len(pydash.uniq(btauOrthologsFamily))

                numBtau = 0
                numCjac = 0
                numCfam = 0
                numEcab = 0
                numFcat = 0
                numGgor = 0
                numMmul = 0
                numMmus = 0
                numOcun = 0
                numOari = 0
                numPtro = 0
                numRnor = 0
                numSscr = 0

                for ortholog in groupOrthologs:
                    orthologMatch = re.findall(r"(\D+)", ortholog)
                    if (orthologMatch[0] == 'ENSBTAP'):
                        numBtau += 1
                    elif (orthologMatch[0] == 'ENSCJAP'):
                        numCjac += 1
                    elif (orthologMatch[0] == 'ENSCAFP'):
                        numCfam += 1
                    elif (orthologMatch[0] == 'ENSECAP'):
                        numEcab += 1
                    elif (orthologMatch[0] == 'ENSFCAP'):
                        numFcat += 1
                    elif (orthologMatch[0] == 'ENSGGOP'):
                        numGgor += 1
                    elif (orthologMatch[0] == 'ENSMMUP'):
                        numMmul += 1
                    elif (orthologMatch[0] == 'ENSMUSP'):
                        numMmus += 1
                    elif (orthologMatch[0] == 'ENSOCUP'):
                        numOcun += 1
                    elif (orthologMatch[0] == 'ENSOARP'):
                        numOari += 1
                    elif (orthologMatch[0] == 'ENSPTRP'):
                        numPtro += 1
                    elif (orthologMatch[0] == 'ENSRNOP'):
                        numRnor += 1
                    elif (orthologMatch[0] == 'ENSSSCP'):
                        numSscr += 1
                numOneToOne = 0
                numDup = 0
                numNoOrtho = 0

                for count in [numBtau, numCjac, numCfam, numEcab, numFcat, numGgor, numMmul, numMmus, numOcun, numOari, numPtro, numRnor, numSscr]:
                    if count == 1:
                        numOneToOne += 1
                    elif count > 1:
                        numDup += 1
                    else:
                        numNoOrtho += 1

                for groupGene in groupGenes:
                    print(groupGene + '\t' + str(numOneToOne) + '\t' + str(numDup) + '\t' + str(numNoOrtho) + '\taffected\t' + name)
Beispiel #25
0
def convert_csv(path):
    ap = []
    result = ""

    with open(path) as csvfile:
        dialect = csv.Sniffer().sniff(csvfile.read(4096))
        dialect.doublequote = True
        csvfile.seek(0)
        reader = csv.reader(csvfile, dialect)
        header = False

        for row in reader:
            if not header:
                header = row
            else:
                item = {}
                for i in range(0, len(row)):
                    item[header[i]] = row[i]
                ap.append(item)

    domains = pydash.without(pydash.uniq(pydash.map_(ap, 'EA-Domain')), '', None)
    codelists = pydash.filter_(ap, {'EA-Type': 'ENUMERATION'})
    domains = list(set(domains) - set(pydash.map_(codelists.copy(), 'EA-Name')))
    domains.sort()
    final_domains = []
    final_datypes = []
    classes = pydash.filter_(ap, {'EA-Type': 'CLASS'}) + pydash.filter_(ap, {'EA-Type': 'DATATYPE'})
    datatypes = pydash.map_(pydash.filter_(ap, {'EA-Type': 'DATATYPE'}), 'EA-Name')
    classes_only = pydash.map_(pydash.filter_(ap, {'EA-Type': 'CLASS'}), 'EA-Name')
    attributes = pydash.filter_(ap, {'EA-Type': 'attribute'}) + pydash.filter_(ap, {'EA-Type': 'connector'})
    attributes = pydash.sort_by(attributes, 'EA-Domain')
    # for enumeration in codelists:
    #    attributes = pydash.remove(attributes, {'EA-Domain': enumeration})

    title = os.path.splitext(os.path.basename(path))[0]
    package = pydash.find(ap, {'EA-Type': 'Package'})

    if len(domains) > 0:
        for domain in domains:

            klassen = pydash.filter_(classes, {'EA-Name': domain})
            if 0 < len(klassen) <= 1:
                klasse = pydash.find(classes, {'EA-Name': domain})
                if klasse['EA-Type'] == 'DATATYPE':
                    result += "\n[%s]\n" % domain
                    final_datypes.append(domain)
                else:
                    result += "\n[%s]\n" % domain
                    final_domains.append(domain)

                if klasse is not None:
                    result += 'ap-definition-nl=%s\n' % klasse['ap-definition-nl']
                    result += 'ap-usagenote-nl=%s\n' % klasse['ap-usageNote-nl']
                    result += 'namespace=%s\n' % klasse['namespace']
                    result += 'localname=%s\n' % klasse['localname']


                domain_attributes = pydash.filter_(attributes, {'EA-Domain': domain})
                domain_attribute_names = pydash.without(pydash.uniq(pydash.map_(domain_attributes, 'EA-Name')), '', None) #localname

                result += 'attributes=%s\n' % ','.join(domain_attribute_names)

                for attr_name in domain_attribute_names:
                    result += "\n[%s:%s]\n" % (domain, attr_name)
                    attr = pydash.find(domain_attributes, {'EA-Name': attr_name})
                    if attr['range'] == "http://www.w3.org/2004/02/skos/core#Concept":
                        ap_codelist = pydash.find(codelists, {'EA-Name': attr['EA-Range']})
                        if not ap_codelist is None:
                            attr['ap-codelist'] = ap_codelist['ap-codelist']
                    for key in attr:
                        result += '%s=%s\n' % (key, attr[key].replace('&', '&amp;'))

            elif len(klassen) > 1:
                for klasse in klassen:
                    if klasse['ap-label-nl'] == "":
                        klasse['ap-label-nl'] = domain
                    if klasse['EA-Type'] == 'DATATYPE':
                        result += "\n[%s]\n" % klasse['ap-label-nl']
                        final_datypes.append(klasse['ap-label-nl'])
                    else:
                        result += "\n[%s]\n" % klasse['ap-label-nl']
                        final_domains.append(klasse['ap-label-nl'])
                    if klasse is not None:
                        result += 'ap-definition-nl=%s\n' % klasse['ap-definition-nl']
                        result += 'ap-usagenote-nl=%s\n' % klasse['ap-usageNote-nl']
                        result += 'namespace=%s\n' % klasse['namespace']
                        result += 'localname=%s\n' % klasse['localname']

                    domain_attributes = pydash.filter_(attributes,
                                                       {'EA-Domain-GUID': klasse['EA-GUID']})
                    domain_attribute_names = pydash.without(pydash.uniq(
                        pydash.map_(domain_attributes, 'localname')), '', None)

                    result += 'attributes=%s\n' % ','.join(
                        domain_attribute_names)

                    for attr_name in domain_attribute_names:
                        result += "\n[%s:%s]\n" % (klasse['ap-label-nl'], attr_name)
                        attr = pydash.find(domain_attributes,
                                           {'localname': attr_name})
                        if attr[
                            'range'] == "http://www.w3.org/2004/02/skos/core#Concept":
                            ap_codelist = pydash.find(codelists, {
                                'EA-Name': attr['EA-Range']})
                            if not ap_codelist is None:
                                attr['ap-codelist'] = ap_codelist[
                                    'ap-codelist']
                        for key in attr:
                            result += '%s=%s\n' % (key, attr[key])

        result += "\n[overview]\n"
        final_domains = list(set(final_domains))
        final_domains.sort()
        result += 'entities=%s\n' % ','.join(final_domains)
        result += 'dtypes=%s\n' % ','.join(final_datypes)
        if package is not None:
            result += 'package=%s\n' % package['EA-Name'].replace('OSLO-', '')
        result += 'title=%s\n' % title

    return [result, package['EA-Name'].replace('OSLO-', '')]