Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/emkcosta/KillifishAutomaticFeederPaper
07 December 2022, 14:04:35 UTC
  • Code
  • Branches (2)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/add-license-1
    • refs/heads/main
    No releases to show
  • 336b4b1
  • /
  • Fig6_SuppFig6
  • /
  • Rscripts
  • /
  • 4_AvgVelocity_SuppFig6.R
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:fde5e2be53bdceb54ab7c34dea45a4c4b10df897
origin badgedirectory badge
swh:1:dir:6e518c2937180bba999c066f721dba2067b61f3d
origin badgerevision badge
swh:1:rev:451bc5d78cd266a00b53612585d201d404f73920
origin badgesnapshot badge
swh:1:snp:a9f2e10f0b2ec00bc74865a9a1af5fd0004baa95

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 451bc5d78cd266a00b53612585d201d404f73920 authored by Emma on 24 October 2022, 20:33:32 UTC
Delete SuppFig2 directory
Tip revision: 451bc5d
4_AvgVelocity_SuppFig6.R
# Title:  Animal Average Velocities
# Author: Emma K. Costa
# Date: code compiled on 20220822
# Related publication: Andrew McKay, Emma K. Costa, and Jingxun Chen, eLife, 2022


# ------------------------------------------------------------------
# Set up
# ------------------------------------------------------------------
inputDir <- c('/../1_ProcessingDLCOutPut/Output/velocity/')
outputDir <- c('/../3_SuppFig6/Output/')

setwd(inputDir)

f <- list.files(pattern=c("*.csv"), full.names=F, recursive=FALSE) 

#make one large table
tables <- lapply(f, read.csv)
df <- do.call(rbind, tables)

#add one to the trial #'s so it's no longer 0 indexed
df$recording_num <- df$recording_num + 1


#compute rolling averages
df <- df %>%
  dplyr::arrange(fishnum) %>% 
  dplyr::group_by(fishnum,recording_num) %>%
  dplyr::mutate(velocity_x_5frame = zoo::rollmean(velocity_x, k = 5, fill = NA),  #5 frames
                velocity_x_10frame = zoo::rollmean(velocity_x, k = 10, fill = NA), #10 frames
                velocity_x_20frame = zoo::rollmean(velocity_x, k = 20, fill = NA), #20 frames
                velocity_x_40frame = zoo::rollmean(velocity_x, k = 40, fill = NA) #40 frames
  )

df <- subset(df, seconds <= 18)
df <- subset(df, recording_num <= 17)

# ------------------------------------------------------------------
# Calculate the mean velocities
# ------------------------------------------------------------------
animals.to.include <- c("1", "2", "3", "4", "5", "9","13","14","15", "16", "19", "20", "26")
df <- subset(df, fishnum %in% animals.to.include)

avg.vel <- data.frame('fishnum' = animals.to.include, 'avg.velocity' =  NA)

for(i in 1:length(animals.to.include)){
  animal <- animals.to.include[i] 
  df.subset <- subset(df, fishnum <= animal) #do this on an individual animal basis
  
  upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]] #thresholding top 15%
  lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]] #thresholding bottom 15%
  
  data <- df.subset %>% 
    mutate(velocity_x2 = case_when(
      velocity_x_20frame >= upper ~ upper,
      T ~ velocity_x_20frame
    )) %>%
    mutate(velocity_x3 = case_when(
      velocity_x2 <= lower ~ lower,
      T ~ velocity_x2
    ))
  
  avg.vel[i,]$avg.velocity <- mean(data$velocity_x3, na.rm = T)
}

View(avg.vel)

#save this data
setwd(paste(outputDir))
write.csv(avg.vel, "allanimals_avgvelocities.csv")

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API