Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • xiangwulu
    Member
    • Apr 2014
    • 18

    a fast way to get human genome sequence by coordinate

    Hi all,

    I want to get a lot human genome fragments (more than 500 million of them) randomly.


    This is a partial work of the whole process. I have .sam result file from bowtie, with 10 million human genome reads alignment. I want to compare each query reads with the 'reference sequence it aligned to' from the sam file. The reference sequence I used is hg19.fa from UCSC. So I need to be able to get the sequence from hg19.fa (or chromosome files) by using the location in the sam file.


    e.g. with giving: chr4:35654-35695, i could get 42bp sequences:
    gtcttccagggtttttatatttttgggttttacacttaagt

    so far, i had 2 solutions:
    1. python script to fetch sequences from UCSC DAS server:


    2. using python script call ''samtools faidx'' command and return commnad output,
    from post:


    but, they are slow. samtools faidx is bit faster than getting it from DAS server, but still slow.

    so, is there any FAST way to do this? i have the seprate chromosome fasta files, and hg19.fa file.
    Last edited by xiangwulu; 04-15-2014, 08:26 AM.
  • swbarnes2
    Senior Member
    • May 2008
    • 910

    #2
    Doesn't the MD line tell you how the read differs from the genome? Wouldn't it be easier to use that and the sequence from the SAM line, so you don't have to look at another file at all?

    Comment

    • westerman
      Rick Westerman
      • Jun 2008
      • 1104

      #3
      How fast do you want it to be? 'samtools faidx', in my experience, is rather speedy but you are asking for a lot of data. As a test, using bash I tried fetching 100,000 genome coordinates (randomly generated asking for lengths from 50 to 100 bases on all chromosomes) via 'samtools faidx'. It took about 7 minutes wall-clock time and generated a 10 MB file. At that rate your desired 500 million would take ... hum, around 25 days and generate a 50GB file.

      If I do the 100,000 coordinates 100 at a time (i.e., 100 regions on the 'samtools faidx' command line thus avoiding having to start up samtools 100,000 times as opposed to only 1000 times) then the time remains the same. So I suspect that the delay is either samtool's efficiency or simply having to read the largish human genome.

      You might be able to cut that time down if you first separated your input into chromosomes and then did per-chromosome 'samtools faidx' in parallel -- assuming that your disks are fast enough. And/or you can use a RAM-disk to hold the genome file and the *.fai file.

      I doubt if doing a web fetch on 500 million fragments will be fast nor will make you popular with UCSC.

      jm's solution could also be feasible. No matter how you slice it taking 500 million of anything takes time.

      Comment

      • westerman
        Rick Westerman
        • Jun 2008
        • 1104

        #4
        swbarne's comment (use the MD line) was also something I was thinking about. But it takes more programming than using samtools directly.

        Comment

        • vivek_
          PhD Student
          • Jul 2012
          • 164

          #5
          System calls from within a scripting language will always add a lot of latency. Since you seem interested in using Python, I came across this module yesterday which might be applicable here



          Samtools provides a function "faidx" (FAsta InDeX), which creates a small flat index file ".fai" allowing for fast random access to any subsequence in the indexed fasta, while loading a minimal amount of the file in to memory.

          Pyfaidx provides an interface for creating and using this index for fast random access of DNA subsequences from huge fasta files in a "pythonic" manner. Indexing speed is comparable to samtools, and in some cases sequence retrieval is much faster (benchmark).

          Comment

          • dpryan
            Devon Ryan
            • Jul 2011
            • 3478

            #6
            If you need it to be quick then just read the genome into memory once and then iterate over things. That's how those of us who have written methylation callers (where you have to do this exact process) do things, since it gives the best performance.

            Anyway, as the others said, it's easier to just parse the MD string if it exists and is valid.

            Comment

            • swbarnes2
              Senior Member
              • May 2008
              • 910

              #7
              Originally posted by westerman View Post
              swbarne's comment (use the MD line) was also something I was thinking about. But it takes more programming than using samtools directly.
              In the 25 days it would take to use samtools faidx hundreds of millions of times, you could learn how to program well enough to parse the SAM entry.

              Comment

              • xiangwulu
                Member
                • Apr 2014
                • 18

                #8
                Originally posted by swbarnes2 View Post
                Doesn't the MD line tell you how the read differs from the genome? Wouldn't it be easier to use that and the sequence from the SAM line, so you don't have to look at another file at all?
                The MD tag in sam files tell something, but not enough. Also, some tools does not output MD tag in sam file, like blat, bfast.

                Comment

                • mdshw5
                  Junior Member
                  • Dec 2011
                  • 1

                  #9
                  Originally posted by vivek_ View Post
                  System calls from within a scripting language will always add a lot of latency. Since you seem interested in using Python, I came across this module yesterday which might be applicable here

                  https://github.com/mdshw5/pyfaidx
                  This is exactly right. System calls from a scripting language will be slow, and pyfaidx is quite a bit better than calls to samtools or pysam (see Table 1 in my pre-print for pyfaidx). However, dpryan's suggestion of using raw strings (or something close, like Biopython's Seq.IO) will always be the fastest option, at the expense of keeping track of your own substring indexes. If "fast enough" is okay, I would suggest using pyfaidx as it's extensively tested for correctness and has a reasonable API for working with your existing indexed fasta files efficiently.

                  However, I may be biased.

                  Comment

                  Latest Articles

                  Collapse

                  • SEQadmin2
                    Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                    by SEQadmin2



                    Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                    ...
                    07-09-2026, 11:10 AM
                  • SEQadmin2
                    Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                    by SEQadmin2



                    Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                    There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                    07-08-2026, 05:17 AM
                  • GATTACAT
                    Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                    by GATTACAT
                    Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                    07-01-2026, 11:43 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, 07-13-2026, 10:26 AM
                  0 responses
                  20 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-09-2026, 10:04 AM
                  0 responses
                  31 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-08-2026, 10:08 AM
                  0 responses
                  20 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-07-2026, 11:05 AM
                  0 responses
                  34 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...