Skip to content

Update ATAC-seq pipeline - #322

Open
marinafloresp wants to merge 17 commits into
masterfrom
atac-update
Open

Update ATAC-seq pipeline#322
marinafloresp wants to merge 17 commits into
masterfrom
atac-update

Conversation

@marinafloresp

@marinafloresp marinafloresp commented Sep 5, 2025

Copy link
Copy Markdown
Collaborator

Description

This pull request will update the ATAC-seq pipeline with the latest working scripts. Documentation still needs to be fully updated. The scripts of this update still need to be reviewed.

Issue ticket number

This pull request is to address issue: #number.

Type of pull request

  • Bug fix
  • New feature/enhancement
  • Code refactor
  • Documentation update

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have tested my code to check that it is functional
  • I have used linters to check for common sources of errors
  • I have implemented fail safes in my code to account for edge cases
  • I have made the corresponding changes to the documentation

@marinafloresp marinafloresp added the ATACSeq ATAC-seq data label Sep 5, 2025

@sof202 sof202 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some nice changes here Marina. Some of the explanations in the Rmarkdown have much more clarity and succinctness than before.

This was pretty hard to review however. All I see on my end is one lump sum of all of your changes from the last couple of months. It would be easier to see your intentions behind changes if each change came as a different commit. As such I must assume I have missed a lot of minor details here. For example, you might remove a function somehwere, but I have no idea why it is has been removed (perhaps it has been replaced, moved or simply isn't needed anymore, I have no way of knowing).

I trust that you and Philippa have already been using these scripts and so they should be functional.

Comment on lines +48 to +52
metadata<-read.table(sampleSheet, header = TRUE, sep = ',', stringsAsFactors = FALSE)

samplesPassed <- read.csv(file.path(paste0(metaDir,"/passAllStatus.csv")), sep = ",",stringsAsFactors = FALSE)
samplesPassed <- samplesPassed[samplesPassed$QCS1 == TRUE & samplesPassed$QCS2 == TRUE,]
qcStats <- read.csv(file.path(paste0(metaDir,"/samplesGroupAnalysisQC1.csv")), sep = ",",stringsAsFactors = FALSE)

if(file.exists(paste0(metaDir,"/leaveOutSamples.txt"))){
loSamples <- read.table(file.path(paste0(metaDir,"/leaveOutSamples.txt")))[,1]
samplesStatus <- samplesPassed[!samplesPassed$sampleID %in% loSamples,]
pheno <- metadata[metadata$sampleID %in% samplesStatus$sampleID,]
samplesStatus <- samplesStatus[samplesStatus$sampleID %in% pheno$sampleID,]
qcStats <- qcStats[qcStats$Sample %in% samplesStatus$sampleID,]
}else{
pheno <- metadata[metadata$sampleID %in% samplesPassed$sampleID,]
qcStats <- qcStats[qcStats$Sample %in% samplesPassed$sampleID,]

}

df_ordered <- pheno[order(pheno$fraction), ]
samplesPassed <- read.csv(file.path(qc12stats), sep = ",",stringsAsFactors = FALSE)
samples <- read.csv(file.path(groupAnalysisSamples), sep = ",",stringsAsFactors = FALSE)
samplesPassed <- samplesPassed[samplesPassed$PASSALL == TRUE,]
qcStats <- read.table(qc1stats, header = TRUE, sep = ',', stringsAsFactors = FALSE)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can I ask why all of our scrips state stringsAsFactors = FALSE. Do we ever have this as TRUE anywhere at all? The default behaviour is this being set to FALSE. The separator being set here is also not really required as it is also the default, but I'm more ok with this as it make it more obvious what the expected format is.

}

df_ordered <- pheno[order(pheno$fraction), ]
samplesPassed <- read.csv(file.path(qc12stats), sep = ",",stringsAsFactors = FALSE)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is file.path() required here? I assume that qc12stats is just some string, in which case this function call is not doing anything. If it qc12stats is a vector of strings, then nevermind.

samplesPassed <- samplesPassed[samplesPassed$PASSALL == TRUE,]
qcStats <- read.table(qc1stats, header = TRUE, sep = ',', stringsAsFactors = FALSE)
metadata$sequencingBatch <- as.factor(metadata$sequencingBatch)
metadata<- droplevels(metadata)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What am I missing here? Is this actually doing anything? This call will remove any levels in a factor vector that has no representation in the vector:

a <- factor(c(1,1,2,2,3))
a[5] <- 2
# 3 is still a level despite not appearing in a
a <- droplevels(a)
# 3 is removed as a level

But here, the only factor column is the sequencingBatch column. The levels have just been generated in the previous line and so all levels appear in the column still. This therefore does nothing right?

@@ -81,8 +67,6 @@ colors <- brewer.pal(3, "Set2")
## Load counts in peaks files and match to pheno samples data

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

stale comment?

tpm.scores<-tpm.scores[,which(tpm.pca > 0.01)]
percentVar = round(100 * (tpm.pca) )
results <- list(tpm.scores[,c(1:5)], percentVar)
results <- list(tpm.scores[,c(1:4)], percentVar)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any particular reason we are now taking 4 instead of 5 principle components? If this is something that would end up being variable, it might be a good idea to add it as a function parameter so the caller can decide how many to pick.

## - <cell-group>.filt.broadPeak.bed" in 4_calledpeaks folder ||
## ||
## REQUIRES: ||
## - R version > 4.3 ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here we now require a version of R greater than 4.3. I presume you meant R >= 4.3

samples <- names(listSamples)
for(i in 1:length(listSamples)) {
df <-data.frame(listSamples[i])
df <-data.frame(listSamples[[i]])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is good, I encourage indexing like this.

Comment on lines -107 to +111
multiqc . -f -o ${FASTQCDIR}/multiqc
multiqc ${FASTQCDIR}/*_fastqc.zip -f -o ${FASTQCDIR}/multiqc
rm -f *.html

cd ${ALIGNED_DIR}
multiqc . -f -o ${ALIGNED_DIR}/multiqc
multiqc ${ALIGNED_DIR}/*.bowtie.log -f -o ${ALIGNED_DIR}/multiqc

cd ${TRIM_DIR}/qc
multiqc . -f -o ${TRIM_DIR}/multiqc
multiqc ${TRIM_DIR}/qc/*_trimmed_fastqc.zip -f -o ${TRIM_DIR}/multiqc

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Much safer.

if [[ ! $2 =~ "FRAGSIZE" ]] && [[ ! $2 =~ "PEAKS" ]] && [[ ! $2 =~ "COUNTS" ]] && [[ ! $2 == '' ]];
if [[ ! $2 =~ "PEAKS" ]] && [[ ! $2 =~ "COUNTS" ]] && [[ ! $2 == 'FILT' ]] && [[ ! $2 == 'CTCHECK' ]] && [[ ! $2 == 'DIFFCOUNTS' ]] && [[ ! $2 == ' ' ]];
then
{ echo "Unknown step specified. Please use FRAGSIZE, PEAKS, COUNTS or some combination of this as a single string (i.e. FASTQC,TRIM)" ; exit 1; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is echo has gone stale (COUNTS no longer exists and is replaced by 3 new steps".

If you still want to have combinations of steps you will need to continue using =~ pattern matching instead of == equality.


## mark duplicates only
picard MarkDuplicates --INPUT ${ALIGNED_DIR}/${sampleName}_sorted_name.bam --OUTPUT ${ALIGNED_DIR}/baseRecalibrate/${sampleName}_dedup.bam --METRICS_FILE ${ALIGNED_DIR}/baseRecalibrate/${sampleName}_metrics.txt --TMP_DIR ${TMPDIR}
picard MarkDuplicates --INPUT ${ALIGNED_DIR}/${sampleName}_sorted_name.bam \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Am I correct in assuming that picard creates ${ALIGNED_DIR}/baseRecalibrate? Or is this now created elsewhere (hence the mkdir command being removed on line 37)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ATACSeq ATAC-seq data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants