def make_predictions_csv_response(predictions, args): up = args.get_upstream() down = args.get_downstream() size = up + down + 1 if args.is_custom_ranges_list(): size = None separator = ',' if args.get_format() == 'tsv': separator = '\t' headers = ['Name', 'ID', 'Max', 'Chromosome', 'Start', 'End'] if args.is_custom_ranges_list(): headers = ['Chromosome', 'Start', 'End', 'Max'] if args.get_include_all(): if args.is_custom_ranges_list(): headers.append('Values') else: headers.extend([str(i) for i in range(-1*up, down+1)]) yield separator.join(headers) + '\n' for prediction in predictions: items = [] if args.is_custom_ranges_list(): items = [prediction['chrom'], str(prediction['start']), str(prediction['end']), str(prediction['max'])] else: start = prediction['start'] end = prediction['end'] items = [ prediction['commonName'], prediction['name'], str(prediction['max']), prediction['chrom'], str(start), str(end)] if args.get_include_all(): items.extend(get_all_values(prediction, size)) yield separator.join(items) + '\n'
def test_get_all_values_without_size(self): prediction = { 'start': 0, 'end': 5, 'values': [{ 'start': 1, 'value': 1.2 }] } expected = ['0', '1.2', '0', '0', '0'] self.assertEqual(expected, get_all_values(prediction, None))
def test_negative_values_guess_with_size(self): prediction = { 'start': 0, 'end': 5, 'values': [{ 'start': 1, 'value': -1.2 }] } expected = ['0', '-1.2', '0', '0', '0', '0'] self.assertEqual(expected, get_all_values(prediction, 6))
def make_download_custom_result(separator, include_all, predictions): headers = ['Name', 'Sequence', 'Max'] if include_all: headers.append('Values') yield separator.join(headers) + '\n' for prediction in predictions: items = [ prediction['name'], prediction['sequence'], str(prediction['max']) ] if include_all: items.extend(get_all_values(prediction, len(prediction['sequence']))) yield separator.join(items) + '\n'
def make_download_custom_result(separator, include_all, predictions): headers = ['Name', 'Sequence', 'Max'] if include_all: headers.append('Values') yield separator.join(headers) + '\n' for prediction in predictions: items = [ prediction['name'], prediction['sequence'], str(prediction['max']) ] if include_all: items.extend( get_all_values(prediction, len(prediction['sequence']))) yield separator.join(items) + '\n'
def test_overlap_most_extreem_value_wins(self): prediction = { 'start': 0, 'end': 5, 'values': [ { 'start': 1, 'value': 1.2 }, { 'start': 1, 'value': -1.3 }, ] } expected = ['0', '-1.3', '0', '0', '0'] self.assertEqual(expected, get_all_values(prediction, None))
def make_predictions_csv_response(predictions, args): up = args.get_upstream() down = args.get_downstream() size = up + down + 1 if args.is_custom_ranges_list(): size = None separator = ',' if args.get_format() == 'tsv': separator = '\t' headers = ['Name', 'ID', 'Max', 'Chromosome', 'Start', 'End'] if args.is_custom_ranges_list(): headers = ['Chromosome', 'Start', 'End', 'Max'] if args.get_include_all(): if args.is_custom_ranges_list(): headers.append('Values') else: headers.extend([str(i) for i in range(-1 * up, down + 1)]) yield separator.join(headers) + '\n' for prediction in predictions: items = [] if args.is_custom_ranges_list(): items = [ prediction['chrom'], str(prediction['start']), str(prediction['end']), str(prediction['max']) ] else: start = prediction['start'] end = prediction['end'] items = [ prediction['commonName'], prediction['name'], str(prediction['max']), prediction['chrom'], str(start), str(end) ] if args.get_include_all(): items.extend(get_all_values(prediction, size)) yield separator.join(items) + '\n'
def make_values(self, prediction): values = self.make_base_values(prediction) return values + get_all_values(prediction, self.size)