当前位置: 首页>>代码示例>>Python>>正文


Python Tools.getChromosomeOfFile方法代码示例

本文整理汇总了Python中tools.Tools.getChromosomeOfFile方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.getChromosomeOfFile方法的具体用法?Python Tools.getChromosomeOfFile怎么用?Python Tools.getChromosomeOfFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tools.Tools的用法示例。


在下文中一共展示了Tools.getChromosomeOfFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: findFastqFiles

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getChromosomeOfFile [as 别名]
 def findFastqFiles(self, directory, inFormat):
     """The method findFastqFiles finds all fastq files recursively in a directory, from each directory with fastq files a sample is created.
     :param directory: the directory where the user hid his fastq files
     :type directory: str -- path to the directory
     
     """
     fastqFiles = []
     for fileName in os.listdir(directory):
         fileName = directory + "/" + fileName
         if os.path.isdir(fileName):
             self.findFastqFiles(fileName, inFormat)
         else:
             if inFormat == "bam":
                 if fileName.endswith(".bam") or fileName.endswith(".bam.gz"):
                     newSamp = Sample.Sample(self.pool, os.path.basename(os.path.splitext(fileName)[0]))
                     self.samples.append(newSamp)
                     newSamp.bam = BamFile.BamFile(self.pool, newSamp, fileName, sortedBam = True, headerLine = True, duplicates = False, mdTag = True, index = True)
                     self.pool.addSample(newSamp)
             elif inFormat == "fq":
                 if fileName.endswith(".fq") or fileName.endswith(".fq.gz"):
                     fastqFiles.append(fileName)
             elif inFormat == "vcf":
                 if fileName.endswith(".vcf") or fileName.endswith(".vcf.gz"):
                     if len(os.listdir(directory)) == 1:
                         chrom = None
                     else:
                         chrom = self.getChromosomeFromVcf(fileName)
                     self.pool.vcf[chrom] = VcfFile.VcfFile(self.pool, fileName, bcf=False, filtered=True, phased=True, chrom=chrom)
                 elif fileName.endswith(".bcf") or fileName.endswith(".bcf.gz"):
                     chrom = Tools.getChromosomeOfFile(Program.config.getPath("refGenome"), fileName)
                     self.pool.vcf[chrom] = VcfFile.VcfFile(self.pool, fileName, bcf=True, filtered=True, phased=True, chrom=chrom)
                     
     if inFormat == "bam" or inFormat =="vcf":
         return
     if len(fastqFiles) > 0:
         #create a library name from the file name
         libName = os.path.basename(fastqFiles[0])
         if libName.endswith("_1.fq") or libName.endswith("_2.fq"):
             libName = libName[:-5]
         if libName.endswith("_1.fq.gz") or libName.endswith("_2.fq.gz"):
             libName = libName[:-8]
         else:
             libName = libName[:-3]
             
         #create the sample
         sample = Sample.Sample(self.pool, libName)
         self.pool.addSample(sample)
         #add the fastq files to the sample
         if len(fastqFiles) == 1:
             sample.setForwardFq(fastqFiles[0])
         elif len(fastqFiles) == 2:
             sample.setForwardFq(fastqFiles[0])
             sample.setReversedFq(fastqFiles[1])
         elif len(fastqFiles) > 2:
             if fastqFiles[0].endswith("_1.fq"):
                 suffix = "_1.fq"
             elif fastqFiles[0].endswith("_1.fq.gz"):
                 suffix = "_1.fq.gz"
             else:
                 print("WARNING: files do not end with _1.fq or _1.fq.gz or _2.fq or _2.fq.gz, using all files in one directory as 1 sample with only forward reads")
                 suffix = fastqFiles[0][-3:]
                 #create a list of forward fastq files and one of reversed fastq files
                 forward = []
                 reversedFastq = []
                 for fastqFile in fastqFiles:
                     if fastqFile.endswith(suffix):
                         forward.append(fastqFile)
                     else:
                         reversedFastq.append(fastqFile)
                         
                 #Convert files to fastqFile objects
                 for i in range(len(forward)):
                     forward[i] = FastqFile.FastqFile(self.pool, sample, forward[i])
                 for i in range(len(reversedFastq)):
                     reversedFastq[i] = FastqFile.FastqFile(self.pool, sample, reversedFastq[i], forward=False)
                     
                 #add the fastq files to the sample
                 sample.forwardFq = forward
                 sample.reversedFq = reversedFastq
开发者ID:JJacobi13,项目名称:VLPB,代码行数:81,代码来源:main.py


注:本文中的tools.Tools.getChromosomeOfFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。