Biological databases and sequence retrieval

Practical 1: Genomics, systems biology and multi-omics

Learning objectives

Identify record levels and provenance; retrieve local teaching records by explicit accession; audit one-to-many annotation.

Biological question and data

Which biological records are needed to connect a measured feature to its sequence and annotation? This offline exercise uses fictional records so retrieval is reproducible and does not depend on a live service.

Records are distinct objects; study, sample, gene and transcript identifiers are not interchangeable. Real retrieval needs species, assembly, version and access checks.

No biological download is required. Numerical inputs are hypothetical, not observed animal data. The runnable examples use base R. Count and abundance units are specified where used.

1. Inspect the resource catalogue

Use the record type to determine what a query returns.

Show R code
catalogue <- data.frame(accession=c("study_demo","sample_demo1","gene_demo1","tx_demo1"),
 type=c("study","sample","gene","transcript"),
 parent=c(NA,"study_demo",NA,"gene_demo1"),version=c("v1","v1","v2","v1"))
catalogue
     accession       type     parent version
1   study_demo      study       <NA>      v1
2 sample_demo1     sample study_demo      v1
3   gene_demo1       gene       <NA>      v2
4     tx_demo1 transcript gene_demo1      v1
Show R code
stopifnot(!anyDuplicated(catalogue$accession))

All identifiers are fictional. A sample belongs to a study; a transcript relates to a gene. Neither relationship supplies the measurement values.

2. Retrieve and preserve records

Select explicitly and round-trip a temporary CSV. This represents retrieval from a supplied snapshot, not an API call.

Show R code
selected <- catalogue[match(c("gene_demo1","tx_demo1"),catalogue$accession),]
stopifnot(!anyNA(selected$accession))
file <- tempfile(fileext=".csv")
write.csv(selected,file,row.names=FALSE,na="")
restored <- read.csv(file,na.strings="",stringsAsFactors=FALSE)
stopifnot(identical(as.character(restored$accession),selected$accession))
data.frame(accession=restored$accession,version=restored$version,
 snapshot_checksum=unname(tools::md5sum(file)))
   accession version                snapshot_checksum
1 gene_demo1      v2 fb0a31a85fa5b9990b6d98b7dd797afa
2   tx_demo1      v1 fb0a31a85fa5b9990b6d98b7dd797afa
Show R code
unlink(file)

A checksum captures this snapshot’s bytes. The version remains separate because a checksum is not a biological accession.

3. Audit annotation expansion

A gene-to-transcript mapping can expand the rows. Count distinct biological keys after the join.

Show R code
measurement <- data.frame(gene=c("gene_demo1","gene_demo2"),value=c(8,10))
map <- data.frame(gene=c("gene_demo1","gene_demo1"),transcript=c("tx1","tx2"))
joined <- merge(measurement,map,all.x=TRUE)
joined
        gene value transcript
1 gene_demo1     8        tx1
2 gene_demo1     8        tx2
3 gene_demo2    10       <NA>
Show R code
stopifnot(nrow(joined)==3,length(unique(joined$gene))==2)

Three joined rows still represent two measured genes, not three independent measurements.

4. Compare records at the right level

A public study may have several samples, several files per sample and several annotations per feature. Count each level separately. The following fictional retrieval result includes two files from one biological sample; treating files as animals would inflate replication.

Show R code
retrieval <- data.frame(study=rep('studyA',4),
 sample=c('sample1','sample1','sample2','sample3'),
 file=c('read1','read2','read3','read4'))
c(files=nrow(retrieval),samples=length(unique(retrieval$sample)),
 studies=length(unique(retrieval$study)))
  files samples studies 
      4       3       1 

Keep a record of species, tissue, treatment, collection time and processing before selecting a dataset. A large matrix without the relevant metadata may not answer the proposed question.

5. Assess an update rather than silently replacing it

An annotation update can add or remove mappings while leaving the measured feature unchanged. Preserve the original mapping, compare unmatched keys and document which results change. A checksum identifies a retrieved file’s bytes; it does not evaluate a record’s biological correctness. For a real retrieval, use the database documentation to distinguish accession levels and retain the retrieval query and version.

Interpretation challenge

A study lists 12 sequence files but only six samples. What evidence is needed before claiming six independent animals?

Establish how files map to samples, specimens and animals, and how treatment was allocated. Multiple libraries, tissues or times from the same animal are not independent allocations.

Interpretation and limits

For a real GEO analysis, distinguish series, samples and platforms using NCBI’s record documentation. This practical does not download or validate an organism-specific annotation.

Exercises

  1. Add an unmatched query and require an informative check.
  2. Explain why transcript rows cannot be counted as independent gene measurements.
  3. What extra fields would a variant-annotation snapshot need?
  1. match returns NA; stop or record the exclusion before indexing.
  2. Both transcript annotations reuse the gene measurement.
  3. Species, assembly, coordinate convention, counted alleles where relevant, annotation release, source and retrieval details.

Continue learning

B03 Databases and B04 Programming.

Continue with sequence handling. Return to the practical index or the unified map.