<jupyter_start><jupyter_text>Draw Graphs<jupyter_code>import seaborn as sns
from  matplotlib.ticker import FuncFormatter

sns.set(font_scale=1.3)
plt.figure(figsize=(16, 12))
# sns.set(style="ticks")
sns.set()
def create_gird(df, col, hue,x,y,sharey=True, legend=False):

    # Initialize a grid of plots with an Axes for each walk
    grid = sns.FacetGrid(df, col=col, hue=hue, palette=sns.color_palette("hls", 4),sharey=sharey,
                         col_wrap=3, height=4.5)
    plt.gca().xaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))

    # Draw a horizontal line to show the starting point
    grid.map(plt.axhline, y=0, ls=":", c=".5")

    # Draw a line plot to show the trajectory of each random walk
    grid.map(plt.plot, x, y)
    grid.set_titles("{col_name}")
    if legend:
        grid.add_legend()


    # Adjust the arrangement of the plots
    grid.fig.tight_layout(w_pad=1)
    return grid
def chunks(l, n):
    # For item i in a range that is a length of l,
    for i in range(0, len(l), n):
        # Create an index range for l of n items:
        yield l[i:i + n]<jupyter_output><empty_output><jupyter_text>Analysis  Load Data<jupyter_code>spothlight = ["SARS","MERS Coronavirus", "Avian Influenza","Ebola", "Influenza", "HIV/AIDS","Hepatitis B","Hepatitis C", "Swine Flu"]
diseases_id= load_sframe("Data/diseases_list.csv")
disease_names = SFrame.read_csv("Data/disease_names.csv")
disease_names = disease_names.rename({"disease":"Disease"})<jupyter_output><empty_output><jupyter_text>SJR<jupyter_code>sjr = SJR()
sjr_sf = sjr.data<jupyter_output><empty_output><jupyter_text>Convert SJR to float form string<jupyter_code>sjr_sf["SJR"] = sjr_sf["SJR"].apply(lambda x: x.replace(",","."))
sjr_sf["SJR"] = sjr_sf["SJR"].apply(lambda x: x if x else "-1")
sjr_sf["SJR"] = sjr_sf["SJR"].astype(float)<jupyter_output><empty_output><jupyter_text>Pubmed<jupyter_code>diseases_pubmed = load_sframe("Data/pubmed/diseases_pubmed.sframe")<jupyter_output><empty_output><jupyter_text>Journals Current State Format ISSN similarly to PubMed dataset<jupyter_code>diseases_pubmed["issn_linking"]
diseases_pubmed["ISSN"] = diseases_pubmed["issn_linking"].apply(lambda x: x.replace("-", ""))<jupyter_output><empty_output><jupyter_text>SJR is publushed in a delay of two years, to deal with it we correct the SJR date to its correct publication date.<jupyter_code>sjr_sf["Year"] = sjr_sf["Year"]+2
diseases_pubmed = diseases_pubmed.rename({"disease":"Disease"})
diseases_pubmed = diseases_pubmed.filter_by(spothlight,"Disease")
pubmed_sjr = sjr_sf.join(diseases_pubmed, on={"ISSN":"ISSN","Year":"year"})
pubmed_sjr = pubmed_sjr.filter_by(spothlight,"Disease")
pubmed_sjr=pubmed_sjr.unique()
pubmed_sjr["Categories Clean"] = pubmed_sjr["Categories"].apply(lambda x: re.compile(r"\s\(.*?\);{0,1}").split(x)[:-1])
pubmed_sjr["Categories Clean"] = pubmed_sjr["Categories Clean"].apply(lambda x: {c.strip() for c in x})
cat = {"Immunology", "Epidemiology", "Infectious Diseases", "Virology", "Microbiology"}
pubmed_sjr = pubmed_sjr[pubmed_sjr["Categories Clean"].apply(lambda x: len(set(x) & cat)>0)]
journal_disease = pubmed_sjr.groupby(["ISSN","Disease","Year"], operations={"Count": agg.COUNT_DISTINCT("pmid")})
journal_map = pubmed_sjr[["SJR" ,"Title", "ISSN","Year"]].unique()
journal_disease = journal_disease.join(journal_map,["ISSN","Year"])
journal_disease = journal_disease[journal_disease["SJR"]>0]
journal_disease_df = journal_disease.to_dataframe()<jupyter_output><empty_output><jupyter_text>Top Journals by Publications<jupyter_code>journal_disease_sf = SFrame(journal_disease_df)
journal_disease_sf["Score"] = journal_disease_sf["Count"]*journal_disease_sf["SJR"]
journal_disease_score = journal_disease_sf.groupby("Disease",{"Count":agg.SUM("Count"), "Score":agg.SUM("Score")})
journal_disease_score["JScore"] = journal_disease_score["Score"] /journal_disease_score["Count"] 
journal_disease_score.sort("JScore",False)
journal_disease_score.save("output/Journals/avg_jscore.csv")
journal_disease_year_score = journal_disease_sf.groupby(["Disease","Year"],{"Count":agg.SUM("Count"), "Score":agg.SUM("Score")})
journal_disease_year_score["JScore"] = journal_disease_year_score["Score"] /journal_disease_year_score["Count"] 
journal_disease_year_score.save("output/Journals/journal_disease_year_score.csv","csv")
journal_disease_year_score = journal_disease_year_score.sort(["Disease", "Year"])

sns.set(font_scale=1.3)


plt.rc('text', usetex=False)
create_gird(journal_disease_year_score[journal_disease_year_score["Count"]>5].to_dataframe(),"Disease","Disease","Year", "JScore")
plt.savefig('output/Journals/jscore.svg')
# plt.close()


sjr_sf["Categories Clean"] = sjr_sf["Categories"].apply(lambda x: re.compile(r"\s\(.*?\);{0,1}").split(x)[:-1])
sjr_sf["Categories Clean"] = sjr_sf["Categories Clean"].apply(lambda x: {c.strip() for c in x})
sjr_sf = sjr_sf[sjr_sf["Categories Clean"].apply(lambda x: len(set(x) & cat)>0)]
jtop_10 = SFrame()
for year in range(2002,2019):
    jtop_10 = jtop_10.append(sjr_sf.filter_by(year, "Year").sort('Rank')[:10])
jtop_3 = SFrame()
for year in range(2002,2019):
    jtop_3 = jtop_3.append(sjr_sf.filter_by(year, "Year").sort('Rank')[:3])
papers_sjr_top_10 = pubmed_sjr.join( jtop_10[["Year","Sourceid"]], on=["Year","Sourceid"])

papers_sjr_top_10 = pubmed_sjr.join( jtop_10[["Year","Sourceid"]], on=["Year","Sourceid"])
papers_top_10= papers_sjr_top_10.groupby(["Disease","Year"], {"Count":agg.COUNT()})
papers_top_10 = papers_top_10.sort(["Disease","Year"])
papers_top_10["# of Papers in Top-10"] = papers_top_10["Count"]

plt.rc('text', usetex=False)
create_gird(papers_top_10.to_dataframe(),"Disease","Disease","Year", "# of Papers in Top-10", False, False)
plt.savefig('output/Journals/top10.svg')
# plt.close()


papers_sjr_top_3 = pubmed_sjr.join( jtop_3[["Year","Sourceid"]], on=["Year","Sourceid"])
papers_top_3= papers_sjr_top_3.groupby(["Disease","Year"], {"Count":agg.COUNT()})
papers_top_3 = papers_top_3.sort(["Disease","Year"])


# if LaTeX is not installed or error caught, change to `usetex=False`
plt.rc('text', usetex=False)
plt.figure(figsize=(8, 6))
create_gird(papers_top_3.to_dataframe(),"Disease","Disease","Year", "Count", True, False)
plt.savefig("output/Journals/top3.svg")


papers_q = pubmed_sjr.groupby(["Year","Disease", "SJR Best Quartile"],{"Count": agg.COUNT()})
papers_q = papers_q.sort(["Disease", "Year"])
papers_q=papers_q[papers_q["SJR Best Quartile"]!="-"]
plt.rc('text', usetex=False)
plt.figure(figsize=(8, 6))
create_gird(papers_q[papers_q["SJR Best Quartile"]=="Q1"].to_dataframe(),"Disease","Disease","Year", "Count", False)
plt.savefig('output/Journals/q1.svg')
papers_q["# of Papers in Quartile"] = papers_q["Count"]
papers_q[papers_q["Disease"]=="MERS Coronavirus"].sort("SJR Best Quartile")
plt.rc('text', usetex=False)
plt.figure(figsize=(8, 6))
create_gird(papers_q.to_dataframe(),"Disease","SJR Best Quartile","Year", "# of Papers in Quartile", False, True)
plt.savefig('output/Journals/q.svg')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17842441447835344, 'fraction_numerical': 0.014194464158977998, 'mean_word_length': 8.162548764629388, 'pattern_counts': {'":': 13, '<': 33, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '161687', 'license': 'MIT', 'n_tokens_mistral': 2958, 'n_tokens_neox': 2725, 'n_words': 418, 'path': 'examples/Coronavirus/Journals Trends.ipynb', 'repo_name': 'data4goodlab/ScienceDynamics', 'size': '7045'}