<commit_before>import {CancerStudyQueryUrlParams, normalizeQuery, QueryStore} from "./QueryStore";
import { MolecularProfile, SampleList } from "shared/api/generated/CBioPortalAPI";
import { AlterationTypeConstants } from "pages/resultsView/ResultsViewPageStore";
import * as _ from "lodash";
import { VirtualStudy } from "shared/model/VirtualStudy";

export type NonMolecularProfileQueryParams = Pick<CancerStudyQueryUrlParams,
    'cancer_study_id' | 'cancer_study_list' | 'Z_SCORE_THRESHOLD' | 'RPPA_SCORE_THRESHOLD' | 'data_priority' |
    'case_set_id' | 'case_ids' | 'gene_list' | 'geneset_list' | 'tab_index' | 'transpose_matrix' | 'Action' | 'profileFilter'>;

export type MolecularProfileQueryParams = Pick<CancerStudyQueryUrlParams,
    'genetic_profile_ids_PROFILE_MUTATION_EXTENDED' | 'genetic_profile_ids_PROFILE_COPY_NUMBER_ALTERATION' |
    'genetic_profile_ids_PROFILE_MRNA_EXPRESSION' | 'genetic_profile_ids_PROFILE_METHYLATION' |
    'genetic_profile_ids_PROFILE_PROTEIN_EXPRESSION' | 'genetic_profile_ids_PROFILE_GENESET_SCORE' |
    'genetic_profile_ids_PROFILE_GENERIC_ASSAY' >;


export function currentQueryParams(store:QueryStore) {
    let nonProfileParams = nonMolecularProfileParams(store);
    let profileParams = molecularProfileParams(store);
    return queryParams(nonProfileParams, profileParams);
}

export function queryParams(nonMolecularProfileParams:NonMolecularProfileQueryParams,
                            molecularProfileParams:MolecularProfileQueryParams) {
    let params:CancerStudyQueryUrlParams = Object.assign({}, nonMolecularProfileParams, molecularProfileParams);

    // Remove params with no value, because they may cause problems.
    // For example, the server will always transpose if transpose_matrix is present, no matter the value.
    for (let key in params) {
        if (!(params as any)[key]) {
            delete (params as any)[key];
        }
    }

    return {query:params};
}

export function nonMolecularProfileParams(store:QueryStore, whitespace_separated_case_ids?:string):NonMolecularProfileQueryParams {
    const selectableSelectedStudyIds = store.selectableSelectedStudyIds;

    // case ids is of format study1:sample1+study2:sample2+...
    const case_ids = whitespace_separated_case_ids ?
                    whitespace_separated_case_ids.replace(/\s+/g, '+') :
                    store.asyncCustomCaseSet.result.map(caseRow => (caseRow.studyId + ':' + caseRow.sampleId)).join('+');

    let ret:NonMolecularProfileQueryParams = {
        cancer_study_id: selectableSelectedStudyIds.length === 1 ? selectableSelectedStudyIds[0] : 'all',
        Z_SCORE_THRESHOLD: store.zScoreThreshold,
        RPPA_SCORE_THRESHOLD: store.rppaScoreThreshold,
        data_priority: store.dataTypePriorityCode,
        profileFilter: store.dataTypePriorityCode,
        case_set_id: store.selectedSampleListId || '-1', // empty string won't work<commit_msg>When composing queryParams in query store (for submission) don't delete undefined params<commit_after>import {CancerStudyQueryUrlParams, normalizeQuery, QueryStore} from "./QueryStore";
import { MolecularProfile, SampleList } from "shared/api/generated/CBioPortalAPI";
import { AlterationTypeConstants } from "pages/resultsView/ResultsViewPageStore";
import * as _ from "lodash";
import { VirtualStudy } from "shared/model/VirtualStudy";

export type NonMolecularProfileQueryParams = Pick<CancerStudyQueryUrlParams,
    'cancer_study_id' | 'cancer_study_list' | 'Z_SCORE_THRESHOLD' | 'RPPA_SCORE_THRESHOLD' | 'data_priority' |
    'case_set_id' | 'case_ids' | 'gene_list' | 'geneset_list' | 'tab_index' | 'transpose_matrix' | 'Action' | 'profileFilter'>;

export type MolecularProfileQueryParams = Pick<CancerStudyQueryUrlParams,
    'genetic_profile_ids_PROFILE_MUTATION_EXTENDED' | 'genetic_profile_ids_PROFILE_COPY_NUMBER_ALTERATION' |
    'genetic_profile_ids_PROFILE_MRNA_EXPRESSION' | 'genetic_profile_ids_PROFILE_METHYLATION' |
    'genetic_profile_ids_PROFILE_PROTEIN_EXPRESSION' | 'genetic_profile_ids_PROFILE_GENESET_SCORE' |
    'genetic_profile_ids_PROFILE_GENERIC_ASSAY' >;


export function currentQueryParams(store:QueryStore) {
    let nonProfileParams = nonMolecularProfileParams(store);
    let profileParams = molecularProfileParams(store);
    debugger;
    return queryParams(nonProfileParams, profileParams);
}

export function queryParams(nonMolecularProfileParams:NonMolecularProfileQueryParams,
                            molecularProfileParams:MolecularProfileQueryParams) {
    let params:CancerStudyQueryUrlParams = Object.assign({}, nonMolecularProfileParams, molecularProfileParams);

    // Remove params with no value, because they may cause problems.
    // For example, the server will always transpose if transpose_matrix is present, no matter the value.
    // for (let key in params) {
    //     if (!(params as any)[key]) {
    //         delete (params as any)[key];
    //     }
    // }

    return {query:params};
}

export function nonMolecularProfileParams(store:QueryStore, whitespace_separated_case_ids?:string):NonMolecularProfileQueryParams {
    const selectableSelectedStudyIds = store.selectableSelectedStudyIds;

    // case ids is of format study1:sample1+study2:sample2+...
    const case_ids = whitespace_separated_case_ids ?
                    whitespace_separated_case_ids.replace(/\s+/g, '+') :
                    store.asyncCustomCaseSet.result.map(caseRow => (caseRow.studyId + ':' + caseRow.sampleId)).join('+');

    let ret:NonMolecularProfileQueryParams = {
        cancer_study_id: selectableSelectedStudyIds.length === 1 ? selectableSelectedStudyIds[0] : 'all',
        Z_SCORE_THRESHOLD: store.zScoreThreshold,
        RPPA_SCORE_THRESHOLD: store.rppaScoreThreshold,
        data_priority: store.dataTypePriorityCode,
        profileFilter: store.dataTypePriorityCode,
        case_set_id: store.selectedSampleListId || '-1', // empty string won't work
{'fraction_non_alphanumeric': 0.09222484012117133, 'fraction_numerical': 0.0023561090541905083, 'mean_word_length': 4.943, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2004290', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1728, 'n_words': 319}