Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ~/devel/pyDev/biopy_multi_class.py
- # pastebin.com/wNRGXJeM
- # renamed the file: "HPA88HDJ016-Alignment.xml" to "blast_output.xml" and used it as the database being parsed.
- FILE_INPUT = open("blast_output.xml") # // set FILE_INPUT equal to the contents of blast_output.xml.
- MINIMUM_INT = 20 # // set MINIMUM_INT to 20 (threshold integer)
- from Bio.Blast import NCBIXML # // import the specialty module NCBXML from Bio.Blast.
- PARSE_FILE = NCBIXML.parse(FILE_INPUT) # // use the parse() function, from the NCBIXML module, on FILE_INPUT and set PARSE_FILE as the result. we now will use PARSE_FILE as our iterator.
- READ_LINE = PARSE_FILE.next() # // tells the PARSE_FILE iterator to use the next() method to parse each line into the READ_LINE variable.
- # though commented heavily, this script is fully executable. the intention of writing the script in this way was
- # so that various sections of the code could be commented and uncommented to show various results when executed.
- # it was my hope that writing a script in this fashion would help you determine the various data sets and how they
- # can be displayed and manipulated.
- """ [UNCOMMENT FOR EXECUTION]
- for READ_LINE in PARSE_FILE: # for each line in PARSE_FILE, begin to loop.
- for alignment in READ_LINE.alignments: # // for each alignment value in the alignments class, begin nested loop.
- for hsp in alignment.hsps: # // for each hsp value in the hsps class, begin the second nested loop.
- if hsp.identities > MINIMUM_INT: # // if the value of the each record's identities field is greater than MINIMUM_INT execute the following.
- print '\n***Seperator*** \n\n ALIGNMENT_TITLE: ', alignment.title
- print 'ALIGNMENT_LENGTH: ', alignment.length
- print 'HSP_SCORE: ', hsp.score
- print 'HSP_BITS: ', hsp.bits
- print 'HSP_EXPECT: ', hsp.expect
- print 'HSP_NUM_ALIGNMENTS: ', hsp.num_alignments
- print 'HSP_IDENTITIES: ', hsp.identities
- print 'HSP_POSITIVES: ', hsp.positives
- print 'HSP_GAPS: ', hsp.gaps
- print 'HSP_STRAND: ', hsp.strand
- print 'HSP_FRAME: ', hsp.frame
- print 'HSP_QUERY: ', hsp.query[0:75] + '...'
- print 'HSP_QUERY_START: ', hsp.query_start
- print 'HSP_MATCH: ', hsp.match[0:75] + '...'
- print 'HSP_SBJCT: ', hsp.sbjct[0:75] + '...'
- print 'HSP_SBJCT_START: ', hsp.sbjct_start
- [UNCOMMENT FOR EXECUTION] """
- """ [UNCOMMENT FOR EXECUTION]
- above is an example of how a parser could be written to parse and print each value contained in the HSP and Alignment classes.
- the snippet of code written below is one way to set 're-usable' variables for eash record parsed.
- while this is not necessary it may be helpful if trying to format the output.
- ALIGNMENT_TITLE = alignment.title
- ALIGNMENT_LENGTH = alignment.length
- HSP_SCORE = hsp.score
- HSP_BITS = hsp.bits
- HSP_EXPECT = hsp.expect
- HSP_NUM_ALIGNMENTS = hsp.num_alignments
- HSP_IDENTITIES = hsp.identities
- HSP_POSITIVES = hsp.positives
- HSP_GAPS = hsp.gaps
- HSP_STRAND = hsp.strand
- HSP_FRAME = hsp.frame
- HSP_QUERY = hsp.query
- HSP_QUERY_START = hsp.query_start
- HSP_MATCH = hsp.match
- HSP_SBJCT = hsp.sbjct
- HSP_SBJCT_START = hsp.sbjct_start
- [UNCOMMENT FOR EXECUTION] """
- """ [UNCOMMENT FOR EXECUTION]
- if you wanted to look inside another class contained in the database such as the description class,
- you could something like the function below.
- FILE_INPUT = open("blast_output.xml")
- MINIMUM_INT = 20
- from Bio.Blast import NCBIXML
- PARSE_FILE = NCBIXML.parse(FILE_INPUT)
- READ_LINE = PARSE_FILE.next()
- for READ_LINE in PARSE_FILE:
- for description in READ_LINE.descriptions: # // for loop through each line contained in the Description class.
- print '\n***Seperator***\n\nDESCRIPTION_TITLE: ', description.title # // seperator to show loop begining and end points, also print each description title.
- print 'DESCRIPTION_SCORE: ', description.score # // print the description's score.
- print 'DESCRIPTION_E: ', description.e # // print the description's E. Whatever that might be.
- print 'DESCRIPTION_NUM_ALIGNMENTS: ', description.num_alignments # // print description's num_alignments.
- DESC_TITLE = str(description.title) # // set DESC_TITLE equal to the description's title.
- DESC_SCORE = str(description.score) # // set DESC_SCORE equal to the description's score.
- DESC_E = str(description.e) # // set DESC_E equal to the description's E...
- DESC_NUM_ALIGN = str(description.num_alignments) # // set DESC_NUM_ALIGN equal to the description's num_alignments.
- [UNCOMMENT FOR EXECUTION]"""
Advertisement
Add Comment
Please, Sign In to add comment