Skip to content

Commit

Permalink
code edits
Browse files Browse the repository at this point in the history
shortened the code for some helper functions
  • Loading branch information
sameerpadhye committed Oct 2, 2024
1 parent 393da1d commit 8b1dc3d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 210 deletions.
11 changes: 2 additions & 9 deletions R/helper.biodiversity_profile_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ preston_profile <- function (df,
dplyr::mutate(rownum=as.numeric(rownum))%>%
dplyr::mutate(Octaves=as.factor(2^rownum))


preston.plot=pres_res%>%
ggplot(aes(x=Octaves,
y=observed))+
geom_bar(stat = "identity",
position = 'dodge',
fill="darkcyan",
fill="lightseagreen",
col="black",
width = 1) +
geom_point(data = pres_res,
Expand All @@ -47,7 +46,7 @@ preston_profile <- function (df,
group=1),
pch=21,
color = "black",
fill="orangered",
fill="sienna1",
size=4) +
geom_line(data = pres_res,
aes(x = Octaves,
Expand All @@ -64,7 +63,6 @@ preston_profile <- function (df,
ylab(y_label)+
ggtitle("Preston plot")


preston_results$preston.plot = preston.plot

preston_results$preston.res = preston.res
Expand All @@ -78,7 +76,6 @@ shannon_div_profile<-function(df)

{


# Shannon diversity

shannon_div=vegan::diversity(df)%>%
Expand All @@ -87,7 +84,6 @@ shannon_div_profile<-function(df)

return(shannon_div)


}

# Function: Beta diversity profile
Expand All @@ -105,8 +101,6 @@ beta_div_profile<-function(df,
runs=10,
comp = T)



beta.total = beta.bin.div$Btotal

beta.replace = beta.bin.div$Brepl
Expand All @@ -123,5 +117,4 @@ beta_div_profile<-function(df,

return(beta_div_res)


}
36 changes: 8 additions & 28 deletions R/helper.column_presets.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ presets<-function(col_groups)
{
bold_fields<-bold.fields.info()

bold_fields[which(bold_fields$field=='country/ocean'),]<-"country.ocean"

bold_fields[which(bold_fields$field=='province/state'),]<-"province.state"

common_ids<-c("processid","sampleid")

switch(col_groups,
Expand Down Expand Up @@ -94,7 +90,6 @@ presets<-function(col_groups)
},
"other_meta_data"=
{

preset<-bold_fields%>%
dplyr::select(field)%>%
dplyr::filter(field %in% c(common_ids,
Expand All @@ -105,10 +100,8 @@ presets<-function(col_groups)
"tissue_type",
"sampling_protocol"))
},

"bold_analyze_align_fields" =
{

preset<-bold_fields%>%
dplyr::select(field)%>%
dplyr::filter(field %in% c(common_ids,
Expand All @@ -117,31 +110,28 @@ presets<-function(col_groups)
},
"bold_analyze_tree_fields" =
{

preset<-data.frame(field = c("processid",
"aligned_seq",
"msa.seq.name"))
},
},
"bol_analyze_map_fields" =
{

preset<-bold_fields%>%
dplyr::select(field)%>%
dplyr::filter(field %in% c(common_ids,
"bin_uri",
"marker_code",
"nuc"))
}

)
}
)

return(preset)

}
# The function to check and return the data with the necessary columns

check_and_return_preset_df<-function (df,
category = c("check","check_return"),
category = c("check",
"check_return"),
preset)
{

Expand All @@ -150,25 +140,17 @@ check_and_return_preset_df<-function (df,
preset_col = preset%>%
dplyr::pull(field)


switch (category,


"check" =

{

if(!any(preset_col %in% names(df)))
{
stop("Please re-check if column names match with the available field names for BCDM dataframe and that minimum field requirement for the analysis is satisfied. Please read the details section of 'bold.export' help for more information on presets.")

}
},
if(!any(preset_col %in% names(df))) stop("Please re-check if column names match with the available field names for BCDM dataframe and that minimum field requirement for the analysis is satisfied. Please read the details section of 'bold.export' help for more information on presets.")
},

"check_return" =

{

if(!any(preset_col %in% names(df)))
{
stop("Please re-check if column names match with the available field names for the BCDM dataframe and that minimum field requirement for the analysis is satisfied. Please read the details section of 'bold.export' help for more information on presets.")
Expand All @@ -177,10 +159,8 @@ check_and_return_preset_df<-function (df,
{
preset_df = df%>%
dplyr::select(all_of(preset_col))

}
return(preset_df)
}
)

)
}
Loading

0 comments on commit 8b1dc3d

Please sign in to comment.