Pysam is a python module for reading and manipulating Samfiles. It's a lightweight wrapper of the samtools C-API. Pysam also includes an interface for tabix.
Questions tagged [pysam]
50 questions
0
votes
0 answers
How to install pysam
When I use conda install, and it succeed.But I enter python to test it, the code is import pysam, it show error,
Traceback (most recent call last):
File "", line 1, in
File "/root/anaconda3/lib/python3.8/site-packages/pysam/init.py", line 5, in…
0
votes
0 answers
Installing pysam for HTSeq - "PackagesNotFoundError: The following packages are not available from current channels:"
I am new to Python, Anaconda, and coding in general. I'm trying to install pysam. I need it to install HTSeq so that I can convert bam files to count files for a class project. Once they are count files, I plan to use edgeR for the rest of the data…

Emily
- 1
- 1
0
votes
0 answers
Wrong plotting data (insert size vs base quality means from BAM file)
I'am using PySam to calculate the insert reads and the mean base quality for the reads of a BAM as follows:
import math
import pysam
import numpy as np
import matplotlib.pyplot as plt
bam_file = pysam.AlignmentFile("mybam.bam",…

P. Solar
- 339
- 3
- 10
0
votes
0 answers
Cannot install pysam
I am attempting to install and use rmats2sashimiplot (https://github.com/Xinglab/rmats2sashimiplot) which requires several python dependencies installed as well. When trying to install pysam using pip, I am receiving the error "python setup.py…

Yvette Moreno
- 1
- 1
0
votes
0 answers
Bam file processing function code with parseargs in Python and Ubuntu
I am trying to adapt a piece of code to extract information for specific elements in bam files.
Here is what I have so far:
import pysam
import pandas as pd
import argparse
args = []
def parseargs(required_args=True):
class…

Laura
- 13
- 4
0
votes
2 answers
How to use pysam.view() to convert SAM to BAM
I would like to convert my SAM file to a BAM using pysam library. I am trying to write this command from samtools:
samtools view -S -b sample.sam > sample.bam
as a python code like this:
pysam.view("-S", "-b", "sample.sam", ">",…

twinsinc
- 123
- 2
- 11
0
votes
1 answer
How to add "OQ" tag with read quality score as additional field in the bam file using pysam
I need to add read quality with OQ tag as an additional field to the bam file using pysam.
Other conventional ways using samtools etc consume more time and create multiple files.
I tried with the given below script but end up unsigned character…

user3214212
- 43
- 5
0
votes
2 answers
extract lines from bam file
I have a bam file that looks like this:
samtools view pingpon.forward.bam | head
K00311:84:HYCNTBBXX:1:1123:2909:4215 0 LQNS02000001.1:55-552 214 28M * 0 0 TCTAGTTCAACTGTAAATCATCCTGCCC AAFFFJJJJJJJJJJJJJJJJJJJJJJJ AS:i:-6 XS:i:-6…

Amaranta_Remedios
- 763
- 4
- 15
0
votes
0 answers
Error inputting string into a pandas dataframe?
I'm trying to create a dataframe using outputs from the pysam module which is used on genomic data (Bam/Sam files). Pysam.depth() outputs a table as a string. I have used the module StringIO to try to parse the string into a pandas dataframe,…

Annie Forster
- 49
- 5
0
votes
2 answers
Can't install pysam with pip in Python 3.6
Macbook
Mac OSX 10.12.6
Python 3.6.2
cython 0.28.5
pip 18.0
I'm trying to install pysam:
pip3 install pysam
It keeps hitting an error at:
creating build/temp.macosx-10.6-intel-3.6/htslib/cram
htslib/cram/cram_io.c:63:10: fatal error:…

andbeonetraveler
- 693
- 3
- 11
- 25
0
votes
1 answer
Changing an orientation of a reverse sequence in the fasta file doesnt work
I am trying to get the reverse sequences orientated correctly in a file. This is the code:
import os
import sys import pysam
from Bio import SeqIO, Seq, SeqRecord
def main(in_file):
out_file = "%s.fa" % os.path.splitext(in_file)[0]
with…

Loki
- 99
- 6
0
votes
1 answer
Replace concatenation with join
I have code which is given below:
for pileupcolumn in samfile.pileup(max_depth = 1000000) :
X.append(pileupcolumn.n)
for pileupread in pileupcolumn.pileups:
if (pileupread.alignment.mapping_quality <= 15):
continue
…

Ammar Sabir Cheema
- 940
- 9
- 27
0
votes
1 answer
manually installing pysam error: "ImportError: No module named version"
I am trying to install pysam manually as I am working on a cluster without internet connection and I do not have admin rights (thus doing it through conda is not possible, which I have tried). I have downloaded all the zipped files from the…

Sergio.pv
- 1,380
- 4
- 14
- 23
0
votes
1 answer
Filter RDD in Spark using class attribute provided by pysam
I am using pysam, a python library, for reading BAM files within Spark. I created an RDD containing the "BAM" data. When I try to filter the data, using the attribute query_sequence of the class AlignedSegment(pysam library), then spark crashes.…

alexa
- 63
- 1
- 4
0
votes
2 answers
redirecting stdout to file
While using the pysam module I am trying to redirect stdout to a file as follows:
bam=sys.argv[1]
samfile = pysam.AlignmentFile(bam, "rb")
for alignment in samfile:
reverse=isReverse(alignment.flag)
if (reverse):
outfile =…

baron
- 1