def __init__(self, filename, doubled):
self.filename = filename
self.doubled = doubled
#determine if the file is bam or sam
self.filetype = os.path.splitext(self.filename)[1]
#throw an error if the file is not bam or sam
if self.filetype not in ['.bam']:
raise Exception("""You have provided a file with an extension other than
'.bam', please check your command-line arguments""")
#now make sure there is an index file for the bam file
if not os.path.exists("{}.bai".format(self.filename)):
raise Exception("""Your .bam file is there, but it isn't indexed and
there isn't a .bai file to go with it. Use
'samtools index <yourfile>.bam' to fix it.""")
#now open the file and just call it a sambam file
filetype_dict = {'.sam': '', '.bam': 'b'}
self.sambam = pysam.AlignmentFile(self.filename, "r{}".format(filetype_dict[self.filetype]))
self.seqlength = self.sambam.lengths[0]
self.true_seqlength = self.seqlength if not self.doubled else int(self.seqlength/2)
self.raw_depthmap = self.get_depthmap()
self.features = self.parse()
self.features.sort_values(by=['POS','MAPLEN'], ascending=[True, False] ,inplace=True)
self.features.reset_index(inplace=True)
self.features.drop('index', 1, inplace=True)
评论列表
文章目录