<commit_before>﻿Imports System.Runtime.CompilerServices
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
Imports Microsoft.VisualBasic.Language
Imports Microsoft.VisualBasic.Linq

Namespace TMIC.HMDB

    Public Module HMDBExtensions

        ''' <summary>
        ''' Build hmdb metabolite classify table.
        ''' </summary>
        ''' <param name="path$"></param>
        ''' <returns></returns>
        <Extension> Public Function LoadHMDBTaxonomy(path$) As Dictionary(Of String, taxonomy)
            Return metabolite.Load(path) _
                .Where(Function(x) Not x.taxonomy Is Nothing) _
                .Select(Function(metabolite)
                            Return metabolite.secondary_accessions _
                                .accession _
                                .SafeQuery _
                                .JoinIterates({metabolite.accession}) _
                                .Select(Function(id)
                                            Return (id, metabolite.taxonomy)<commit_msg>hmdb metabolite biosamples<commit_after>﻿Imports System.Runtime.CompilerServices
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
Imports Microsoft.VisualBasic.Language
Imports Microsoft.VisualBasic.Linq

Namespace TMIC.HMDB

    Public Module HMDBExtensions

        <MethodImpl(MethodImplOptions.AggressiveInlining)>
        <Extension>
        Public Function BioSamples(metabolite As metabolite) As String()
            Return metabolite.biofluid_locations.biofluid.AsList + metabolite.tissue_locations.tissue
        End Function

        ''' <summary>
        ''' Build hmdb metabolite classify table.
        ''' </summary>
        ''' <param name="path$"></param>
        ''' <returns></returns>
        <Extension> Public Function LoadHMDBTaxonomy(path$) As Dictionary(Of String, taxonomy)
            Return metabolite.Load(path) _
                .Where(Function(x) Not x.taxonomy Is Nothing) _
                .Select(Function(metabolite)
                            Return metabolite.secondary_accessions _
                                .accession _
                                .SafeQuery _
                                .JoinIterates({metabolite.accession}) _
                                .Select(Function(id)
                                            Return (id, metabolite.taxonomy)
{'fraction_non_alphanumeric': 0.08103521425540942, 'fraction_numerical': 0.0, 'mean_word_length': 1.8307322929171668, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4142632', 'n_tokens_mistral': 589, 'n_tokens_neox': 536, 'n_words': 111}