|
| 1 | +#------------------------------------------------------------------------------- |
| 2 | +# Name: module1 |
| 3 | +# Purpose: |
| 4 | +# |
| 5 | +# Author: Eli |
| 6 | +# |
| 7 | +# Created: 14/04/2015 |
| 8 | +# Copyright: (c) Eli 2015 |
| 9 | +# Licence: <your licence> |
| 10 | +#------------------------------------------------------------------------------- |
| 11 | + |
| 12 | +def main(): |
| 13 | + pass |
| 14 | + |
| 15 | +if __name__ == '__main__': |
| 16 | + main() |
| 17 | + |
| 18 | +import sys |
| 19 | + |
| 20 | +#Read data |
| 21 | +f_in = open("C:/users/eli/downloads/ish/ish_ci.xml") |
| 22 | + |
| 23 | +#Print header row |
| 24 | +sys.stdout.write("gene" +"\t"+ "stage" +"\t"+ "tissue" +"\t"+ "pattern" +"\t"+ "original" +"\t"+ "source" +"\t"+ "exp" +"\t"+ "note" +'\n') |
| 25 | + |
| 26 | +#Set number of header rows to skip |
| 27 | +headers = 3 |
| 28 | +count = 1 |
| 29 | +source = False |
| 30 | + |
| 31 | +for line in f_in: |
| 32 | + |
| 33 | + #Skip specified number of header lines |
| 34 | + if count <= headers: |
| 35 | + count+=1 |
| 36 | + pass |
| 37 | + |
| 38 | + #Parse desired information |
| 39 | + else: |
| 40 | + if "experiment id" in line: |
| 41 | + exp = "NA" |
| 42 | + stage = "NA" |
| 43 | + stage_source = "NA" |
| 44 | + gene = "NA" |
| 45 | + tissue = "NA" |
| 46 | + note = "NA" |
| 47 | + pattern = "NA" |
| 48 | + original = "NA" |
| 49 | + exp = line.split('"')[1] |
| 50 | + if "developmental_stage" in line and source == False: |
| 51 | + stage = line.split(">")[1].split('<')[0] |
| 52 | + source = True |
| 53 | + |
| 54 | + if "developmental_stage" in line and source == True: |
| 55 | + stage_source = line.split(">")[1].split('<')[0] |
| 56 | + source = False |
| 57 | + |
| 58 | + if "probe_gene_predicted" in line: |
| 59 | + gene = line.split(">")[1].split('<')[0] |
| 60 | + |
| 61 | + if "staining_localization" in line: |
| 62 | + tissue = line.split(">")[1].split('<')[0] |
| 63 | + |
| 64 | + if "image_note" in line: |
| 65 | + note = line.split(">")[1].split('<')[0] |
| 66 | + if "Expression pattern:" in note: |
| 67 | + pattern = note.split("Expression pattern:")[1].split("<")[0] |
| 68 | + |
| 69 | + if "Original annotation:" in note: |
| 70 | + original = note.split("Original annotation:")[1].split(".")[0] |
| 71 | + |
| 72 | + else: |
| 73 | + pass |
| 74 | + |
| 75 | + #Output information for parsed record |
| 76 | + if "/experiment" in line: |
| 77 | + #results = [gene, stage, tissue, pattern, original, exp, note] |
| 78 | + output = "\t".join([gene, stage, tissue, pattern, original, stage_source, exp, note]) |
| 79 | + sys.stdout.write(output + '\n') |
0 commit comments