Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions R/madc2vcf_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"out_vcf= ", out_vcf, ', ',
"verbose= ", verbose,')">')

if(!is.null(madc)) report <- read.csv(madc) else stop("Please provide a MADC file")
if(!is.null(madc)) report <- read.csv(madc, check.names = FALSE) else stop("Please provide a MADC file")

Check warning on line 78 in R/madc2vcf_all.R

View check run for this annotation

Codecov / codecov/patch

R/madc2vcf_all.R#L78

Added line #L78 was not covered by tests
if(!is.null(botloci_file)) botloci <- read.csv(botloci_file, header = F) else stop("Please provide a botloci file")
if(!is.null(hap_seq_file)) hap_seq <- read.table(hap_seq_file, header = F) else hap_seq <- NULL

Expand Down Expand Up @@ -142,12 +142,12 @@
new.file <- data.frame("AlleleID" = report[,1],
"Chromosome" = NA, "SNP_position_in_Genome" = NA,
"Ref" = NA, "Alt" =NA,
"CloneID" = report[,2], report[,3:ncol(report)])
"CloneID" = report[,2], report[,3:ncol(report)], check.names = FALSE)

by_cloneID <- split.data.frame(new.file, new.file$CloneID)

clust <- makeCluster(n.cores)
#clusterExport(clust, c("hap_seq","add_ref_alt"))
#clusterExport(clust, c("hap_seq","add_ref_alt", "nsamples"))
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clusterExport call is commented out, so hap_seq, nsamples, and add_ref_alt won't be available on the workers. Uncomment or add the export call before parLapply to ensure these objects are passed to the cluster.

Suggested change
#clusterExport(clust, c("hap_seq","add_ref_alt", "nsamples"))
clusterExport(clust, c("hap_seq", "add_ref_alt", "nsamples"))

Copilot uses AI. Check for mistakes.
add_ref_alt_results <- parLapply(clust, by_cloneID, function(x) add_ref_alt(x, hap_seq, nsamples, verbose = verbose))
stopCluster(clust)

Expand All @@ -169,7 +169,6 @@

clust <- makeCluster(n.cores)
#clusterExport(clust, c("botloci", "compare", "nucleotideSubstitutionMatrix", "pairwiseAlignment", "DNAString", "reverseComplement"))
#clusterExport(clust, c("botloci"))
compare_results <- parLapply(clust, updated_by_cloneID, function(x) compare(x, botloci, alignment_score_thr))
stopCluster(clust)

Expand Down Expand Up @@ -209,7 +208,6 @@
#'
#' @noRd
add_ref_alt <- function(one_tag, hap_seq, nsamples, verbose = TRUE) {

# Add ref and alt
cloneID <- one_tag$CloneID[1]
ref <- paste0(cloneID, "|Ref_0001")
Expand Down Expand Up @@ -281,13 +279,14 @@
#'
#' @noRd
compare <- function(one_tag, botloci, alignment_score_thr = 40){
#one_tag <- updated_by_cloneID[[2]]
cloneID <- one_tag$CloneID[1]
isBotLoci <- cloneID %in% botloci[,1]
# If marker is present in the botloc list, get the reverse complement sequence
if(isBotLoci) one_tag$AlleleSequence <- sapply(one_tag$AlleleSequence, function(x) as.character(reverseComplement(DNAString(x))))

chr <- sapply(strsplit(cloneID, "_"), function(x) x[-length(x)])
if(length(chr > 1)) chr <- paste(chr, collapse = "_")
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition uses length(chr > 1), which computes the length of a logical comparison vector. It should be length(chr) > 1 to correctly check for multiple segments before collapsing.

Suggested change
if(length(chr > 1)) chr <- paste(chr, collapse = "_")
if(length(chr) > 1) chr <- paste(chr, collapse = "_")

Copilot uses AI. Check for mistakes.

# Target SNP at the position in the ID
ref_seq <- one_tag$AlleleSequence[grep("Ref_0001$",one_tag$AlleleID)]
alt_seq <- one_tag$AlleleSequence[grep("Alt_0002$",one_tag$AlleleID)]
Expand All @@ -305,9 +304,9 @@
alt_base <- substring(alt_seq, align@subject@mismatch@unlistData, align@subject@mismatch@unlistData)

# If target alternative have N, discard whole tag
if(all(alt_base %in% c("A", "T", "C", "G"))) {
# Always only one polymorphism, if there are more than one, not sure which is the target
if(all(alt_base %in% c("A", "T", "C", "G")) & length(align@pattern@mismatch@unlistData) == 1) {
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use && instead of & for scalar logical operations in if conditions to avoid unintended vectorized behavior.

Suggested change
if(all(alt_base %in% c("A", "T", "C", "G")) & length(align@pattern@mismatch@unlistData) == 1) {
if(all(alt_base %in% c("A", "T", "C", "G")) && length(align@pattern@mismatch@unlistData) == 1) {

Copilot uses AI. Check for mistakes.

# Update with new info - always only one polymorphism, if there are more than one, not sure which is the target
update_tag <- one_tag[grep("Ref_0001$",one_tag$AlleleID),]
update_tag[,2:5] <- c(chr, pos_target, ref_base, alt_base)
update_tag_temp <- one_tag[grep("Alt_0002$",one_tag$AlleleID),]
Expand Down Expand Up @@ -365,6 +364,7 @@
return(list(update_tag = NULL,
rm_score = cloneID,
rm_N = NULL))

}
}

Expand Down