Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem Bam to Fastq

    Hi
    I want to create 2 fastq file starting from bam allignment.
    I didi this:
    samtools view -F 8 acc.bam > new.bam
    java -jar ~/picard-tools-1.99/ValidateSamFile.jar INPUT=new.bam OUTPUT=foi.bam
    java -jar ~/picard-tools-1.99/SamToFastq.jar INPUT=foi.bam FASTQ=p_R1.fq SECOND_END_FASTQ=p_R2.fq VALIDATION_STRINGENCY=LENIENT


    This is the error:
    To get help, see http://picard.sourceforge.net/index.shtml#GettingHelp
    Exception in thread "main" net.sf.samtools.SAMFormatException: Error parsing text SAM file. Not enough fields; Line 1
    Line: ERROR: Read groups is empty
    at net.sf.samtools.SAMLineParser.reportFatalErrorParsingLine(SAMLineParser.java:420)
    at net.sf.samtools.SAMLineParser.parseLine(SAMLineParser.java:210)
    at net.sf.samtools.SAMTextReader$RecordIterator.parseLine(SAMTextReader.java:237)
    at net.sf.samtools.SAMTextReader$RecordIterator.next(SAMTextReader.java:225)
    at net.sf.samtools.SAMTextReader$RecordIterator.next(SAMTextReader.java:201)
    at net.sf.samtools.SAMFileReader$AssertableIterator.next(SAMFileReader.java:687)
    at net.sf.samtools.SAMFileReader$AssertableIterator.next(SAMFileReader.java:665)
    at net.sf.picard.sam.SamToFastq.doWork(SamToFastq.java:132)
    at net.sf.picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:177)
    at net.sf.picard.sam.SamToFastq.main(SamToFastq.java:121)


    How can resolve? Thanks in advance for your help!!

  • #2
    I have never done a direct BAM to fastq, but you could use samtools to get a SAM file from your BAM, and then use picard tools (SamtoFastq) for conversion. One important thing to remember is that the SAM file genearted when you use samtools, does not contain a header. Attach the header to your sam file and then picard tools should work fine.

    #bam to sam: samtools view in.bam > out.bam

    Add your header for the sam files (out.bam)

    eg:
    @HD VN:1.0 SO:unsorted
    @SQ SN:chr10 LN:135534747
    @SQ SN:chr11 LN:135006516
    @SQ SN:chr12 LN:133851895
    @SQ SN:chr13 LN:115169878
    @SQ SN:chr14 LN:107349540
    @SQ SN:chr15 LN:102531392
    @SQ SN:chr16 LN:90354753
    @SQ SN:chr17 LN:81195210
    @SQ SN:chr18 LN:78077248
    @SQ SN:chr19 LN:59128983
    @SQ SN:chr1 LN:249250621
    @SQ SN:chr20 LN:63025520
    @SQ SN:chr21 LN:48129895
    @SQ SN:chr22 LN:51304566
    @SQ SN:chr2 LN:243199373
    @SQ SN:chr3 LN:198022430
    @SQ SN:chr4 LN:191154276
    @SQ SN:chr5 LN:180915260
    @SQ SN:chr6 LN:171115067
    @SQ SN:chr7 LN:159138663
    @SQ SN:chr8 LN:146364022
    @SQ SN:chr9 LN:141213431
    @SQ SN:chrM LN:16571
    @SQ SN:chrX LN:155270560
    @SQ SN:chrY LN:59373566
    @PG ID:bowtie2 PN:bowtie2 VN:2.1.0

    New file: out.sam

    #sam to fastq: java -jar SamToFastq.jar I=out.sam F=out.fastq

    Comment


    • #3
      Originally posted by hypno View Post
      Hi
      I want to create 2 fastq file starting from bam allignment.
      I didi this:
      Code:
      samtools view -F 8 acc.bam > new.bam
      This command will output a SAM (text) file not a BAM file and that file will not have a header as akshaya.ramesh alread said. The default output mode for samtools view is SAM; to output to BAM you have to use the '-b' option; you can also use '-o' to define the output file instead of redirecting STDOUT:
      Code:
      samtools view -b -F 8 -o new.bam acc.bam
      new.bam now contains only those aligned reads whose mates did not align (that's what you want right, since you used the -F 8 flag?).
      Code:
      java -jar ~/picard-tools-1.99/ValidateSamFile.jar  INPUT=new.bam OUTPUT=foi.bam
      ValidateSamFile does not output a new bam file, it simply checks an existing file, leaves it unchanged and prints a report to STDOUT. Using the OUTPUT= option just redirects the report to an output file, in this case an output file named foi.bam.
      Code:
      java -jar ~/picard-tools-1.99/SamToFastq.jar  INPUT=foi.bam FASTQ=p_R1.fq SECOND_END_FASTQ=p_R2.fq VALIDATION_STRINGENCY=LENIENT
      Based on the comment immediately above you should now understand why this failed. The file 'foi.bam' is not a BAM (or SAM) file, it is simply the report output by ValidateSamFile.

      You should use:
      Code:
      java -jar ~/picard-tools-1.99/SamToFastq.jar  INPUT=new.bam FASTQ=p_R1.fq SECOND_END_FASTQ=p_R2.fq VALIDATION_STRINGENCY=LENIENT

      Comment

      Latest Articles

      Collapse

      • seqadmin
        Best Practices for Single-Cell Sequencing Analysis
        by seqadmin



        While isolating and preparing single cells for sequencing was historically the bottleneck, recent technological advancements have shifted the challenge to data analysis. This highlights the rapidly evolving nature of single-cell sequencing. The inherent complexity of single-cell analysis has intensified with the surge in data volume and the incorporation of diverse and more complex datasets. This article explores the challenges in analysis, examines common pitfalls, offers...
        06-06-2024, 07:15 AM
      • seqadmin
        Latest Developments in Precision Medicine
        by seqadmin



        Technological advances have led to drastic improvements in the field of precision medicine, enabling more personalized approaches to treatment. This article explores four leading groups that are overcoming many of the challenges of genomic profiling and precision medicine through their innovative platforms and technologies.

        Somatic Genomics
        “We have such a tremendous amount of genetic diversity that exists within each of us, and not just between us as individuals,”...
        05-24-2024, 01:16 PM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, 06-07-2024, 06:58 AM
      0 responses
      179 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 06-06-2024, 08:18 AM
      0 responses
      228 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 06-06-2024, 08:04 AM
      0 responses
      184 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 06-03-2024, 06:55 AM
      0 responses
      18 views
      0 likes
      Last Post seqadmin  
      Working...
      X