| 1 | """Collection of regular expressions to catch spectrum XML-tags.""" |
| 2 | import re |
| 3 | import regex |
| 4 | |
| 5 | SPECTRUM_INDEX_PATTERN = re.compile( |
| 6 | b'(?P<type>(scan=|nativeID="))(?P<nativeID>[0-9]*)">"' |
| 7 | b"(?P<offset>[0-9]*)</offset>" |
| 8 | ) |
| 9 | """ |
| 10 | Regex pattern for spectrum index |
| 11 | works for obo format 1.1.0 until <last version checked> |
| 12 | |
| 13 | Catches: |
| 14 | #. demo 1 |
| 15 | #. demo 2 |
| 16 | """ |
| 17 | |
| 18 | |
| 19 | SIM_INDEX_PATTERN = re.compile( |
| 20 | b'(?P<type>idRef=")(?P<nativeID>.*)">(?P<offset>[0-9]*)</offset>' |
| 21 | ) |
| 22 | """ |
| 23 | Regex pattern for SIM index |
| 24 | """ |
| 25 | SPECTRUM_PATTERN3 = regex.compile(r"((\w+)=(\w+\s*))+") |
| 26 | SPECTRUM_ID_PATTERN = re.compile(r'="{0,1}([0-9]*)"{0,1}>{0,1}$') |
| 27 | SPECTRUM_ID_PATTERN2 = re.compile(r"(scan|scanId)=(\d+)") |
| 28 | """ |
| 29 | Simplified spectrum id regex. Greedly catches ints at the end of line |
| 30 | """ |
| 31 | |
| 32 | FILE_ENCODING_PATTERN = re.compile(b'encoding="(?P<encoding>[A-Za-z0-9-]*)"') |
| 33 | """ |
| 34 | Regex to catch xml file encoding |
| 35 | """ |
| 36 | |
| 37 | MOBY_DICK_CHAPTER_PATTERN = re.compile(r"CHAPTER ([0-9]+).*") |
| 38 | """ |
| 39 | Regex to catch moby dick chapter number used in the index gezip writer example. |
| 40 | """ |
| 41 | SPECTRUM_OPEN_PATTERN = re.compile( |
| 42 | b'<*spectrum[^>]*(index|id)="(.*?)".*(index|id)="(.*?)"' |
| 43 | ) |
| 44 | """ |
| 45 | Regex to catch specturm open xml tag with encoded array length |
| 46 | """ |
| 47 | |
| 48 | SPECTRUM_OPEN_PATTERN_SIMPLE = re.compile(rb"<spectrum ") |
| 49 | SPECTRUM_ID_PATTERN_SIMPLE = re.compile(rb"<*spectrum[^>]*id=\"(?P<id>[^\"]+)\"") |
| 50 | SPECTRUM_DEFAULTARRY_PATTERN_SIMPLE = re.compile( |
| 51 | rb"<*spectrum[^>]*defaultArrayLength=\"[0-9]+\">" |
| 52 | ) |
| 53 | |
| 54 | CHROMO_OPEN_PATTERN = re.compile(b'<chromatogram\\s.*?id="(.*?)"') |
| 55 | |
| 56 | SPECTRUM_CLOSE_PATTERN = re.compile(b"</spectrum>") |
| 57 | """Regex to catch spectrum xml close tags""" |
| 58 | |
| 59 | CHROMATOGRAM_CLOSE_PATTERN = re.compile(b"</chromatogram>") |
| 60 | """Regex to catch spectrum xml close tags""" |
| 61 | |
| 62 | SPECTRUM_TAG_PATTERN = re.compile(r'<spectrum.*?id="(?P<index>[^"]+)".*?>') |
| 63 | """Regex to catch spectrum tag pattern""" |
| 64 | |
| 65 | CHROMATOGRAM_ID_PATTERN = re.compile(r'<chromatogram.*id="(.*?)".*?>') |
| 66 | """Regex to catch chromatogram id patterns""" |
| 67 | |
| 68 | CHROMATOGRAM_PATTERN = re.compile(r'<chromatogram.*id="(.*?)".*?>') |
| 69 | """Regex to catch chromatogram id pattern (again ?)""" |
| 70 | |
| 71 | CHROMATOGRAM_AND_SPECTRUM_PATTERN_WITH_ID = re.compile( |
| 72 | r"<\s*(chromatogram|spectrum)\s*(id=(\".*?\")|index=\".*?\")\s(id=(\".*?\"))*\s*.*\sdefaultArrayLength=\"[0-9]+\">" |
| 73 | ) |
| 74 | """Regex to catch combined chromatogram and spectrum patterns""" |
| 75 | |
| 76 | INDEX_LIST_OFFSET_PATTERN = re.compile( |
| 77 | b"<indexListOffset>(?P<indexListOffset>[0-9]*)</indexListOffset>" |
| 78 | ) |
| 79 | |
| 80 | CHROMATOGRAM_OFFSET_PATTERN = re.compile( |
| 81 | b'(?P<WTF>[nativeID|idRef])="TIC">(?P<offset>[0-9]*)</offset' |
| 82 | ) |