From 197cbc0eed0b3bc137e25a6545de744a339df80c Mon Sep 17 00:00:00 2001 From: Roman Sloutsky Date: Wed, 20 Sep 2017 17:04:50 -0400 Subject: [PATCH 1/2] Switched pysam.Samfile to pysam.AlignmentFile Samfile has been deprecated in favor of pysam.AlignmentFile. It's only kept for backwards compatibility. --- misopy/pe_utils.py | 2 +- misopy/run_events_analysis.py | 4 ++-- misopy/sam_utils.py | 2 +- misopy/sashimi_plot/plot_utils/plot_gene.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/misopy/pe_utils.py b/misopy/pe_utils.py index 029c1ce..1be8dd8 100644 --- a/misopy/pe_utils.py +++ b/misopy/pe_utils.py @@ -280,7 +280,7 @@ def compute_insert_len(bams_to_process, raise Exception, "Error: Insert length computation failed." # Load mapped BAM filename - mapped_bam = pysam.Samfile(mapped_bam_filename, "rb") + mapped_bam = pysam.AlignmentFile(mapped_bam_filename, "rb") ### ### TODO: Rewrite this so that you only pair reads within an interval ### diff --git a/misopy/run_events_analysis.py b/misopy/run_events_analysis.py index 9d1d4be..e6e28f6 100644 --- a/misopy/run_events_analysis.py +++ b/misopy/run_events_analysis.py @@ -92,7 +92,7 @@ def check_gff_and_bam(gff_dir, bam_filename, main_logger, %(bam_index_fname)) main_logger.warning("Are you sure your BAM file is indexed?") print "Checking if BAM has mixed read lengths..." - bam_file = pysam.Samfile(bam_filename, "rb") + bam_file = pysam.AlignmentFile(bam_filename, "rb") n = 0 seq_lens = {} for bam_read in bam_file: @@ -152,7 +152,7 @@ def check_gff_and_bam(gff_dir, bam_filename, main_logger, gff_starts_with_chr = True n += 1 # Read first few BAM reads chromosomes - bam_file = pysam.Samfile(bam_filename, "rb") + bam_file = pysam.AlignmentFile(bam_filename, "rb") bam_chroms = {} bam_starts_with_chr = False n = 0 diff --git a/misopy/sam_utils.py b/misopy/sam_utils.py index 83a34b2..7e0f8a5 100644 --- a/misopy/sam_utils.py +++ b/misopy/sam_utils.py @@ -146,7 +146,7 @@ def load_bam_reads(bam_filename, """ print "Loading BAM filename from: %s" %(bam_filename) bam_filename = os.path.abspath(os.path.expanduser(bam_filename)) - bamfile = pysam.Samfile(bam_filename, "rb", + bamfile = pysam.AlignmentFile(bam_filename, "rb", template=template) return bamfile diff --git a/misopy/sashimi_plot/plot_utils/plot_gene.py b/misopy/sashimi_plot/plot_utils/plot_gene.py index 542cae4..3572db1 100644 --- a/misopy/sashimi_plot/plot_utils/plot_gene.py +++ b/misopy/sashimi_plot/plot_utils/plot_gene.py @@ -45,7 +45,7 @@ def plot_density_single(settings, sample_label, Plot MISO events using BAM files and posterior distribution files. TODO: If comparison files are available, plot Bayes factors too. """ - bamfile = pysam.Samfile(bam_filename, 'rb') + bamfile = pysam.AlignmentFile(bam_filename, 'rb') try: subset_reads = bamfile.fetch(reference=chrom, start=tx_start,end=tx_end) except ValueError as e: From 251f3b259fcfc777affe6ffdce81c0113690b688 Mon Sep 17 00:00:00 2001 From: Roman Sloutsky Date: Wed, 20 Sep 2017 17:36:30 -0400 Subject: [PATCH 2/2] Fixed bug: miso --run crashed on bam_read.seq==None When an alignment file doesn't contain sequence information, read objects get initialized with read.seq=None (or however that happens in the C code under the hood). In this case len(bam_read.seq) raises an error. --- misopy/run_events_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misopy/run_events_analysis.py b/misopy/run_events_analysis.py index e6e28f6..e7003d6 100644 --- a/misopy/run_events_analysis.py +++ b/misopy/run_events_analysis.py @@ -99,7 +99,7 @@ def check_gff_and_bam(gff_dir, bam_filename, main_logger, # Check more of the reads for mixed read lengths if n >= (num_reads * 10): break - seq_lens[len(bam_read.seq)] = True + seq_lens[bam_read.query_alignment_length] = True n += 1 all_seq_lens = seq_lens.keys() if len(all_seq_lens) > 1: