@@ -713,6 +713,7 @@ public static function sequence_count_from_cache($rest_service_id, $sample_id_li
713
713
714
714
public static function object_count_from_cache ($ type , $ rest_service_id , $ sample_id_list = [])
715
715
{
716
+ // Search the appropriate cache based on type.
716
717
if ($ type == 'sequence ' ) {
717
718
$ l = SequenceCount::where ('rest_service_id ' , $ rest_service_id )->orderBy ('updated_at ' , 'desc ' )->take (1 )->get ();
718
719
} elseif ($ type == 'clone ' ) {
@@ -721,21 +722,27 @@ public static function object_count_from_cache($type, $rest_service_id, $sample_
721
722
$ l = CellCount::where ('rest_service_id ' , $ rest_service_id )->orderBy ('updated_at ' , 'desc ' )->take (1 )->get ();
722
723
}
723
724
725
+ // If we got no data, return
724
726
if (count ($ l ) == 0 ) {
725
727
return ;
726
728
}
727
729
730
+ // Get all of the object counts base on the type.
728
731
if ($ type == 'sequence ' ) {
729
732
$ all_object_counts = $ l [0 ]->sequence_counts ;
730
733
} elseif ($ type == 'clone ' ) {
731
734
$ all_object_counts = $ l [0 ]->clone_counts ;
732
735
} elseif ($ type == 'cell ' ) {
733
736
$ all_object_counts = $ l [0 ]->cell_counts ;
734
737
}
735
- //if (count($sample_id_list) == 0) {
736
- // return $all_sequence_counts;
737
- //}
738
+ // If our sample ID list is of 0 length, we are not filtering on any
739
+ // sample IDs and we therefore return the full list.
740
+ if (count ($ sample_id_list ) == 0 ) {
741
+ return $ all_object_counts ;
742
+ }
738
743
744
+ // If we get here, we need to could up the objects for only the
745
+ // samples in the cache that are provided in the sample_id_list.
739
746
$ object_counts = [];
740
747
foreach ($ sample_id_list as $ sample_id ) {
741
748
if (isset ($ all_object_counts [$ sample_id ])) {
@@ -754,7 +761,7 @@ public static function object_count($type, $sample_id_list_by_rs, $filters = [],
754
761
// clean filters
755
762
$ filters = self ::clean_filters ($ filters );
756
763
757
- // hack: use cached total counts if there are no sequence filters
764
+ // use cached total counts if there are no sequence filters
758
765
if (count ($ filters ) == 0 && $ use_cache_if_possible ) {
759
766
$ counts_by_rs = [];
760
767
foreach ($ sample_id_list_by_rs as $ rs_id => $ sample_id_list ) {
@@ -779,24 +786,27 @@ public static function object_count($type, $sample_id_list_by_rs, $filters = [],
779
786
// generate JSON query
780
787
$ service_filters ['repertoire_id ' ] = $ sample_id_list ;
781
788
789
+ // set up the facet query on repertoire_id
782
790
$ query_parameters = [];
783
791
$ query_parameters ['facets ' ] = 'repertoire_id ' ;
784
792
785
793
// prepare parameters for each service
786
794
$ t = [];
787
795
796
+ // Get the service info for the given service ID
788
797
$ rs = self ::find ($ rs_id );
789
798
$ t ['rs ' ] = $ rs ;
790
799
800
+ // Assign the query service endpoint based on the query type.
791
801
if ($ type == 'sequence ' ) {
792
802
$ t ['url ' ] = $ rs ->url . 'rearrangement ' ;
793
803
} elseif ($ type == 'clone ' ) {
794
804
$ t ['url ' ] = $ rs ->url . 'clone ' ;
795
805
} elseif ($ type == 'cell ' ) {
796
806
$ t ['url ' ] = $ rs ->url . 'cell ' ;
797
807
}
798
- //$t['url'] = $rs->url . 'rearrangement';
799
808
809
+ // Generate the JSON query based on the filters and parameters.
800
810
$ t ['params ' ] = self ::generate_json_query ($ service_filters , $ query_parameters , $ rs ->api_version );
801
811
$ t ['timeout ' ] = config ('ireceptor.service_request_timeout ' );
802
812
@@ -811,14 +821,18 @@ public static function object_count($type, $sample_id_list_by_rs, $filters = [],
811
821
foreach ($ response_list as $ response ) {
812
822
$ rest_service_id = $ response ['rs ' ]->id ;
813
823
824
+ // if it is an error make a note of it.
814
825
if ($ response ['status ' ] == 'error ' ) {
815
826
$ counts_by_rs [$ rest_service_id ]['samples ' ] = null ;
816
827
$ counts_by_rs [$ rest_service_id ]['error_type ' ] = $ response ['error_type ' ];
817
828
continue ;
818
829
}
819
830
831
+ // Get the facet count list for the response.
820
832
$ facet_list = data_get ($ response , 'data.Facet ' , []);
821
833
$ object_count = [];
834
+ // Iterate over the list and get a count for each repertoire, keyed
835
+ // on repertoire_id
822
836
foreach ($ facet_list as $ facet ) {
823
837
$ object_count [$ facet ->repertoire_id ] = $ facet ->count ;
824
838
}
@@ -831,12 +845,101 @@ public static function object_count($type, $sample_id_list_by_rs, $filters = [],
831
845
}
832
846
}
833
847
848
+ // Add the count list for this service to this services data.
834
849
$ counts_by_rs [$ rest_service_id ]['samples ' ] = $ object_count ;
835
850
}
836
851
837
852
return $ counts_by_rs ;
838
853
}
839
854
855
+ // $sample_id_list_by_rs: array of rest_service_id => [list of samples ids]
856
+ public static function object_list ($ type , $ sample_id_list_by_rs , $ filters = [], $ field ='' )
857
+ {
858
+ // Set up info that depends on the query type
859
+ if ($ type == 'sequence ' ) {
860
+ $ endpoint = 'rearrangement ' ;
861
+ $ airr_object = 'Rearrangement ' ;
862
+ } elseif ($ type == 'clone ' ) {
863
+ $ endpoint = 'clone ' ;
864
+ $ airr_object = 'Clone ' ;
865
+ } elseif ($ type == 'cell ' ) {
866
+ $ endpoint = 'cell ' ;
867
+ $ airr_object = 'Cell ' ;
868
+ } elseif ($ type == 'expression ' ) {
869
+ $ endpoint = 'expression ' ;
870
+ $ airr_object = 'CellExpression ' ;
871
+ } elseif ($ type == 'reactivity ' ) {
872
+ $ endpoint = 'reactivity ' ;
873
+ $ airr_object = 'Reactivity ' ;
874
+ } else {
875
+ Log::error ('RestService::object_list - Unexpected query type ' . $ type );
876
+ throw new \Exception ('Unexpected query type ' . $ type );
877
+ }
878
+
879
+ // clean filters
880
+ $ filters = self ::clean_filters ($ filters );
881
+
882
+ // prepare request parameters for each service
883
+ $ request_params = [];
884
+
885
+ foreach ($ sample_id_list_by_rs as $ rs_id => $ sample_id_list ) {
886
+ $ service_filters = $ filters ;
887
+
888
+ // force all sample ids to string
889
+ foreach ($ sample_id_list as $ k => $ v ) {
890
+ $ sample_id_list [$ k ] = (string ) $ v ;
891
+ }
892
+
893
+ // generate JSON query
894
+ $ service_filters ['repertoire_id ' ] = $ sample_id_list ;
895
+
896
+ $ query_parameters = [];
897
+ $ query_parameters ['facets ' ] = $ field ;
898
+
899
+ // prepare parameters for each service
900
+ $ t = [];
901
+
902
+ // Get the service information
903
+ $ rs = self ::find ($ rs_id );
904
+ $ t ['rs ' ] = $ rs ;
905
+
906
+ // Get the query URL based on the endpoint
907
+ $ t ['url ' ] = $ rs ->url . $ endpoint ;
908
+
909
+ $ t ['params ' ] = self ::generate_json_query ($ service_filters , $ query_parameters , $ rs ->api_version );
910
+ $ t ['timeout ' ] = config ('ireceptor.service_request_timeout ' );
911
+
912
+ $ request_params [] = $ t ;
913
+ }
914
+
915
+ // do requests
916
+ $ response_list = self ::doRequests ($ request_params );
917
+
918
+ // build list of sequence count for each sample grouped by repository id
919
+ $ objects_by_rs = [];
920
+ foreach ($ response_list as $ response ) {
921
+ $ rest_service_id = $ response ['rs ' ]->id ;
922
+
923
+ if ($ response ['status ' ] == 'error ' ) {
924
+ $ objects_by_rs [$ rest_service_id ]['samples ' ] = null ;
925
+ $ objects_by_rs [$ rest_service_id ]['error_type ' ] = $ response ['error_type ' ];
926
+ continue ;
927
+ }
928
+
929
+ $ object_response = data_get ($ response , 'data.Facet ' , []);
930
+ $ object_list = [];
931
+ foreach ($ object_response as $ object_data ) {
932
+ if ($ object_data ->count > 0 ) {
933
+ $ object_list [] = $ object_data ->$ field ;
934
+ }
935
+ }
936
+
937
+ $ objects_by_rs [$ rest_service_id ] = $ object_list ;
938
+ }
939
+
940
+ return $ objects_by_rs ;
941
+ }
942
+
840
943
// $sample_id_list_by_rs: array of rest_service_id => [list of samples ids]
841
944
/*
842
945
public static function sequence_count($sample_id_list_by_rs, $filters = [], $use_cache_if_possible = true)
@@ -1161,9 +1264,6 @@ public static function data_summary($filters, $username = '', $group_by_rest_ser
1161
1264
{
1162
1265
Log::debug ('RestService::data_summary() ' );
1163
1266
1164
- //Log::debug($filters);
1165
- //blah;
1166
-
1167
1267
// Build list of repository ids to query. For each enabled repository
1168
1268
// generate the internal key (ir_project_sample_id_list_). If that key
1169
1269
// is in the filters from the gateway, then we add it to the list of
@@ -1213,7 +1313,7 @@ public static function data_summary($filters, $username = '', $group_by_rest_ser
1213
1313
}
1214
1314
1215
1315
Log::debug ('Filtered to requested samples only: ' );
1216
- Log::debug ($ response_list_requested );
1316
+ // Log::debug($response_list_requested);
1217
1317
1218
1318
// Build list of data filters only (remove sample id filters)
1219
1319
$ data_filters = $ filters ;
@@ -1234,18 +1334,22 @@ public static function data_summary($filters, $username = '', $group_by_rest_ser
1234
1334
1235
1335
$ sample_id_list_by_rs [$ response ['rs ' ]->id ] = $ sample_id_list_requested ;
1236
1336
}
1337
+ //var_dump('<br/>');
1237
1338
//var_dump($sample_id_list_by_rs);
1339
+ //var_dump('<br/>');
1238
1340
//var_dump($data_filters);
1239
- //blah ;
1341
+ //var_dump('<br/>') ;
1240
1342
1241
1343
// count objects for each requested sample
1242
1344
if ($ type == 'sequence ' || $ type == 'clone ' || $ type == 'cell ' ) {
1243
1345
$ counts_by_rs = self ::object_count ($ type , $ sample_id_list_by_rs , $ data_filters );
1346
+ //$stuff = self::object_list($type, $sample_id_list_by_rs, $data_filters, 'cell_id');
1347
+ //var_dump($stuff);
1244
1348
} else {
1245
1349
Log::error ('Unexpected query type ' . $ type );
1246
1350
throw new \Exception ('Unexpected query type ' . $ type );
1247
1351
}
1248
- var_dump ($ counts_by_rs );
1352
+ // var_dump($counts_by_rs);
1249
1353
1250
1354
/*
1251
1355
if ($type == 'sequence') {
@@ -1389,11 +1493,15 @@ public static function data_subset($filters, $response_list_data_summary, $n = 1
1389
1493
} elseif ($ type == 'clone ' ) {
1390
1494
$ base_uri = 'clone ' ;
1391
1495
} else {
1392
- $ query_type = 'cell ' ;
1393
- if (isset ($ filters ['property_expression ' ])) {
1394
- $ query_type = 'expression ' ;
1395
- }
1396
- $ base_uri = $ query_type ;
1496
+ //$query_type = 'cell';
1497
+ //if (isset($filters['property_expression'])) {
1498
+ // $query_type = 'expression';
1499
+ //} elseif (isset($filters['peptide_sequence_aa_reactivity'])) {
1500
+ // $query_type = 'reactivity';
1501
+ //}
1502
+
1503
+ //$base_uri = $query_type;
1504
+ $ base_uri = 'cell ' ;
1397
1505
}
1398
1506
1399
1507
Log::debug ('We have reponses for repos with id: ' );
0 commit comments