I ran this commands:
samtools sort output.gfa1.onlymapped.sam -o output.gfa1.onlymapped.sorted.bam
samtools index output.gfa1.onlymapped.sorted.bam
samtools idxstats output.gfa1.onlymapped.sorted.bam | cut -f 1 | grep -v '*' | parallel -j 8 --bar 'samtools view -o {}.sam output.gfa1.onlymapped.sorted.sam {} && samtools fasta {}.sam > {}.fasta'
Unfortunately, all sam files are empty and no FASTA files have been generated. Please find below the log file:
[bam_sort_core] merging from 370 files and 1 in-memory blocks...
^M^M# 0 sec Backbone_8 ^M0^M0% 0:4947=0s Backbone_8 [main_samview] random alignment retrieval only works for indexed BAM or CRAM files.
...
99% 4946:1=0s Backbone_4947 [main_samview] random alignment retrieval only works for indexed BAM or CRAM files.
100% 4947:0=0s Backbone_4947
What did I miss?
Thank you in advance,
your code seems relatively* efficient, no idea why it would run 2 weeks. The only thing might be the file open overhead for writing each line. You can certainly avoid that by sorting the bam/sam file before hand (
samtools sort). This will sort all reads by alignment position and is a de facto standard required by many downstream programs anyway. After that, you can essentially open a new file once you see a new contig_name. Also look into thepysammodule, this might be helpful, too.*Edit: putting a bit more emphasis on relative, keeping Pierre's comment below in mind.
i'm not a python guy, but unless I'm wrong you're opening a new file (append mode) for every SAM record ? Opening a file costs a lot of I/O.