<commit_before>'use strict';

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

// Hard-coded expression dataset
var expressionHost = 'https://toil.xenahubs.net';
var subtypeDataset = 'TCGA_GTEX_category.txt';
var subtypeField = 'TCGA_GTEX_main_category';

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 prefix = 4; // TCGA, GTEX
function filterSubtypes(subtypes) {
	var study = _.groupBy(subtypes[subtypeField], subtype => subtype.slice(0, prefix));

	return {
		tcga: study.TCGA,
		gtex: study.GTEX<commit_msg>Fix transcript expression query.<commit_after>'use strict';

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

// Hard-coded expression dataset
var expressionHost = 'https://toil.xenahubs.net';
var subtypeDataset = 'TCGA_GTEX_category.txt';
var subtypeField = 'TCGA_GTEX_main_category';

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

var identity = x => x;

var prefix = 4; // "TCGA", "GTEX"

// The transcriptExpression query is a bit wonky, because we're pulling the subtypes from TCGA_GTEX_main_category,
// but in transcriptExpression we filter on _sample_type. This assumes the two are kept in sync. It would be
// better to use the same field in both places, but first we need to confirm that it will work.
var fetchExpression = (transcripts, {studyA, subtypeA, studyB, subtypeB}) =>
	xenaQuery.transcriptExpression(expressionHost,
			// adding 1 for the space after the prefix
			_.pluck(transcripts, 'name'), studyA, subtypeA.slice(prefix + 1), studyB, subtypeB.slice(prefix + 1))
		.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 study = _.groupBy(subtypes[subtypeField], subtype => subtype.slice(0, prefix));

	return {
		tcga: study.TCGA,
		gtex: study.GTEX
{'fraction_non_alphanumeric': 0.13890808569454044, 'fraction_numerical': 0.0038009675190048375, 'mean_word_length': 5.19914346895075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7364971', 'n_tokens_mistral': 1051, 'n_tokens_neox': 948, 'n_words': 243}