<commit_before>import synapseclient
import pandas as pd
import mock
from nose.tools import assert_raises
import os
import sys
from genie.cna import cna

def test_processing():
	def createMockTable(dataframe):
		table = mock.create_autospec(synapseclient.table.CsvFileTable)
		table.asDataFrame.return_value= dataframe
		return(table)

	def table_query_results(*args):
		return(table_query_results_map[args])
	databaseMapping = pd.DataFrame(dict(Database=['bed'],
										Id=['syn8457748']))
	symbols = pd.DataFrame(dict(Hugo_Symbol=['AAK1','AAED1','AAAS','AAED1'],
								ID=['AAK1', 'AAED', 'AAAS','AAD']))
	#This is the gene positions that all bed dataframe will be processed against
	table_query_results_map = {
	("SELECT * FROM syn10967259",) : createMockTable(databaseMapping),
	("select Hugo_Symbol, ID from syn8457748 where CENTER = 'SAGE'",) : createMockTable(symbols),
	}   

	syn = mock.create_autospec(synapseclient.Synapse) 
	syn.tableQuery.side_effect=table_query_results

	cnaClass = cna(syn, "SAGE")
	order = ["Hugo_Symbol","Entrez_gene_id","Id1-1","Id2-1"]

	# expectedCnaDf = pd.DataFrame(dict(TUMOR_SAMPLE_BARCODE =['GENIE-SAGE-ID1-1', 'GENIE-SAGE-ID2-1'],
	# 								  CNAData =["AAED1,AAK1,AAAS\n1,2,0", "AAED1,AAK1,AAAS\n2,1,-1"],
	# 								  CENTER =['SAGE','SAGE'],
	# 								  unmappedData =[float('nan'),float('nan')]))
	expectedCnaDf = pd.DataFrame({"Hugo_Symbol":['AAED1', 'AAK1', 'AAAS'],
						  "GENIE-SAGE-Id1-1":[1, 2, 0],
						  "GENIE-SAGE-Id2-1":[2, 1, -1]})

	cnaDf = pd.DataFrame({"Hugo_Symbol":['AAED', 'AAK1', 'AAAS'],
						  "Entrez_gene_id":[0,0,0],
						  "Id1-1":[1, 2, 0],
						  "Id2-1":[2, 1, -1]})
	cnaDf = cnaDf[order]
	newCnaDf = cnaClass._process(cnaDf)
	assert expectedCnaDf.equals(newCnaDf[expectedCnaDf.columns])
	
	# expectedCnaDf = pd.DataFrame(dict(TUMOR_SAMPLE_BARCODE =['GENIE-SAGE-ID1-1',"GENIE-SAGE-ID2-1"],
	# 								  CNAData =["AAED1\n1","AAED1\n"],
	# 								  CENTER =['SAGE','SAGE'],
	# 								  unmappedData =["foo\n0","foo\n-1"]))
	order = ["Hugo_Symbol","Entrez_gene_id","GENIE-SAGE-Id1-1","GENIE-SAGE-Id2-1"]

	expectedCnaDf = pd.DataFrame({"Hugo_Symbol":['AAAS','AAED1'],
						  "GENIE-SAGE-Id1-1":['NA',1],
						  "GENIE-SAGE-Id2-1":['NA',2]})

	cnaDf = pd.DataFrame({"Hugo_Symbol":['AAED', 'AAED1', 'foo','AAAS','AAD'],
						  "Entrez_gene_id":[0,0,0,0,0],
						  "GENIE-SAGE-Id1-1":[1, 1, 0, float('nan'),1],
						  "GENIE-SAGE-Id2-1":[2, 0, -1, float('nan'),float('nan')]})
	cnaDf = cnaDf[order]
	newCnaDf = cnaClass._process(cnaDf)
	newCnaDf.reset_index(inplace=True,drop=True)
	pd.util.testing.assert_frame_equal(expectedCnaDf, newCnaDf[expectedCnaDf.columns])

def test_validation():
	def createMockTable(dataframe):
		table = mock.create_autospec(synapseclient.table.CsvFileTable)
		table.asDataFrame.return_value= dataframe
		return(table)

	def table_query_results(*args):
		return(table_query_results_map[args])<commit_msg>Start conversion of cna to pytest<commit_after>import synapseclient
import pandas as pd
import mock
from nose.tools import assert_raises
import os
import sys
from genie.cna import cna


def createMockTable(dataframe):
	table = mock.create_autospec(synapseclient.table.CsvFileTable)
	table.asDataFrame.return_value= dataframe
	return(table)

def table_query_results(*args):
	return(table_query_results_map[args])

database_mapping = pd.DataFrame(dict(Database=['bed'],
									Id=['syn8457748']))
symbols = pd.DataFrame(dict(Hugo_Symbol=['AAK1','AAED1','AAAS','AAED1'],
							ID=['AAK1', 'AAED', 'AAAS','AAD']))
#This is the gene positions that all bed dataframe will be processed against
table_query_results_map = {
("SELECT * FROM syn10967259",) : createMockTable(database_mapping),
("select Hugo_Symbol, ID from syn8457748 where CENTER = 'SAGE'",) : createMockTable(symbols),
}   

syn = mock.create_autospec(synapseclient.Synapse) 
syn.tableQuery.side_effect=table_query_results

cna_class = cna(syn, "SAGE")


def test_processing():

	order = ["Hugo_Symbol","Entrez_gene_id","Id1-1","Id2-1"]

	expected_cnadf = pd.DataFrame({"Hugo_Symbol":['AAED1', 'AAK1', 'AAAS'],
						  "GENIE-SAGE-Id1-1":[1, 2, 0],
						  "GENIE-SAGE-Id2-1":[2, 1, -1]})

	cnadf = pd.DataFrame({"Hugo_Symbol":['AAED', 'AAK1', 'AAAS'],
						  "Entrez_gene_id":[0,0,0],
						  "Id1-1":[1, 2, 0],
						  "Id2-1":[2, 1, -1]})
	cnadf = cnadf[order]
	new_cnaDf = cna_class._process(cnadf)
	assert expectedCnaDf.equals(newCnaDf[expected_cnadf.columns])
	
	# expectedCnaDf = pd.DataFrame(dict(TUMOR_SAMPLE_BARCODE =['GENIE-SAGE-ID1-1',"GENIE-SAGE-ID2-1"],
	# 								  CNAData =["AAED1\n1","AAED1\n"],
	# 								  CENTER =['SAGE','SAGE'],
	# 								  unmappedData =["foo\n0","foo\n-1"]))
	order = ["Hugo_Symbol","Entrez_gene_id","GENIE-SAGE-Id1-1","GENIE-SAGE-Id2-1"]

	expectedCnaDf = pd.DataFrame({"Hugo_Symbol":['AAAS','AAED1'],
						  "GENIE-SAGE-Id1-1":['NA',1],
						  "GENIE-SAGE-Id2-1":['NA',2]})

	cnaDf = pd.DataFrame({"Hugo_Symbol":['AAED', 'AAED1', 'foo','AAAS','AAD'],
						  "Entrez_gene_id":[0,0,0,0,0],
						  "GENIE-SAGE-Id1-1":[1, 1, 0, float('nan'),1],
						  "GENIE-SAGE-Id2-1":[2, 0, -1, float('nan'),float('nan')]})
	cnaDf = cnaDf[order]
	newCnaDf = cnaClass._process(cnaDf)
	newCnaDf.reset_index(inplace=True,drop=True)
	pd.util.testing.assert_frame_equal(expectedCnaDf, newCnaDf[expectedCnaDf.columns])

def test_validation():
	def createMockTable(dataframe):
		table = mock.create_autospec(synapseclient.table.CsvFileTable)
		table.asDataFrame.return_value= dataframe
		return(table)

	def table_query_results(*args):
		return(table_query_results_map[args])
{'fraction_non_alphanumeric': 0.18263205013428827, 'fraction_numerical': 0.03581020590868397, 'mean_word_length': 4.974331550802139, 'pattern_counts': {'":': 28, '<': 3, '<?xml version=': 0, '>': 3, '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': '4475575', 'n_tokens_mistral': 2643, 'n_tokens_neox': 2316, 'n_words': 313}