| 1084 | use polars::prelude::{DataFrame, NamedFrom, Series}; |
| 1085 | |
| 1086 | fn create_test_anndata() -> anyhow::Result<IMAnnData> { |
| 1087 | let rows: Vec<usize> = vec![ |
| 1088 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, |
| 1089 | 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
| 1090 | 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, |
| 1091 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, |
| 1092 | 9, 9, 9, 9, |
| 1093 | ]; |
| 1094 | |
| 1095 | let cols: Vec<usize> = vec![ |
| 1096 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, |
| 1097 | 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, |
| 1098 | 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
| 1099 | 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, |
| 1100 | 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
| 1101 | ]; |
| 1102 | |
| 1103 | let vals: Vec<f32> = vec![ |
| 1104 | 10.0, 10.2, 9.8, 10.5, 10.3, 9.7, 1.0, 1.2, 0.8, 1.1, 0.9, 1.3, 12.0, 11.8, 12.2, 11.5, |
| 1105 | 12.5, 11.7, 1.5, 1.7, 1.3, 1.6, 1.4, 1.8, 11.0, 11.3, 10.7, 11.2, 10.8, 11.4, 1.2, 1.1, |
| 1106 | 1.3, 0.9, 1.4, 1.0, 1.5, 1.3, 1.7, 1.4, 1.8, 1.2, 8.0, 8.2, 7.8, 8.5, 7.7, 8.3, 1.8, |
| 1107 | 1.6, 2.0, 1.5, 1.9, 1.7, 9.0, 8.8, 9.2, 8.7, 9.3, 8.9, 1.2, 1.4, 1.0, 1.3, 0.9, 1.1, |
| 1108 | 7.5, 7.7, 7.3, 7.8, 7.2, 7.9, 5.0, 5.2, 4.8, 5.1, 4.9, 5.3, 5.1, 4.9, 5.3, 4.7, 5.2, |
| 1109 | 5.0, 4.7, 4.5, 4.9, 4.6, 5.0, 4.8, 4.8, 5.0, 4.6, 4.9, 4.7, 5.1, 5.2, 5.0, 5.4, 4.8, |
| 1110 | 5.3, 5.1, 5.0, 5.2, 4.8, 5.3, 4.9, 5.1, 3.0, 3.2, 2.8, 3.1, 2.9, 3.3, 3.2, 2.8, 3.4, |
| 1111 | 2.9, 3.3, 3.1, |
| 1112 | ]; |
| 1113 | |
| 1114 | let coo = CooMatrix::try_from_triplets(10, 12, rows, cols, vals).unwrap(); |
| 1115 | let csr = CsrMatrix::from(&coo); |
| 1116 | |
| 1117 | let mut obs_df = DataFrame::default(); |
| 1118 | let names: Vec<String> = vec![ |
| 1119 | "c1".into(), |
| 1120 | "c2".into(), |
| 1121 | "c3".into(), |
| 1122 | "c4".into(), |
| 1123 | "c5".into(), |
| 1124 | "c6".into(), |
| 1125 | "c7".into(), |
| 1126 | "c8".into(), |
| 1127 | "c9".into(), |
| 1128 | "c10".into(), |
| 1129 | ]; |
| 1130 | let index_col = Series::new("index".into(), names.clone()); |
| 1131 | let group_labels = Series::new( |
| 1132 | "group".into(), |
| 1133 | vec!["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"], |
| 1134 | ); |
| 1135 | obs_df.with_column(index_col)?; |
| 1136 | obs_df.with_column(group_labels)?; |
| 1137 | |
| 1138 | let mut var_df = DataFrame::default(); |
| 1139 | let g_names: Vec<String> = vec![ |
| 1140 | "gene0".into(), |
| 1141 | "gene1".into(), |
| 1142 | "gene2".into(), |
| 1143 | "gene3".into(), |