from has_read_groups import read_group_checks

if __name__ == "__main__":
	parser = argparse.ArgumentParser(description="Augment the bam list for a release with a prior existing version of the library")
	parser.add_argument("bam_list", help="Each line contains the parameters to build a library bam for release. This includes the library ID, the individual ID, experiment, read group description (sequencing run name with experiment type and udg treatment), experiment, and (bam, sequencing run date) pairs ")
	args = parser.parse_args()

	with open(args.bam_list) as f:
		library_parameters = [LibraryParameters(line) for line in f]

	for x in library_parameters:
		experiment = x.experiment
		if '1240k' in experiment:
			experiment = '1240k'
		search_directory = MT_default_dir if x.reference == 'rsrs' else library_default_dir
		existingBAM = getBamPath(x.library_id, experiment=experiment, reference=x.reference, version_policy='latest', shop_parent_directory=search_directory)
		bam = str(existingBAM)
		#print(bam)
		if len(bam) > 0:
			try: # this will match a new pipeline bam
				match = re.search('v([0-9]+).bam', bam)
				new_version = int(match.group(1)) + 1
				has_read_groups, has_real_library_name, date_string = read_group_checks(bam)
			except: # if the existing version is Shop's
				new_version = 1
				shop = ShopVersion(bam)
				date_string = shop.date_string
			#print('{}\t{}\t{:d}'.format(x.library_id, bam, new_version))
			x.version = new_version
			x.bam_filenames.append(str(existingBAM))
			x.bam_date_strings.append(date_string) # the bam date string is used for generating read groups, which the existing bam does not need
Example #2
0
	def testShopMT(self):
		expected = '/n/data1/hms/genetics/reich/1000Genomes/amh_samples/ancientMergeSets__MT/B-per_library_versions/S8861.E1.L1/MT.v0030.1__2018_08_08/merged/aln.sort.mapped.rmdupse_adna_v2.md.bam'
		found = getBamPath('S8861.E1.L1', MT_default_dir, default_bam_root, 'rsrs')
		self.assertEqual(expected, found)
Example #3
0
	def testPipelineMT(self):
		expected = '/n/groups/reich/matt/pipeline/released_libraries/S8861.E1.L2/S8861.E1.L2.1240k_plus.rsrs.v1.bam'
		found = str(getBamPath('S8861.E1.L2', '', '', 'rsrs'))
		self.assertEqual(expected, found)
Example #4
0
	def testShopNuclear(self):
		expected = '/n/data1/hms/genetics/reich/1000Genomes/amh_samples/ancientMergeSets__CAPTURE/B-per_library_versions/S8861.E1.L1/v0029.8__2018_03_01/merged/aln.sort.mapped.rmdupse_adna_v2.md.bam'
		found = getBamPath('S8861.E1.L1', library_default_dir, default_bam_root, 'hg19')
		self.assertEqual(expected, found)