コード例 #1
0
ファイル: bamGeneration.py プロジェクト: jicheng-li/Scoring
def getFastqPath(archive,bam,fqExt,lane=None):
	"""
	Function : Given an archive path to sequencing and analysis results, and a BAM file, tries to find the path to the FASTQ file used to generate the BAM, using several assumptions.
	Args     : archive - str. Archive directory path or a archive name (sequencing run name). In the latter case, SequencingRuns.runPaths.getPubDir does the work.
						 bam - str. Bam file name (w/o directory path)
						 fqExt - str. File exension used for the FASTQ file (i.e. 'fastq', or 'fq').
	Returns  : str, or None.
	"""
	print("Looking for the FASTQ file that corresponds to BAM file {bam}.".format(bam=bam))
	if not os.path.dirname(archive):
		archive = runPaths.getPubPath(archive)
	fastqBasename = bam.rstrip(".gz")
	fastqBasename = fastqBasename.rstrip(".bam") + "." + fqExt
	fastqPath = os.path.join(archive,fastqBasename)
	print("Checking Path: {}".format(fastqPath))
	if os.path.exists(fastqPath):
		print("Found it.\n")
		return fastqPath

	fastqPathGz = fastqPath + ".gz"
	print("Checking Path: {}".format(fastqPathGz))
	if os.path.exists(fastqPathGz):
		print("Found it.\n")
		return fastqPathGz

	fastqPath = os.path.join(archive,lane,fastqBasename)
	print("Checking Path: {}".format(fastqPath))
	if os.path.exists(fastqPath):
		print("Found it.\n")
		return fastqPath

	fastqPathGz = fastqPath + ".gz"
	print("Checking Path: {}".format(fastqPathGz))
	if os.path.exists(fastqPathGz):
		print("Found it.\n")
		return fastqPathGz
	else:
		print("\n")
		return None