Mercurial > repos > lain > xseekerpreparator
comparison XSeekerPreparator.R @ 12:bdb2878ee189 draft
" master branch Updating"
author | lain |
---|---|
date | Wed, 07 Apr 2021 13:05:36 +0000 |
parents | f4fc4a0f41e2 |
children | 26f01380145d |
comparison
equal
deleted
inserted
replaced
11:f4fc4a0f41e2 | 12:bdb2878ee189 |
---|---|
482 context$groupidx <- rdata$xa@xcmsSet@groupidx | 482 context$groupidx <- rdata$xa@xcmsSet@groupidx |
483 xcms_set <- rdata$xa@xcmsSet | 483 xcms_set <- rdata$xa@xcmsSet |
484 singlefile <- rdata$singlefile | 484 singlefile <- rdata$singlefile |
485 process_arg_list <- rdata$listOFlistArguments | 485 process_arg_list <- rdata$listOFlistArguments |
486 var_meta <- rdata$variableMetadata | 486 var_meta <- rdata$variableMetadata |
487 ## We needed to get rid of the rdata, which is very big. | |
488 ## So we gathered all variable assignment from rdata here, and got rid of it. | |
489 rm(rdata) | |
490 | 487 |
491 process_params <- list() | 488 process_params <- list() |
492 for (list_name in names(process_arg_list)) { | 489 if (is.null(process_arg_list)) { |
493 param_list <- list() | 490 histories <- list() |
494 for (param_name in names(process_arg_list[[list_name]])) { | 491 for (history in xcms_set@.processHistory) { |
495 param_list[[param_name]] <- process_arg_list[[list_name]][[param_name]] | 492 if ( |
496 } | 493 class(history@param) == "CentWaveParam" |
497 process_params[[length(process_params)+1]] <- param_list | 494 && history@type == "Peak detection" |
498 } | 495 ) { |
496 params <- history@param | |
497 process_params <- list(list( | |
498 xfunction="annotatediff", | |
499 ppm=params@ppm, | |
500 peakwidth=sprintf("%s - %s", params@peakwidth[[1]], params@peakwidth[[2]]), | |
501 snthresh=params@snthresh, | |
502 prefilterStep=params@prefilter[[1]], | |
503 prefilterLevel=params@prefilter[[2]], | |
504 mzdiff=params@mzdiff, | |
505 fitgauss=params@fitgauss, | |
506 noise=params@noise, | |
507 mzCenterFun=params@mzCenterFun, | |
508 integrate=params@integrate, | |
509 firstBaselineCheck=params@firstBaselineCheck, | |
510 snthreshIsoROIs=!identical(params@roiScales, numeric(0)) | |
511 )) | |
512 break | |
513 } | |
514 } | |
515 } else { | |
516 for (list_name in names(process_arg_list)) { | |
517 param_list <- list() | |
518 for (param_name in names(process_arg_list[[list_name]])) { | |
519 param_list[[param_name]] <- process_arg_list[[list_name]][[param_name]] | |
520 } | |
521 process_params[[length(process_params)+1]] <- param_list | |
522 } | |
523 } | |
524 | |
499 message("Parameters from previous processes extracted.") | 525 message("Parameters from previous processes extracted.") |
500 | 526 |
501 | 527 |
502 indices <- as.numeric(unique(var_meta[, file_grouping_var])) | 528 indices <- as.numeric(unique(var_meta[, file_grouping_var])) |
503 smol_xcms_set <- orm$smol_xcms_set() | 529 smol_xcms_set <- orm$smol_xcms_set() |
530 env <- new.env() | 556 env <- new.env() |
531 ms_file <- xcms::xcmsRaw(sample_path) | 557 ms_file <- xcms::xcmsRaw(sample_path) |
532 env$tic <- ms_file@tic | 558 env$tic <- ms_file@tic |
533 env$mz <- ms_file@env$mz | 559 env$mz <- ms_file@env$mz |
534 env$scanindex <- ms_file@scanindex | 560 env$scanindex <- ms_file@scanindex |
535 env$scantime <- ms_file@scantime | 561 env$scantime <- ms_file@scantime * 60 |
536 env$intensity <- ms_file@env$intensity | 562 env$intensity <- ms_file@env$intensity |
537 env$polarity <- as.character(ms_file@polarity[[1]]) | 563 env$polarity <- as.character(ms_file@polarity[[1]]) |
538 | 564 |
539 ## Again, ms file is huge, so we get rid of it quickly. | 565 ## Again, ms file is huge, so we get rid of it quickly. |
540 rm(ms_file) | 566 rm(ms_file) |
553 } | 579 } |
554 context$clusters <- list() | 580 context$clusters <- list() |
555 context$show_percent <- show_percent | 581 context$show_percent <- show_percent |
556 context$cluster_mean_rt_abundance <- list() | 582 context$cluster_mean_rt_abundance <- list() |
557 context$central_feature <- list() | 583 context$central_feature <- list() |
584 context$adducts <- list() | |
558 load_variable_metadata(orm, var_meta, context) | 585 load_variable_metadata(orm, var_meta, context) |
559 clusters <- context$clusters | 586 clusters <- context$clusters |
560 rm(context) | 587 rm(context) |
561 message("Features enrichment") | 588 message("Features enrichment") |
562 complete_features(orm, clusters, show_percent) | 589 complete_features(orm, clusters, show_percent) |
693 if (!is.na(max_o <- extract_peak_var(sample_peak_list, "maxo"))) { | 720 if (!is.na(max_o <- extract_peak_var(sample_peak_list, "maxo"))) { |
694 dummy_feature$set_max_o(max_o) | 721 dummy_feature$set_max_o(max_o) |
695 } | 722 } |
696 } | 723 } |
697 create_associated_cluster( | 724 create_associated_cluster( |
725 orm, | |
698 context$central_feature[[clusterID]], | 726 context$central_feature[[clusterID]], |
699 dummy_feature, clusterID, | 727 dummy_feature, clusterID, |
700 context, curent_var_meta, next_pc_group, | 728 context, curent_var_meta, next_pc_group, |
701 next_align_group | 729 next_align_group |
702 ) | 730 ) |
759 } | 787 } |
760 return (clusterID + next_cluster_id) | 788 return (clusterID + next_cluster_id) |
761 } | 789 } |
762 | 790 |
763 create_associated_cluster <- function( | 791 create_associated_cluster <- function( |
792 orm, | |
764 sample_no, feature, clusterID, | 793 sample_no, feature, clusterID, |
765 context, curent_var_meta, next_pc_group, next_align_group | 794 context, curent_var_meta, next_pc_group, next_align_group |
766 ) { | 795 ) { |
767 pcgroup <- as.numeric(curent_var_meta[["pcgroup"]]) | |
768 adduct <- as.character(curent_var_meta[["adduct"]]) | |
769 annotation <- curent_var_meta[["isotopes"]] | |
770 clusterID <- as.character(clusterID) | 796 clusterID <- as.character(clusterID) |
771 if (is.null(cluster <- context$clusters[[clusterID]])) { | 797 if (is.null(cluster <- context$clusters[[clusterID]])) { |
798 pcgroup <- as.numeric(curent_var_meta[["pcgroup"]]) | |
799 adduct_name <- as.character(curent_var_meta[["adduct"]]) | |
800 annotation <- curent_var_meta[["isotopes"]] | |
772 cluster <- context$clusters[[clusterID]] <- orm$cluster( | 801 cluster <- context$clusters[[clusterID]] <- orm$cluster( |
773 pc_group=pcgroup + next_pc_group, | 802 pc_group=pcgroup + next_pc_group, |
774 adduct=adduct, | 803 # adduct=adduct, |
775 align_group=next_align_group, | 804 align_group=next_align_group, |
776 # curent_group=curent_group, | 805 # curent_group=curent_group, |
777 clusterID=context$clusterID, | 806 clusterID=context$clusterID, |
778 annotation=annotation | 807 annotation=annotation |
779 ) | 808 ) |
809 if (is.null(adduct <- context$adducts[[adduct_name]])) { | |
810 context$adducts[[adduct_name]] <- orm$adduct()$load_by(name=adduct_name)$first() | |
811 if (is.null(adduct <- context$adducts[[adduct_name]])) { | |
812 adduct <- context$adducts[[adduct_name]] <- orm$adduct(name=adduct_name, charge=0) | |
813 adduct$save() | |
814 } | |
815 } | |
816 cluster$set_adduct(adduct) | |
780 ## Crappy hack to assign sample id to cluster without loading the sample. | 817 ## Crappy hack to assign sample id to cluster without loading the sample. |
781 ## Samples are too big (their sample$env) and slows the process, and eat all the menory | 818 ## Samples are too big (their sample$env) and slows the process, and eat all the menory |
782 ## so we dont't want to load them. | 819 ## so we dont't want to load them. |
783 cluster[["sample_id"]] <- context$samples[sample_no][[1]] | 820 cluster[["sample_id"]] <- context$samples[sample_no][[1]] |
784 cluster$modified__[["sample_id"]] <- cluster[["sample_id"]] | 821 cluster$modified__[["sample_id"]] <- cluster[["sample_id"]] |