Skip to content

Commit

Permalink
Add curation rates stats to JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
kimrutherford committed Feb 11, 2024
1 parent 0949dfa commit 3c8f52e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/bin/pombase-chado-json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate getopts;

use deadpool_postgres::{Pool, Manager};
use pombase::bio::pdb_reader::read_pdb_data;
use pombase::db::ChadoQueries;

use std::str::FromStr;

Expand Down Expand Up @@ -131,6 +132,8 @@ async fn main() -> Result<(), Box<dyn Error>> {

let raw = Raw::new(&mut client).await?;

let chado_queries = ChadoQueries::new(&mut client).await?;

let interpro_data = parse_interpro(&config, &interpro_json);
let pfam_data = maybe_pfam_json.map(|pfam_json| parse_pfam(&pfam_json));
let rnacentral_data =
Expand All @@ -151,6 +154,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let web_data_build = WebDataBuild::new(&raw, &interpro_data, &pfam_data,
&rnacentral_data, &gene_history,
&pdb_entry_map, &pdb_ref_entry_map,
&chado_queries,
&config);
let web_data = web_data_build.get_web_data();

Expand Down
2 changes: 2 additions & 0 deletions src/pombase/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use std::cmp::Ordering;
use std::hash::{Hash, Hasher};

use crate::api::search_types::SolrMatchHighlight;
use crate::db::chado_queries::CommunityResponseRate;
use crate::web::config::*;
use crate::types::*;
use crate::interpro::InterProMatch;
Expand Down Expand Up @@ -2595,6 +2596,7 @@ pub struct DetailedStats {
pub ltp_genes_per_pub_per_year_range: StatsFloatTable,
pub ltp_annotations_per_pub_per_year_range: StatsFloatTable,
pub htp_annotations_per_pub_per_year_range: StatsFloatTable,
pub community_response_rates: Vec<CommunityResponseRate>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
68 changes: 68 additions & 0 deletions src/pombase/db/chado_queries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
extern crate tokio_postgres;

use self::tokio_postgres::Client;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CommunityResponseRate {
pub year: i32,
pub submitted: i64,
pub sent_sessions: i64,
pub response_rate: f32,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ChadoQueries {
pub community_response_rates: Vec<CommunityResponseRate>,
}

const RESPONSE_RATE_SQL: &str = "
WITH counts as (SELECT year,
(SELECT COUNT (*)
FROM pombase_publication_curation_summary
WHERE canto_curator_role = 'community'
AND (canto_annotation_status = 'NEEDS_APPROVAL' OR canto_annotation_status = 'APPROVAL_IN_PROGRESS' OR canto_annotation_status = 'APPROVED')
AND (canto_session_submitted_date IS NOT NULL
AND canto_session_submitted_date <= (YEAR || '-12-30')::date)) AS submitted,
(SELECT COUNT (*)
FROM pombase_publication_curation_summary
WHERE canto_curator_role = 'community'
AND (canto_approved_date is not null OR canto_first_sent_to_curator_year IS NOT NULL
AND canto_first_sent_to_curator_year <= YEAR)) AS sent_sessions
FROM generate_series(2013,
(SELECT extract(YEAR
FROM CURRENT_DATE))::integer) AS YEAR)
SELECT year, submitted, sent_sessions, trunc(100.0*submitted/sent_sessions,1)::real as response_rate from counts;
";

async fn get_community_response_rates(conn: &mut Client)
-> Result<Vec<CommunityResponseRate>, tokio_postgres::Error>
{
let mut ret = vec![];

let result = conn.query(RESPONSE_RATE_SQL, &[]).await?;

for row in &result {
let el = CommunityResponseRate {
year: row.get(0),
submitted: row.get(1),
sent_sessions: row.get(2),
response_rate: row.get(3),
};

ret.push(el);
}

Ok(ret)
}

impl ChadoQueries {
pub async fn new(conn: &mut Client) -> Result<ChadoQueries, tokio_postgres::Error> {
let community_response_rates = get_community_response_rates(conn).await?;
Ok(ChadoQueries {
community_response_rates,
})
}
}
2 changes: 2 additions & 0 deletions src/pombase/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod raw;
pub mod processed;
pub mod chado_queries;

pub use raw::Raw;
pub use processed::Processed;
pub use chado_queries::ChadoQueries;
2 changes: 1 addition & 1 deletion src/pombase/web/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ impl WebData {
let file_name = String::new() + output_dir + "/detailed_stats.json";
let f = File::create(file_name).expect("Unable to open file");
let mut writer = BufWriter::new(&f);
writer.write_all(s.as_bytes()).expect("Unable to write stats.json");
writer.write_all(s.as_bytes()).expect("Unable to write detailed_stats.json");

Ok(())
}
Expand Down
6 changes: 5 additions & 1 deletion src/pombase/web/data_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::collections::{HashMap, HashSet};

use crate::bio::pdb_reader::{PDBGeneEntryMap, PDBRefEntryMap};
use crate::bio::protein_view::make_protein_view_data_map;
use crate::db::raw::*;
use crate::db::{raw::*, ChadoQueries};

use crate::gene_history::GeneHistoryMap;
use crate::types::*;
Expand Down Expand Up @@ -65,6 +65,7 @@ pub struct WebDataBuild<'a> {
all_gene_history: &'a Option<GeneHistoryMap>,
pdb_gene_entry_map: &'a Option<PDBGeneEntryMap>,
pdb_ref_entry_map: &'a Option<PDBRefEntryMap>,
chado_queries: &'a ChadoQueries,
config: &'a Config,

genes: UniquenameGeneMap,
Expand Down Expand Up @@ -879,6 +880,7 @@ impl <'a> WebDataBuild<'a> {
all_gene_history: &'a Option<GeneHistoryMap>,
pdb_gene_entry_map: &'a Option<PDBGeneEntryMap>,
pdb_ref_entry_map: &'a Option<PDBRefEntryMap>,
chado_queries: &'a ChadoQueries,
config: &'a Config) -> WebDataBuild<'a>
{
WebDataBuild {
Expand All @@ -889,6 +891,7 @@ impl <'a> WebDataBuild<'a> {
all_gene_history,
pdb_gene_entry_map,
pdb_ref_entry_map,
chado_queries,
config,

genes: BTreeMap::new(),
Expand Down Expand Up @@ -7300,6 +7303,7 @@ phenotypes, so just the first part of this extension will be used:
header: annotations_per_year_header,
data: htp_annotations_per_year_range,
},
community_response_rates: self.chado_queries.community_response_rates.clone(),
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/test_db_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use self::pombase::data_types::*;
use self::pombase::web::config::*;
use self::pombase::web::data_build::*;
use self::pombase::web::data::*;
use pombase::db::ChadoQueries;
use pombase::interpro::DomainData;

mod util;
Expand Down Expand Up @@ -747,10 +748,13 @@ fn get_test_web_data() -> WebData {
let rnacentral_data = Some(HashMap::new());
let pfam_data = Some(HashMap::new());
let gene_history = None;
let chado_queries = ChadoQueries {
community_response_rates: vec![],
};

let web_data_build = WebDataBuild::new(&raw, &domain_data, &pfam_data,
&rnacentral_data, &gene_history,
&None, &None, &config);
&None, &None, &chado_queries, &config);
web_data_build.get_web_data()
}

Expand Down

0 comments on commit 3c8f52e

Please sign in to comment.