Beispiel #1
0
def secondTests():
	writer= uWriter("","BEDGRAPH")
	bedParser = uParser("/home/local/USHERBROOKE/nora2001/Work/class/NGS_testing/data/BED/bedH2AZ.bed","BED")
	A = uBasicExp()
	A.load_with_parser(bedParser,0)
	A.write_with_writer(writer)
	C = uBasicExp()
	bedParser = uParser("/home/local/USHERBROOKE/nora2001/Work/class/NGS_testing/data/BED/bedH2AZ.bed","BED")
	C.load_with_parser(bedParser,0)
	C.removeChr("chr2")
	C.write_with_writer
	print "before anything"
	A.write_with_writer(writer)
	L=A.get_overlapping_from_exp(C)
	print "after get overlapping exp"
	L.write_with_writer(writer)
	L=A.get_overlapping_from_region("chr20",257180,257480)
	print "after get overlapping region"
	L.write_with_writer(writer)
	#Need to test
	#get_overlapping_from_chrom(self,chrom):
	print "reset"
	bedParser = uParser("/home/local/USHERBROOKE/nora2001/Work/class/NGS_testing/data/BED/bedH2AZ.bed","BED")
	A = uBasicExp()
	A.load_with_parser(bedParser,0)
	A.write_with_writer(writer)

	print "after removeDistinct"
	A.sort_sites()
	A.remove_distinct("chr20",250000, 257700)
	A.write_with_writer(writer)
	print "reset"
	bedParser = uParser("/home/local/USHERBROOKE/nora2001/Work/class/NGS_testing/data/BED/bedH2AZ.bed","BED")
	A = uBasicExp()
	A.load_with_parser(bedParser,0)
	print "after getDistinct"
	A.sort_sites()
	F=A.get_distinct("chr20",250000, 257700)
	print F.count()
	F.write_with_writer(writer)
	print "ChrCount", F.get_chr_count()
	print "Get subset no chrom"
	print A.get_subset_count("chr22",250000, 257700)
	deleteA= uBasic()
Beispiel #2
0
def ManyTests():
	print "--------------------------"
	print "TESTS: uBasicNGSChrom"
	print "--------------------------"
	print "**** Tests for constructor"
	print "No param:"
	chrom = uBasicChrom()
	print "chr: " + chrom.get_chr()
	print "chrSize: " + str(chrom.get_chrom_size())
	print "Chrom Name"
	chromName = uBasicChrom("chr5")
	print "chr: " + chromName.get_chr()
	print "chrSize: " + str(chromName.get_chrom_size())
	print "Chrom Name Size:"
	chromNameSize = uBasicChrom("chr3", 123456)
	print "chr: " + chromNameSize.get_chr()
	print "chrSize: " + str(chromNameSize.get_chrom_size())
	print "Chrom Size:"
	chrom_size = uBasicChrom(chromosomeSize=123456)
	print "chr: " + chrom_size.get_chr()
	print "chrSize: " + str(chrom_size.get_chrom_size())

	print ""
	print "**** Tests for get_copy"
	chromCopy = chromNameSize.get_copy()
	print "chr: " + chromCopy.get_chr()
	print "chrSize: " + str(chromCopy.get_chrom_size())

	print ""
	print "**** Tests for add_data functions"
	chromAddData = uBasicChrom("chr3")
	basicAddData = uBasic("chr3", 100, 200)
	chromAddData.add_data(basicAddData)
	print "chr: " + chromAddData.get_chr()
	print "chrSize: " + str(chromAddData.get_chrom_size())

	print ""
	print "**** Tests for infer_chr_size "
	chromInfer = uBasicChrom("chr3")
	chromInfer.add_data(uBasic("chr3", 1000, 3000))
	print "chrSize (before): " + str(chromInfer.get_chrom_size())
	chromInfer.infer_chr_size()
	print "chrSize (after): " + str(chromInfer.get_chrom_size())
	chromInfer = uBasicChrom()
	print "chrSize (empty):" + str(chromInfer.get_chrom_size())

	print ""
	print "**** Tests for the divide_items_into_n_bins function"
	chromDivide = uBasicChrom("chr4")
	chromDivide.add_data(uBasic("chr4", 1000, 3000))
	print "count (before): " + str(chromDivide.count())
	chromDivide.divide_items_into_n_bins(10, "IGNORE")
	print "count (after): " + str(chromDivide.count())

	print ""
	print "**** Tests for the divideItemsIntoBinofSize function"
	chromDivide = uBasicChrom("chr4")
	chromDivide.add_data(uBasic("chr4", 1000, 2000))
	print "count (before): " + str(chromDivide.count())
	chromDivide.divide_items_into_bin_of_size(20, "IGNORE")
	print "count (after): " + str(chromDivide.count())

	print ""
	print "**** Tests for the function getSite"
	chromGetSite = uBasicChrom("chr1")
	chromGetSite.add_data(uBasic("chr1", 300, 500))
	aSite = chromGetSite.get_site(0)
	print "getSite: chr: " + aSite.get_chr()
	print "getSite: start: " + str(aSite.get_start())
	print "getSite: end: " + str(aSite.get_end())

	print ""
	print "**** Tests for the statistic functions"
	chromStats = uBasicChrom("chrX")
	chromStats.add_data(uBasic("chrX", 300, 500))
	chromStats.add_data(uBasic("chrX", 300, 600))
	chromStats.add_data(uBasic("chrX", 400, 500))
	print "avg: " + str(chromStats.avg_site_size())
	print "min: " + str(chromStats.min_site_size())
	print "max: " + str(chromStats.max_site_size())
	print "sum: " + str(chromStats.sum_site_size())
	print "count: " + str(chromStats.count())

	print "**** Tests for adding random sites"

	chromAddRandom = uBasicChrom("chrY")
	chromAddRandom.set_chr_size(100000)
	chromAddRandom.add_random_sites(100, 10,10)
	print "Count: " + str(chromAddRandom.count())
	writer= uWriter("","BEDGRAPH")
	chromAddRandom.write_with_writer(writer)
	print ""
	print "**** Tests for get_overlapping/get_overlapping_count (other Chrom)"
	chromOverlap1 = uBasicChrom("chr1")
	chromOverlap1.add_data(uBasic("chr1", 100, 200))
	chromOverlap1.add_data(uBasic("chr1", 400, 800))
	chromOverlap1.add_data(uBasic("chr1", 1000, 1200))
	print "Different chrom:"
	chromOverlap2 = uBasicChrom("chr2")
	chromOverlap2.add_data(uBasic("chr2", 100, 200))
	chromOverlap2.add_data(uBasic("chr2", 400, 800))
	chromOverlap2.add_data(uBasic("chr2", 1000, 1200))
	chromOverlapResult = chromOverlap1.get_overlapping(chromOverlap2)
	print "Result Count: " + str(chromOverlapResult.count())
	print "get_overlapCount: " + str(chromOverlap1.get_overlapping_count(chromOverlap2))
	print "No overlap:"
	chromOverlap3 = uBasicChrom("chr1")
	chromOverlap3.add_data(uBasic("chr1", 1300, 1400))
	chromOverlap3.add_data(uBasic("chr1", 1400, 1800))
	chromOverlap3.add_data(uBasic("chr1", 11000, 11200))
	chromOverlapResult = chromOverlap1.get_overlapping(chromOverlap3)
	print "Result Count: " + str(chromOverlapResult.count())
	print "get_overlapCount: " + str(chromOverlap1.get_overlapping_count(chromOverlap3))
	print "Some overlap:"
	chromOverlap4 = uBasicChrom("chr1")
	chromOverlap4.add_data(uBasic("chr1", 100, 150))
	chromOverlap4.add_data(uBasic("chr1", 400, 900))
	chromOverlap4.add_data(uBasic("chr1", 11000, 11200))
	chromOverlapResult = chromOverlap1.get_overlapping(chromOverlap4)
	print "Result Count: " + str(chromOverlapResult.count())
	print "get_overlapCount: " + str(chromOverlap1.get_overlapping_count(chromOverlap4))
	print "All overlap: "
	chromOverlap5 = uBasicChrom("chr1")
	chromOverlap5.add_data(uBasic("chr1", 100, 200))
	chromOverlap5.add_data(uBasic("chr1", 400, 800))
	chromOverlap5.add_data(uBasic("chr1", 1000, 1200))
	chromOverlapResult = chromOverlap1.get_overlapping(chromOverlap5)
	print "Result Count: " + str(chromOverlapResult.count())
	print "get_overlapCount: " + str(chromOverlap1.get_overlapping_count(chromOverlap5))

	print ""
	print "**** Tests for get_overlapping/get_overlapping_count (basic)"
	chromBasicOverlap1 = uBasicChrom("chr2")
	chromBasicOverlap1.add_data(uBasic("chr2", 100, 200))
	chromBasicOverlap1.add_data(uBasic("chr2", 400, 800))
	chromBasicOverlap1.add_data(uBasic("chr2", 1000, 1200))
	print "chromBasicOverlap1.count(): " + str(chromBasicOverlap1.count())
	basicOverlap = uBasic("chr2", 50, 900)
	chromOverlapResult = chromBasicOverlap1.get_overlapping_basic(basicOverlap)
	print "Result Count: " + str(chromOverlapResult.count())
	print "get_overlapCount: " + str(chromBasicOverlap1.get_overlapping_count_basic(basicOverlap))
	aSite = chromOverlapResult.get_site(0)
	print "get_site: chr: " + aSite.get_chr()
	print "get_site: start: " + str(aSite.get_start())
	print "get_site: end: " + str(aSite.get_end())

	print ""
	print "**** Tests for get_overlapping/get_overlapping_count (region)"
	chromRegionOverlap1 = uBasicChrom("chr3")
	chromRegionOverlap1.add_data(uBasic("chr3", 100, 200))
	chromRegionOverlap1.add_data(uBasic("chr3", 400, 800))
	chromRegionOverlap1.add_data(uBasic("chr3", 1000, 1200))
	chromOverlapResult = chromRegionOverlap1.get_overlapping_region(50, 900)
	print "Result Count: " + str(chromOverlapResult.count())
	print "get_overlapCount: " + str(chromBasicOverlap1.get_overlapping_count_region(50, 900))

	print ""
	print "**** Tests for get_not_overlapping (other Chrom)"
	chromNotOverlap1 = uBasicChrom("chr1")
	chromNotOverlap1.add_data(uBasic("chr1", 100, 200))
	chromNotOverlap1.add_data(uBasic("chr1", 400, 800))
	chromNotOverlap1.add_data(uBasic("chr1", 1000, 1200))
	print "Different chrom:"
	chromNotOverlap2 = uBasicChrom("chr2")
	chromNotOverlap2.add_data(uBasic("chr2", 100, 200))
	chromNotOverlap2.add_data(uBasic("chr2", 400, 800))
	chromNotOverlap2.add_data(uBasic("chr2", 1000, 1200))
	chromNotOverlapResult = chromNotOverlap1.get_not_overlapping(chromNotOverlap2)
	print "Result Count: " + str(chromNotOverlapResult.count())
#	print "get_not_overlapCount: " + str(chromNotOverlap1.get_not_overlapping_count(chromNotOverlap2))
	print "No overlap:"
	chromNotOverlap3 = uBasicChrom("chr1")
	chromNotOverlap3.add_data(uBasic("chr1", 1300, 1400))
	chromNotOverlap3.add_data(uBasic("chr1", 1400, 1800))
	chromNotOverlap3.add_data(uBasic("chr1", 11000, 11200))
	chromNotOverlapResult = chromNotOverlap1.get_not_overlapping(chromNotOverlap3)
	print "Result Count: " + str(chromNotOverlapResult.count())
#	print "get_not_overlapCount: " + str(chromNotOverlap1.get_not_overlapping_count(chromNotOverlap3))
	print "Some overlap:"
	chromNotOverlap4 = uBasicChrom("chr1")
	chromNotOverlap4.add_data(uBasic("chr1", 100, 150))
	chromNotOverlap4.add_data(uBasic("chr1", 400, 900))
	chromNotOverlap4.add_data(uBasic("chr1", 11000, 11200))
	chromNotOverlapResult = chromNotOverlap1.get_not_overlapping(chromNotOverlap4)
	print "Result Count: " + str(chromNotOverlapResult.count())
#	print "get_overlapCount: " + str(chromNotOverlap1.get_not_overlapping_count(chromNotOverlap4))
	print "All overlap: "
	chromNotOverlap5 = uBasicChrom("chr1")
	chromNotOverlap5.add_data(uBasic("chr1", 100, 200))
	chromNotOverlap5.add_data(uBasic("chr1", 400, 800))
	chromNotOverlap5.add_data(uBasic("chr1", 1000, 1200))
	chromNotOverlapResult = chromNotOverlap1.get_not_overlapping(chromNotOverlap5)
	print "Result Count: " + str(chromNotOverlapResult.count())
Beispiel #3
0
def firstTests():
	from uBasicNGS_wrapper import uBasic
	from uParser_wrapper import uParser
	from uWriter_Wrapper import uWriter
	bedParser = uParser("/home/local/USHERBROOKE/nora2001/Work/class/NGS_testing/data/BED/bedH2AZ.bed","BED")
	print "Make empty BasicExp"
	A = uBasicExp()
	A.sort_sites()
	B= uBasic("chr2",100,200)
	print "Test is Chrom"
	if (A.is_chrom("chr1")==0):
		print "Chrom check ok"
	else:
		print A.is_chrom("chr1")
	print "Test count"	
	print A.count()
	print "Test add Data"	
	A.add_data_unit(B)
	A.add_data_unit(uBasic("chr2",50,100))
	print A.count()
	if (A.is_chrom("chr2")==1):
		print "Chrom check2 ok"
	if (A.is_chrom("chr1")==1):
		print "Chrom check fail"
	
	print "before sort"
	print A.is_sorted()
	print "Test Sort"
	A.sort_sites()
	print "after sort"
	print A.is_sorted()
	print "Test Load With Parser"
	A.load_with_parser(bedParser,5)
	print A.count()
	A.load_with_parser_path("/home/local/USHERBROOKE/nora2001/Work/class/NGS_testing/data/BED/bedH2AZ.bed","BED",3)
	print A.count()
	writer= uWriter("","BEDGRAPH")
	
	B= A.get_site("chr20",2)
	print B.get_chr(),B.get_start(),B.get_end()
	print A.count()
	A.removeChr("chr20")
	print A.count()
	A.write_with_writer(writer)
	A.sort_sites()
	C = A.find_preceding_site("chr2",0)
	print C
	C = A.find_next_site("chr2",600)
	print C
	print "----"
	A.remove_site("chr2",C)
	A.write_with_writer(writer)

	print "reloading"
	A.load_with_parser_path("/home/local/USHERBROOKE/nora2001/Work/class/NGS_testing/data/BED/bedH2AZ.bed","BED",0)
	print "before subset"
	A.sort_sites()
	A.write_with_writer(writer)
	
	#F = BasicExp()

	A.remove_subset("chr2",30,120)
	print "after subset"
	A.write_with_writer(writer)

	print "before setSize"
	print A.get_chr_size("chr2")
	print "after setSize"
	A.set_chr_size("chr2",22999)
	print A.get_chr_size("chr2")
	print "after infer"
	A.infer_chr_size()
	print A.get_chr_size("chr2")