Example #1
0
def test_init():

	scriptPath = os.path.realpath(__file__)
	dataPath = os.path.dirname(scriptPath) + "/../data/"

	g = get_switches.GetSwitches(dataPath + 'annotation.pklz')

	g._genes.flushSwitches()
	g.run(dataPath + "switches")

	# number of switches is correct
	assert len(g._genes.nodes()["ENSG00.5"]["switches"]) == 2
	assert len(g._genes.nodes()["ENSG03.3"]["switches"]) == 2
	assert len(g._genes.nodes()["ENSG05.2"]["switches"]) == 1
	assert len(g._genes.nodes()["ENSG09.6"]["switches"]) == 3

	# check the switches are the right ones
	assert [ x for x in g._genes.nodes()["ENSG00.5"]["switches"] if x.ctrl == "ENST01.2" and x.case == "ENST02.2" and x.samples == {"A","B","C"} ]
	assert [ x for x in g._genes.nodes()["ENSG00.5"]["switches"] if x.ctrl == "ENST02.2" and x.case == "ENST01.2" and x.samples == {"D"} ]
	assert [ x for x in g._genes.nodes()["ENSG03.3"]["switches"] if x.ctrl == "ENST06.1" and x.case == "ENST05.1" and x.samples == {"A","B"} ]
	assert [ x for x in g._genes.nodes()["ENSG03.3"]["switches"] if x.ctrl == "ENST05.1" and x.case == "ENST06.1" and x.samples == {"C","D"} ]
	assert [ x for x in g._genes.nodes()["ENSG05.2"]["switches"] if x.ctrl == "ENST08.1" and x.case == "ENST09.1" and x.samples == {"A","B"} ]
	assert [ x for x in g._genes.nodes()["ENSG09.6"]["switches"] if x.ctrl == "ENST15.1" and x.case == "ENST13.5" and x.samples == {"A","B","C","D"} ]
	assert [ x for x in g._genes.nodes()["ENSG09.6"]["switches"] if x.ctrl == "ENST16.2" and x.case == "ENST13.5" and x.samples == {"E","F","G"} ]
	assert [ x for x in g._genes.nodes()["ENSG09.6"]["switches"] if x.ctrl == "ENST16.2" and x.case == "ENST14.5" and x.samples == {"H","I"} ]
Example #2
0
def test_run():

    g = get_switches.GetSwitches(dataPath + 'annotation.pklz')

    g.run(dataPath + "switches")

    assert [x for x in g._genes.switches(g._txs)]
Example #3
0
def test_printSwitches():

	g = get_switches.GetSwitches(dataPath + 'annotation.pklz')
	g.run(dataPath + 'switches')

	io.printSwitches(g._genes, g._txs)

	switches = [ x for x in io.readTable("switches_spada.tsv") ]

	assert len(switches) == 8

	os.remove("switches_spada.tsv")
Example #4
0
def test_printSwitchesToGff():
	
	g = get_switches.GetSwitches(dataPath + 'annotation.pklz')
	g.run(dataPath + 'switches')

	io.printSwitchesToGff(g._genes, g._txs)

	for line in io.readGTF('switches_spada.gff', tag_sep = '='):

		if line['feature'] == 'mRNA':
			assert line['ID'] in g._txs.nodes()
			assert line['strand'] == g._txs[line['ID']]['strand']
		elif line['feature'] == 'exon':
			assert [line['start'], line['end']] in g._txs[line['Parent']]['exons']
			assert line['strand'] == g._txs[line['Parent']]['strand']
		elif line['feature'] == 'CDS':
			assert (line['start'], line['end']) == tuple(g._txs[line['Parent']]['CDS'])
			assert line['strand'] == g._txs[line['Parent']]['strand']
		elif line['feature'] == 'start_codon':
			if line['strand'] == '+':
				assert line['start'] ==  g._txs[line['Parent']]['start_codon']
			elif line['strand'] == '-':
				assert line['end'] ==  g._txs[line['Parent']]['start_codon']
			assert line['strand'] == g._txs[line['Parent']]['strand']
		elif line['feature'] in ('five_prime_UTR', 'three_prime_UTR'):
			pass
		elif line['feature'] == 'translated_nucleotide_match':
			parent = line['CDS_matches'].replace('cds_', '')
			assert line['strand'] == g._txs[parent]['strand']
			p = protein.Protein(parent, g._txs[parent])
			regions = p.getFeature(line['Note'], line['Alias'])
			gpos = map(lambda x: [ y.genomicPosition for y in x ], regions)
			bounds = [ (min(x), max(x)) for x in gpos ]

			assert (line['start'], line['end']) in bounds

	os.remove('switches_spada.gff')
Example #5
0
from spada.methods import get_switches, structural_analysis
from spada.io import io

import os
import pytest

scriptPath = os.path.realpath(__file__)
dataPath = os.path.dirname(scriptPath) + "/../../data/"
g = get_switches.GetSwitches(dataPath + 'annotation.pklz')
g._genes.flushSwitches()
g.run(dataPath + "switches")


def test_featureAnalysis():

    s = structural_analysis.StructuralAnalysis((g._genes, g._txs))
    s.featureAnalysis()

    # pfams
    pfam = [x for x in io.readTable("pfam_analysis.tsv")]
    assert len(pfam) == 8
    assert [
        x for x in pfam
        if x['Control_transcript'] == "ENST01.2" and x['Case_transcript'] ==
        "ENST02.2" and x['What'] == "Nothing" and x['Feature'] == "D1"
    ]
    assert [
        x for x in pfam
        if x['Control_transcript'] == "ENST01.2" and x['Case_transcript'] ==
        "ENST02.2" and x['What'] == "Lost_in_cases" and x['Feature'] == "D1"
    ]