2020-05-02 01:46:04 +02:00
source ( " renv/activate.R" )
2020-06-02 23:49:55 +02:00
source ( " src/features/call/call_base.R" )
2019-10-25 16:21:09 +02:00
library ( dplyr )
2019-11-06 20:47:33 +01:00
calls <- read.csv ( snakemake @ input [ [1 ] ] , stringsAsFactors = FALSE )
2020-08-26 18:09:53 +02:00
day_segments_labels <- read.csv ( snakemake @ input [ [ " day_segments_labels" ] ] )
2020-04-08 17:51:18 +02:00
requested_features <- snakemake @ params [ [ " features" ] ]
2020-06-02 23:49:55 +02:00
call_type <- snakemake @ params [ [ " call_type" ] ]
2020-08-26 18:09:53 +02:00
features = data.frame ( local_segment = character ( ) , stringsAsFactors = FALSE )
2019-10-25 16:21:09 +02:00
2020-08-26 18:09:53 +02:00
day_segments <- day_segments_labels %>% pull ( label )
for ( day_segment in day_segments )
features <- merge ( features , base_call_features ( calls , call_type , day_segment , requested_features ) , all = TRUE )
2019-10-25 16:21:09 +02:00
2020-06-02 23:49:55 +02:00
if ( ncol ( features ) != length ( requested_features ) + 1 )
stop ( paste0 ( " The number of features in the output dataframe (=" , ncol ( features ) , " ) does not match the expected value (=" , length ( requested_features ) , " + 1). Verify your Call feature extraction functions" ) )
2020-03-12 16:18:32 +01:00
2020-08-26 18:09:53 +02:00
features <- features %>% separate ( col = local_segment ,
2020-08-26 19:02:27 +02:00
into = c ( " local_segment_label" , " local_start_date" , " local_start_time" , " local_end_date" , " local_end_time" ) ,
2020-08-26 18:09:53 +02:00
sep = " #" ,
remove = FALSE )
2019-11-06 20:47:33 +01:00
write.csv ( features , snakemake @ output [ [1 ] ] , row.names = FALSE )