rcai commited on
Commit
42df4c2
·
verified ·
1 Parent(s): 1fd0231

Create test.py

Browse files
Files changed (1) hide show
  1. test.py +91 -0
test.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import re
3
+
4
+ # Example text extracted from the provided screenshot
5
+ llm_response = """
6
+ Table 1: Biomarker Results
7
+ Biomarker | Method | Result
8
+ --- | --- | ---
9
+ Microsatellite Instability (MSI) | NGS | Stable
10
+ Tumor Mutational Burden (TMB) | NGS | Low
11
+
12
+ Table 2: Gene Mutations
13
+ Gene | Method | Variant | Interpretation | Protein Alteration | Exon | DNA Alteration | Variant Frequency (%)
14
+ --- | --- | --- | --- | --- | --- | --- | ---
15
+ ARID1A | NGS | Mutated, Pathogenic | p.P227fs | | | 24 |
16
+ CDKN2A | NGS | Mutated, Pathogenic | p.W15* | | | 26 |
17
+ KRAS | NGS | Mutated, Pathogenic | p.G12D | | | 32 |
18
+ TP53 | NGS | Mutated, Pathogenic | p.Y163C | | | 29 |
19
+
20
+ Table 3: Other Findings
21
+ Biomarker | Result
22
+ --- | ---
23
+ MLH1 | Positive
24
+ PD-L1 | Negative
25
+ MSH2 | Positive
26
+ PMS2 | Positive
27
+ MSH6 | Positive
28
+
29
+ Table 4: Genes Tested Without Point Mutations or Indels
30
+ Genes | Tested
31
+ --- | ---
32
+ BRCA2 |
33
+ EGFR |
34
+ IDH1 |
35
+ KIT |
36
+ MET |
37
+ NRAS |
38
+ NTRK1 |
39
+ NTRK2 |
40
+ Neu |
41
+ NTRK3 |
42
+ ERBB2 |
43
+ ATM |
44
+ BRAF |
45
+ PDGFRA |
46
+ PIK3CA |
47
+ RET |
48
+ SMARCB1 |
49
+ """
50
+
51
+ # Function to parse tables from the response
52
+ def parse_tables(response_text):
53
+ tables = {}
54
+ current_table = []
55
+ current_table_name = None
56
+
57
+ for line in response_text.strip().split('\n'):
58
+ if line.startswith("Table"):
59
+ if current_table_name:
60
+ tables[current_table_name] = current_table
61
+ current_table_name = re.sub(r'Table \d+: ', '', line)
62
+ current_table = []
63
+ else:
64
+ current_table.append(line.strip())
65
+
66
+ if current_table_name:
67
+ tables[current_table_name] = current_table
68
+
69
+ return tables
70
+
71
+ # Function to convert parsed tables into DataFrames
72
+ def tables_to_dataframes(parsed_tables):
73
+ dataframes = {}
74
+ for table_name, lines in parsed_tables.items():
75
+ if len(lines) > 2:
76
+ headers = lines[1].split(" | ")
77
+ data = [row.split(" | ") for row in lines[2:]]
78
+ df = pd.DataFrame(data, columns=headers)
79
+ dataframes[table_name] = df
80
+ return dataframes
81
+
82
+ # Parse the tables
83
+ parsed_tables = parse_tables(llm_response)
84
+
85
+ # Convert tables to DataFrames
86
+ dataframes = tables_to_dataframes(parsed_tables)
87
+
88
+ # Display dataframes
89
+ for table_name, df in dataframes.items():
90
+ print(f"\n{table_name}:\n")
91
+ print(df)