<commit_before>/*global define: false, confirm: true */
/*global require: false, module: false */

'use strict';

var domHelper = require("./dom_helper");
var xenaQuery = require("./xenaQuery");
var session = require("./session");
var _ = require("underscore");
var Rx = require("./rx");
var xenaAdmin = require("./xenaAdmin");
var {defaultLocal} = require('./defaults');

require("../css/datapages.css");

var showdown = require('showdown');  /* https://github.com/showdownjs/showdown */

var {activeHosts} = session;
var allHosts;

var queryString = domHelper.queryStringToJSON(),  	//parse current url to see if there is a query string
	COHORT_NULL = '(unassigned)',
	TYPE_NULL = 'genomicMatrix',
	NOT_GENOMICS = ["sampleMap", "probeMap", "genePred", "genePredExt"],
	FORMAT_MAPPING = {
		'clinicalMatrix': "ROWs (samples)  x  COLUMNs (identifiers) (i.e. clinicalMatrix)",
		'genomicMatrix': "ROWs (identifiers)  x  COLUMNs (samples) (i.e. genomicMatrix)",
		'mutationVector': "Variant by Position (i.e. mutationVector)",
		'genomicSegment': 'Genomic Segment (i.e. genomicSegment)',
		'unknown': "unknown"
	},
	denseMatrixType = ['genomicMatrix', 'clinicalMatrix'],
	treehouseImg = require('../images/Treehouse.jpg'),
	infoImgSource = require('../images/Info.png'),
	cohortMetaDataSource = "https://rawgit.com/ucscXena/cohortMetaData/master/";

const MAX_SAMPLES = 1000 * 1000;

function datasetList(servers, cohort) {
	return Rx.Observable.zipArray(
			_.map(servers, server => xenaQuery.datasetList(server, [cohort])
				.catch(() => Rx.Observable.of([]))
				.map(datasets => ({server, datasets})))
	);
}


// check if there is some genomic data for the cohort, if goodsStatus is a parameter, also check if the genomic data meet the status
function checkGenomicDataset(hosts, cohort, goodStatus) {
	return datasetList(hosts, cohort).map(function (s) {
		return s.some(function (r) {
			if (r.datasets) {
				return r.datasets.some(function (dataset) {
					var format = dataset.type,
						dataSubType = dataset.dataSubType,
						patt = /filter/i,
						status = dataset.status;
					return ((goodStatus ? (status === goodStatus) : true) &&
							(NOT_GENOMICS.indexOf(format) === -1) &&
							(dataSubType ? !(patt.test(dataSubType)) : true)
							);
				});
			}
			return false;
		});
	});
}

// check if there is some genomic data for the cohort, if goodsStatus is a parameter, also check if the genomic data meet the status
function checkGenomicDatasetAllBad(hosts, cohort, goodStatus) {
	return datasetList(hosts, cohort).map(function (s) {
		return s.every(function (r) {
			if (r.datasets && r.datasets.length > 0) {
				return r.datasets.some(function (dataset) {
					var format = dataset.type,
						dataSubType = dataset.dataSubType,
						patt = /filter/i,
						status = dataset.status;
					return ((goodStatus ? (status !== goodStatus) : false) ||
							(NOT_GENOMICS.indexOf(format) !== -1) ||
							(dataSubType ? patt.test(dataSubType) : false)
							);
				});
			}
			return true;
		});
	});
}

// test if a legit chort exits, (i.e. with real genomic data), carry out action
function ifCohortExistDo(cohort, hosts, goodStatus, action ) {
	checkGenomicDataset(hosts, cohort, goodStatus).subscribe(function (s) {
		if (s) {
			action.apply(null, arguments);
		}
	});
}
<commit_msg>bug fix: count the number of good cohort<commit_after>/*global define: false, confirm: true */
/*global require: false, module: false */

'use strict';

var domHelper = require("./dom_helper");
var xenaQuery = require("./xenaQuery");
var session = require("./session");
var _ = require("underscore");
var Rx = require("./rx");
var xenaAdmin = require("./xenaAdmin");
var {defaultLocal} = require('./defaults');

require("../css/datapages.css");

var showdown = require('showdown');  /* https://github.com/showdownjs/showdown */

var {activeHosts} = session;
var allHosts;

var queryString = domHelper.queryStringToJSON(),  	//parse current url to see if there is a query string
	COHORT_NULL = '(unassigned)',
	TYPE_NULL = 'genomicMatrix',
	NOT_GENOMICS = ["sampleMap", "probeMap", "genePred", "genePredExt"],
	FORMAT_MAPPING = {
		'clinicalMatrix': "ROWs (samples)  x  COLUMNs (identifiers) (i.e. clinicalMatrix)",
		'genomicMatrix': "ROWs (identifiers)  x  COLUMNs (samples) (i.e. genomicMatrix)",
		'mutationVector': "Variant by Position (i.e. mutationVector)",
		'genomicSegment': 'Genomic Segment (i.e. genomicSegment)',
		'unknown': "unknown"
	},
	denseMatrixType = ['genomicMatrix', 'clinicalMatrix'],
	treehouseImg = require('../images/Treehouse.jpg'),
	infoImgSource = require('../images/Info.png'),
	cohortMetaDataSource = "https://rawgit.com/ucscXena/cohortMetaData/master/";

const MAX_SAMPLES = 1000 * 1000;

function datasetList(servers, cohort) {
	return Rx.Observable.zipArray(
			_.map(servers, server => xenaQuery.datasetList(server, [cohort])
				.catch(() => Rx.Observable.of([]))
				.map(datasets => ({server, datasets})))
	);
}


// check if there is some genomic data for the cohort, if goodsStatus is a parameter, also check if the genomic data meet the status
function checkGenomicDataset(hosts, cohort, goodStatus) {
	return datasetList(hosts, cohort).map(function (s) {
		return s.some(function (r) {
			if (r.datasets) {
				return r.datasets.some(function (dataset) {
					var format = dataset.type,
						dataSubType = dataset.dataSubType,
						patt = /filter/i,
						status = dataset.status;
					return ((goodStatus ? (status === goodStatus) : true) &&
							(NOT_GENOMICS.indexOf(format) === -1) &&
							(dataSubType ? !(patt.test(dataSubType)) : true)
							);
				});
			}
			return false;
		});
	});
}

// check if there is some genomic data for the cohort, if goodsStatus is a parameter, also check if the genomic data meet the status
function checkGenomicDatasetAllBad(hosts, cohort, goodStatus) {
	return datasetList(hosts, cohort).map(function (s) {
		return s.every(function (r) {
			if (r.datasets && r.datasets.length > 0) {
				return r.datasets.every(function (dataset) {
					var format = dataset.type,
						dataSubType = dataset.dataSubType,
						patt = /filter/i,
						status = dataset.status;
					return ((goodStatus ? (status !== goodStatus) : false) ||
							(NOT_GENOMICS.indexOf(format) !== -1) ||
							(dataSubType ? patt.test(dataSubType) : false)
							);
				});
			}
			return true;
		});
	});
}

// test if a legit chort exits, (i.e. with real genomic data), carry out action
function ifCohortExistDo(cohort, hosts, goodStatus, action ) {
	checkGenomicDataset(hosts, cohort, goodStatus).subscribe(function (s) {
		if (s) {
			action.apply(null, arguments);
		}
	});
}

{'fraction_non_alphanumeric': 0.1531409678388939, 'fraction_numerical': 0.0033062819356777877, 'mean_word_length': 3.9369436201780417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, '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': '1948506', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2140, 'n_words': 553}