def __init__(self, genome_name="chM", sample_name="SAMP_CHM"): """ Empty databases prior to start :return: """ sync_test_data() db.fastqs.drop() db.mappings.drop() db.experiments.drop() db.gtfs.drop() mock_insert(sample_name, genome_name) gtfs.get_version_before = Mock(return_value=genome_name) encode.get_online_list = Mock( return_value=ex_mock.get_online_list(sample_name)) self.e_acc = sample_name self.gtf_ver = gtfs.get_version_before(datetime.datetime.now()) self.design_dir = os.path.join(config.results_root, "junctionseq", self.gtf_ver, self.e_acc) self.design_by_sample = os.path.join(self.design_dir, "decoder.bySample.txt") self.design_by_uid = os.path.join(self.design_dir, "decoder.byUID.txt") # Design files need to be generated inside the tests if os.path.exists(self.design_dir): print("Directory %s exists, removing ..." % self.design_dir) shutil.rmtree(self.design_dir)
def setUp(self): db.gtfs.drop() self.gtf_ver = gtfs.get_version_before(datetime.datetime.min) self.in_gtf = gtfs.version_to_path(gtf_ver=self.gtf_ver) self.in_gff = gtfs.version_to_path(gtf_ver=self.gtf_ver, gff=True) self.genome_dir = gtfs.get_genome_index_dir(self.gtf_ver) if os.path.exists(self.in_gff): os.remove(self.in_gff)
def test_count_bam(self): # Test counting functionality base on recieved data empty_and_create(in_dir=self.out_count_dir) in_gtf = gtfs.version_to_path(gtfs.get_version_before( datetime.MINYEAR)) in_bam = os.path.join(self.out_mapping_dir, mappings.STAR_BAM_NAME) mappings.count_bam(in_bam, in_gtf, self.out_count_dir, None) assert os.path.exists( os.path.join(self.out_count_dir, mappings.QORTS_COUNT_NAME))
def test_process_queue(self): # Insert data on fastqs into database in_gtf = gtfs.get_version_before(datetime.MINYEAR) out_bam = mappings.get_bam_file_paths(self.fastq_pair, in_gtf) assert out_bam is None # Assert correct insertion and directory creation lst = list( db.mappings.find({ "fastq_pair": self.fastq_pair, "gtf_ver": in_gtf, "status": "to map" })) assert len(lst) == 1 out_bam_dir = lst[0]["out_dir"] out_count_dir = lst[0]["out_count_dir"] empty_and_create(out_bam_dir) empty_and_create(out_count_dir) # Run mapping and counting jobs by the same process method; # first run is map, next run is count for upcoming_status in ["to count", "ready"]: mappings.process() lst = [] while len(lst) == 0: lst = list( db.mappings.find({ "fastq_pair": self.fastq_pair, "gtf_ver": in_gtf, "status": upcoming_status })) time.sleep(1) print("Current record", lst) # Check that results exist and paths are correct assert os.path.exists(os.path.join(out_bam_dir, mappings.STAR_BAM_NAME)) assert os.path.exists( os.path.join(out_count_dir, mappings.QORTS_COUNT_NAME)) # Assert read count is correctly written to database rec = lst[0] assert rec["read_count"] != -1
def setUp(self): self.gtf_ver = gtfs.get_version_before(datetime.datetime.now()) self.in_gtf = gtfs.version_to_path(self.gtf_ver)