<commit_before>'use strict';

var _ = require('../underscore_ext');
var xenaQuery = require('../xenaQuery');

// Hard-coded expression dataset
var expressionHost = 'https://toil.xenahubs.net';

var transcriptDataset = {
	host: 'https://reference.xenahubs.net',
	name: 'wgEncodeGencodeBasicV23'
};

var identity = x => x;

var fetchExpression = (transcripts, {studyA, subtypeA, studyB, subtypeB}) =>
	xenaQuery.transcriptExpression(expressionHost,
			_.pluck(transcripts, 'name'), studyA, subtypeA, studyB, subtypeB)
		.map(([expsA, expsB]) => _.mmap(expsA, expsB, transcripts,
					(expA, expB, transcript) => _.assoc(transcript, 'expA', expA, 'expB', expB)));

function fetchTranscripts(serverBus, params) {
	var {host, name} = transcriptDataset,
		query = xenaQuery.geneTranscripts(host, name, params.gene)
			.flatMap(transcripts =>
					fetchExpression(transcripts, params));

	serverBus.next(['geneTranscripts', query]);
}


var controls = {
	loadGene: (state, gene, studyA, subtypeA, studyB, subtypeB) =>
		_.updateIn(state, ['transcripts'], s => _.merge(s, {gene, studyA, subtypeA, studyB, subtypeB})),
	'loadGene-post!': (serverBus, state, newState) => {
		fetchTranscripts(serverBus, newState.transcripts);
	},
	'geneTranscripts':
		(state, transcripts) => _.assocIn(state, ['transcripts', 'genetranscripts'], transcripts)
};

module.exports = {<commit_msg>Fetch tissue subtypes.<commit_after>'use strict';

var _ = require('../underscore_ext');
var xenaQuery = require('../xenaQuery');

// Hard-coded expression dataset
var expressionHost = 'https://toil.xenahubs.net';

var transcriptDataset = {
	host: 'https://reference.xenahubs.net',
	name: 'wgEncodeGencodeBasicV23'
};

var identity = x => x;

var fetchExpression = (transcripts, {studyA, subtypeA, studyB, subtypeB}) =>
	xenaQuery.transcriptExpression(expressionHost,
			_.pluck(transcripts, 'name'), studyA, subtypeA, studyB, subtypeB)
		.map(([expsA, expsB]) => _.mmap(expsA, expsB, transcripts,
					(expA, expB, transcript) => _.assoc(transcript, 'expA', expA, 'expB', expB)));

function fetchTranscripts(serverBus, params) {
	var {host, name} = transcriptDataset,
		query = xenaQuery.geneTranscripts(host, name, params.gene)
			.flatMap(transcripts =>
					fetchExpression(transcripts, params));

	serverBus.next(['geneTranscripts', query]);
}

function filterSubtypes(subtypes) {
	var {'detailed_category': dc, '_primary_site': ps} = subtypes;

	return {
		tcga: dc.filter(identity), // filter out ""
		gtex: ps.filter(identity)
	};
}

function fetchSubtypes(serverBus) {
	serverBus.next(['transcriptSampleSubtypes',
				   xenaQuery.fieldCodes(expressionHost, 'TcgaTargetGTEX_phenotype.txt', ['detailed_category', '_primary_site'])
						.map(filterSubtypes)]);
}


var controls = {
	'init-post!': fetchSubtypes,
	loadGene: (state, gene, studyA, subtypeA, studyB, subtypeB) =>
		_.updateIn(state, ['transcripts'], s => _.merge(s, {gene, studyA, subtypeA, studyB, subtypeB})),
	'loadGene-post!': (serverBus, state, newState) => {
		fetchTranscripts(serverBus, newState.transcripts);
	},
	geneTranscripts:
		(state, transcripts) => _.assocIn(state, ['transcripts', 'genetranscripts'], transcripts),
	transcriptSampleSubtypes:
		(state, subtypes) => _.assocIn(state, ['transcripts', 'subtypes'], subtypes)
};

module.exports = {
{'fraction_non_alphanumeric': 0.1643420254699818, 'fraction_numerical': 0.001212856276531231, 'mean_word_length': 5.705284552845528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '4245230', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1109, 'n_words': 230}