Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • skbrimer
    Member
    • Mar 2014
    • 55

    Biopython blast parsing

    Hello all,

    I am currently trying to automate some of the work that I do for some in-house dsRNA viral sequencing. I'm pretty new to this but instead of re-inventing the wheel I'm using Biopython and so far it has work well following the tutorial. However my ultimate goal with this to be able to take my list of de novo contigs, BLAST them, pull the info I want from the blast into another flat file (csv) and be sort them into like groups.

    This is what I'm doing manually and it takes forever! I'm not even sure its the right way to go but it is working so I shouldn't complain. It would be a huge help to be able to put this list together automatically so I can spend more time in closing the sequences instead of the bulk of the time just trying to figure out what they are!

    So far my script is working (just on one of the contigs), I'm more confused on how to use the NCBIXML.parse() command

    Code:
      
    import sys
    from Bio import SeqIO
    from Bio.Blast import NCBIWWW
    from Bio.Blast import NCBIXML
    
    #this allows for any fasta file to be parsed using Biopython
    file_name =sys.argv[1]
    
    #reads in the list of cotigs
    handle = open(file_name, "rU")
    records = list(SeqIO.parse(handle,"fasta"))
    handle.close()
    
    #will blast the contigs
    results_handle = NCBIWWW.qblast("blastn", "nr", records[0].seq, hitlist_size = 1)
    #save_file = open("my_blast.xml","w")
    save_file = open("my_blast.text","w")
    save_file.write(results_handle.read())
    save_file.close()
    results_handle.close()
    
    #this section will be for the parsing and exporting of the 
    #data I'm looking for into a csv for easy sorting and visual inspection
    I would like the csv file to contain the Seqrecord.id, Hit_id, Hit_def, Hsp_query-from, HSP_query-to, Hsp_Hit-from, Hsp-Hit-to, Hsp_score

    Is this possible to do in a simple script? The only thing I want to keep from this is the csv at the end so I don't think I need to setup an actual db, am I correct?

    EDIT:: corrected the code to show that I'm trying to get this information from the xml file not the text file.
    Last edited by skbrimer; 12-02-2014, 11:50 AM.
  • maubp
    Peter (Biopython etc)
    • Jul 2009
    • 1544

    #2
    Given you want to make a CSV file, why mess about with XML? One of the best things in BLAST+ is the pick-your-own columns in tabular or CSV output.

    Comment

    • skbrimer
      Member
      • Mar 2014
      • 55

      #3
      Thanks for the advice Peter,

      To be able to do this would I find the documentation in Biopython or in NCBI? I ask because the output says I'm using the the current BLAST (2.2.30+) however in the Biopython documentation I have not found the where to do that, I'm sorry if this is a easy question but I'm very new to both programming and genomics and any guidance you could provide would be greatly appreciated.

      Sean

      Comment

      • maubp
        Peter (Biopython etc)
        • Jul 2009
        • 1544

        #4
        At the command line,
        Code:
        $ blastn -help
        ...
        You are looking for the -outfmt option, which can be simply a number, say 6 for tabular, or a quoted string like "6 std stitlesall" where you list the fields you want (std is shorthand for the default 12 columns).

        You can do this via the BLAST+ wrapper object in Biopython too, but be careful about the quotes - see https://www.biostars.org/p/95911/

        Comment

        • skbrimer
          Member
          • Mar 2014
          • 55

          #5
          Thank you Peter!

          I will work on getting this implimented. Since I do not have the command line BLAST tool on my machine... well right now at least, that is easy to fix. I will install it and see if I can get the output I'm looking for.

          Thank you again. I will let you know how this works.

          Sean

          Comment

          • skbrimer
            Member
            • Mar 2014
            • 55

            #6
            Hi Peter,

            I just waned to say that I feel this will work. I am having issues with the implementation of using both the BLAST tool and Biopython, however your suggestion to use the BLAST+ tool is the correct one.

            Thank you again,
            Sean

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              Nine Things a Sample Prep Scientist Thinks About Before Sequencing
              by SEQadmin2


              I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

              Here are nine questions we think about, in roughly the order they matter, before...
              06-18-2026, 07:11 AM
            • SEQadmin2
              From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
              by SEQadmin2


              Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


              The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
              ...
              06-02-2026, 10:05 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, 06-26-2026, 11:10 AM
            0 responses
            16 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 06-17-2026, 06:09 AM
            0 responses
            49 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 06-09-2026, 11:58 AM
            0 responses
            108 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 06-05-2026, 10:09 AM
            0 responses
            125 views
            0 reactions
            Last Post SEQadmin2  
            Working...