SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
pybedtools - a Python wrapper for BEDTools daler Bioinformatics 7 09-30-2014 11:10 AM
bowtie wrapper script lh3 Bioinformatics 5 06-28-2012 11:27 AM
pysam IteratorSNPCall output different than the samtools mpileup aggp11 Genomic Resequencing 0 07-13-2011 10:25 AM
pysam pileup wierdness mbreese Bioinformatics 1 06-29-2011 12:04 PM
coverage by strand with pysam desaila Bioinformatics 1 10-15-2010 11:54 AM

Reply
 
Thread Tools
Old 07-06-2011, 01:37 PM   #21
aggp11
Member
 
Location: Wisconsin

Join Date: Jun 2011
Posts: 87
Default pysam not working from terminal

Hello,

I am a new pysam user. I installed pysam and it is running fine in the python interpreter but when I try to run a python script (*.py) from the command line it gives me the "pysam command not found error".

I am guessing this is something to do woth the installation. I can run samtools properly and like I said pysam is running fine in the interpreter. Could you help me with this?

Thanks a lot,

Praful
aggp11 is offline   Reply With Quote
Old 07-06-2011, 11:53 PM   #22
ffinkernagel
Senior Member
 
Location: Marburg, Germany

Join Date: Oct 2009
Posts: 110
Default

How are you trying to run the python script?
Usually you'd type 'python myscript.py', while the command not found error suggests
you're inputing 'pysam myscript.py' instead.
ffinkernagel is offline   Reply With Quote
Old 07-07-2011, 04:28 AM   #23
aggp11
Member
 
Location: Wisconsin

Join Date: Jun 2011
Posts: 87
Default

ffinkernagel

Thanks for your reply..

Actually I am trying to run the script as ./myscript.py. Also, the error comes when python tries to import pysam: "import pysam" ...
aggp11 is offline   Reply With Quote
Old 07-07-2011, 04:36 AM   #24
ffinkernagel
Senior Member
 
Location: Marburg, Germany

Join Date: Oct 2009
Posts: 110
Default

Then my magic glassball says, you're missing a correct shebang at the start of your file.
It should start with "#! /usr/bin/python" (or wherever your python executable is located. "Which python" will tell you what to place there).
In effect, it tells the system with which engine to run this script.

If python couldn't import the module, you'd get an "ImportError" (and a complet traceback), not a 'command not found'.
ffinkernagel is offline   Reply With Quote
Old 07-07-2011, 05:37 AM   #25
aggp11
Member
 
Location: Wisconsin

Join Date: Jun 2011
Posts: 87
Default

Ohh....I am sorry for the trouble...I just missed that line on top of the script...

Thanks a lot...
aggp11 is offline   Reply With Quote
Old 07-07-2011, 06:38 AM   #26
ffinkernagel
Senior Member
 
Location: Marburg, Germany

Join Date: Oct 2009
Posts: 110
Default

don't worry, glad to help!
ffinkernagel is offline   Reply With Quote
Old 03-16-2012, 03:59 PM   #27
vyellapa
Member
 
Location: phoenix

Join Date: Oct 2011
Posts: 59
Default

Im trying to a runs simple script to print reads that align to chr1 between 100 and 120 using pysam

Code:
import pysam
samfile=pysam.Samfile("sorted309.bam", "rb")
for alignedread in samfile.fetch('chr1', 100, 120):
	print alignedread
samfile.close()
However I'm getting an error:
code
Code:
dhcp-ws-10-55-120-36:programs vyellapantula$ python sampy.py 
Traceback (most recent call last):
  File "sampy.py", line 3, in <module>
    for alignedread in samfile.fetch('chr1', 100, 120):
  File "csamtools.pyx", line 771, in csamtools.Samfile.fetch (pysam/csamtools.c:8233)
  File "csamtools.pyx", line 702, in csamtools.Samfile._parseRegion (pysam/csamtools.c:7458)
ValueError: invalid reference `chr1`
Does this something to do with Tophat alignment output or is there something Im not doing right?

Last edited by vyellapa; 03-16-2012 at 04:03 PM.
vyellapa is offline   Reply With Quote
Old 03-16-2012, 04:15 PM   #28
Mr Mutundes
Member
 
Location: Sydney, Australia

Join Date: Jan 2009
Posts: 17
Default

Are you sure that the reference sequence name in the bam file is 'chr1' and not '1'? What is shown if you add a line to your script to print samfile.references?
Mr Mutundes is offline   Reply With Quote
Old 03-16-2012, 04:26 PM   #29
vyellapa
Member
 
Location: phoenix

Join Date: Oct 2011
Posts: 59
Default

It is indeed '1' and not 'chr1'.
vyellapa is offline   Reply With Quote
Old 06-07-2012, 01:20 AM   #30
arvid
Senior Member
 
Location: Berlin

Join Date: Jul 2011
Posts: 156
Default

I just noticed that pysam.Samfile.pileup() only gives me primary read alignments that overlap a given position, no secondary alignments. Is there a reason for this behaviour?

I do get all the read alignments in a certain region with pysam.Samfile.fetch(), but for my application I find the pileup engine more convenient.

Did I miss anything here, or is this an undocumented "feature"?
arvid is offline   Reply With Quote
Old 07-05-2012, 05:55 AM   #31
shwetaramdas
Junior Member
 
Location: USA

Join Date: Jul 2012
Posts: 1
Default

I was wondering if vyellappa's query was resolved? I'm getting the exact same error when I run another program that calls samtools.

Quote:
Traceback (most recent call last):
File "../conifer/conifer_v0.2/conifer.py", line 597, in <module>
args.func(args)
File "../conifer/conifer_v0.2/conifer.py", line 526, in CF_bam2RPKM
iter = f.fetch(p_chr,p_start,p_stop)
File "csamtools.pyx", line 771, in csamtools.Samfile.fetch (pysam/csamtools.c:8233)
File "csamtools.pyx", line 702, in csamtools.Samfile._parseRegion (pysam/csamtools.c:7458)
ValueError: invalid reference `chr1`
Thanks!
shwetaramdas is offline   Reply With Quote
Old 07-05-2012, 08:15 AM   #32
vyellapa
Member
 
Location: phoenix

Join Date: Oct 2011
Posts: 59
Default

I should have been clearer earlier.In sam fetch line:

Code:
samfile.fetch('chr1', 100, 120):
Replace 'chr1' with '1' if that's how its encoded in your bam.
vyellapa is offline   Reply With Quote
Old 03-06-2013, 04:34 AM   #33
syfo
Just a member
 
Location: Southern EU

Join Date: Nov 2012
Posts: 103
Default Different read numbers between samtools view -c and pysam fetch()

Any idea why pysam.Samfile and samtools don't see the same number of reads in a bam file?
Code:
samtools view -c file.bam
=> 355.610

Code:
python
>>> import pysam
>>> bam=pysam.Samfile("file.bam")
>>> N=0
>>> for read in bam.fetch(): N+=1
... 
>>> N
=> 329.366

Thanks in advance
syfo is offline   Reply With Quote
Old 03-06-2013, 05:24 AM   #34
syfo
Just a member
 
Location: Southern EU

Join Date: Nov 2012
Posts: 103
Default

Quote:
Originally Posted by syfo View Post
Any idea why pysam.Samfile and samtools don't see the same number of reads in a bam file?
Code:
samtools view -c file.bam
=> 355.610

Code:
python
>>> import pysam
>>> bam=pysam.Samfile("file.bam")
>>> N=0
>>> for read in bam.fetch(): N+=1
... 
>>> N
=> 329.366

Thanks in advance
Problem solved - no need to fetch:
Code:
for read in bam: N+=1
=> 355.610
syfo is offline   Reply With Quote
Old 12-16-2015, 10:32 AM   #35
Mat29
Junior Member
 
Location: Russia

Join Date: Mar 2015
Posts: 4
Default Can Pysam call variants on .sam files?

Can Pysam call variants on .sam files?
Mat29 is offline   Reply With Quote
Old 12-16-2015, 10:56 AM   #36
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480
Default

No, more or less everything needs a sorted BAM file. I assume you're the same person who asked this in various forms on biostars too. Why not just convert to a BAM file, sort and index it? That's not exactly difficult.
dpryan is offline   Reply With Quote
Old 01-28-2016, 02:13 AM   #37
Mat29
Junior Member
 
Location: Russia

Join Date: Mar 2015
Posts: 4
Default

Please tell how to compare 300 VCF files using PySAM or smth else and to generate nonshared unique SNPs?
Mat29 is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 09:35 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO