差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
20220914_invertebrate_grouping_script_4 [2022/09/14 07:56] – 作成 133.11.50.163 | 20220914_invertebrate_grouping_script_4 [Unknown date] (現在) – 削除 - 外部編集 (Unknown date) 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ``` | ||
- | //read species file | ||
- | const { group } = require(" | ||
- | const { Socket } = require(" | ||
- | var fs = require(" | ||
- | var data = fs.readFileSync('/ | ||
- | //change the data to 1D-array | ||
- | var arr = data.toString().split(" | ||
- | arr.sort(); | ||
- | var processList=[] | ||
- | var speciesNumber=arr.length | ||
- | var saveList=[] | ||
- | //change the data to 2D-array | ||
- | for (var species=0; species< | ||
- | processList[species]=arr[species].split(";" | ||
- | } | ||
- | |||
- | var countNumber=speciesNumber | ||
- | |||
- | //COUNTING the words, and separate the list | ||
- | var round=0 | ||
- | do{ | ||
- | var counttmp=[] | ||
- | var wordListtmp=[] | ||
- | for (var s=0; s< | ||
- | var existchecker=" | ||
- | for (i=0; | ||
- | if (processList[s][round]===wordListtmp[i]){ | ||
- | existchecker=" | ||
- | var posilog=i | ||
- | } | ||
- | } | ||
- | if (existchecker==" | ||
- | counttmp[posilog]=counttmp[posilog]+1 | ||
- | } | ||
- | else{ | ||
- | wordListtmp.push(processList[s][round]) | ||
- | counttmp.push(1) | ||
- | } | ||
- | } | ||
- | //get nost counted word | ||
- | var countNumbertmp=0 | ||
- | for (var j=0; j< | ||
- | if(countNumbertmp< | ||
- | countNumbertmp=counttmp[j] | ||
- | var indexOfCountNumber=j | ||
- | } | ||
- | var mostCountedWord=wordListtmp[indexOfCountNumber] | ||
- | } | ||
- | //separate the species list if need | ||
- | if (countNumbertmp!==countNumber){ | ||
- | //separate the list to save list and process list | ||
- | var savelisttmp=[] | ||
- | var processListtmp=[] | ||
- | processNumber=processList.length | ||
- | for (var k=0; | ||
- | if (mostCountedWord!==processList[k][round]){ | ||
- | savelisttmp.push(processList[k]) | ||
- | } | ||
- | else{ | ||
- | processListtmp.push(processList[k]) | ||
- | } | ||
- | } | ||
- | if (savelisttmp.length!==0){ | ||
- | saveList.push(savelisttmp) | ||
- | } | ||
- | processList=processListtmp | ||
- | } | ||
- | countNumber=countNumbertmp | ||
- | var time=round+1 | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | round=round+1 | ||
- | } | ||
- | while (countNumber> | ||
- | |||
- | |||
- | //get final separate list and counts | ||
- | var separatedList=[] | ||
- | separatedList.push(processList) | ||
- | for (var q=0; q< | ||
- | separatedList.push(saveList[q]) | ||
- | } | ||
- | |||
- | var separatedCountList=[] | ||
- | for (var t=0; t< | ||
- | separatedCountList[t]=separatedList[t].length | ||
- | } | ||
- | |||
- | |||
- | |||
- | |||
- | //GROUPING | ||
- | var operationseparatedCountList=separatedCountList | ||
- | var operationseparatedList=separatedList | ||
- | do{ | ||
- | var groupinglisttmp=[] | ||
- | console.log(" | ||
- | var groupingtmp=[] | ||
- | console.log(" | ||
- | var d=speciesNumber | ||
- | var positionsaver=0 | ||
- | for(var i=0; | ||
- | var a=operationseparatedCountList[i] | ||
- | var b=operationseparatedCountList[i+1] | ||
- | var c=a+b | ||
- | if (c<d){ | ||
- | d=c | ||
- | positionsaver=i | ||
- | } | ||
- | } | ||
- | console.log(" | ||
- | console.log(positionsaver) | ||
- | console.log(" | ||
- | for (var j=0; | ||
- | groupinglisttmp.push(operationseparatedList[j]) | ||
- | console.log(operationseparatedList[j].length) | ||
- | console.log(" | ||
- | } | ||
- | for (var s=0; | ||
- | groupingtmp.push(operationseparatedList[positionsaver][s]) | ||
- | } | ||
- | for (var s=0; | ||
- | groupingtmp.push(operationseparatedList[positionsaver+1][s]) | ||
- | } | ||
- | groupinglisttmp.push(groupingtmp) | ||
- | console.log(" | ||
- | console.log(groupingtmp.length) | ||
- | console.log(" | ||
- | for (var j=positionsaver+2; | ||
- | groupinglisttmp.push(operationseparatedList[j]) | ||
- | console.log(operationseparatedList[j].length) | ||
- | console.log(" | ||
- | } | ||
- | |||
- | if (groupinglisttmp[-1]=undefined){ | ||
- | groupinglisttmp.pop() | ||
- | } | ||
- | operationseparatedCountList=[] | ||
- | for (var t=0; t< | ||
- | operationseparatedCountList[t]=groupinglisttmp[t].length | ||
- | } | ||
- | console.log(" | ||
- | console.log(groupinglisttmp.length) | ||
- | console.log(operationseparatedCountList.length) | ||
- | console.log(operationseparatedCountList) | ||
- | operationseparatedList=groupinglisttmp | ||
- | |||
- | } | ||
- | while(operationseparatedCountList.length> | ||
- | |||
- | |||
- | |||
- | console.log(" | ||
- | console.log(" | ||
- | console.log(separatedCountList) | ||
- | |||
- | var groupingresult=operationseparatedList | ||
- | console.log(" | ||
- | for(var i=0; | ||
- | console.log(groupingresult[i].length) | ||
- | } | ||
- | ``` | ||
- | result | ||
- | ``` | ||
- | -------round------- | ||
- | ------0 | ||
- | ----positionsaver---- | ||
- | 8 | ||
- | ----species number---- | ||
- | 11 | ||
- | ------1 | ||
- | 4 | ||
- | ------2 | ||
- | 2 | ||
- | ------3 | ||
- | 27 | ||
- | ------4 | ||
- | 7 | ||
- | ------5 | ||
- | 9 | ||
- | ------6 | ||
- | 1 | ||
- | ------7 | ||
- | 12 | ||
- | ------8 | ||
- | ----combine---- | ||
- | 3 | ||
- | ------9 | ||
- | 13 | ||
- | ------10 | ||
- | 9 | ||
- | ------11 | ||
- | 2 | ||
- | ------12 | ||
- | ----count now---- | ||
- | 12 | ||
- | 12 | ||
- | [ | ||
- | 11, 4, 2, 27, 7, | ||
- | 9, 1, 12, 3, 13, | ||
- | 9, 2 | ||
- | ] | ||
- | -------round------- | ||
- | ------0 | ||
- | ----positionsaver---- | ||
- | 1 | ||
- | ----species number---- | ||
- | 11 | ||
- | ------1 | ||
- | ----combine---- | ||
- | 6 | ||
- | ------2 | ||
- | 27 | ||
- | ------3 | ||
- | 7 | ||
- | ------4 | ||
- | 9 | ||
- | ------5 | ||
- | 1 | ||
- | ------6 | ||
- | 12 | ||
- | ------7 | ||
- | 3 | ||
- | ------8 | ||
- | 13 | ||
- | ------9 | ||
- | 9 | ||
- | ------10 | ||
- | 2 | ||
- | ------11 | ||
- | ----count now---- | ||
- | 11 | ||
- | 11 | ||
- | [ | ||
- | 11, 6, 27, 7, 9, | ||
- | 1, 12, 3, 13, 9, | ||
- | 2 | ||
- | ] | ||
- | -------round------- | ||
- | ------0 | ||
- | ----positionsaver---- | ||
- | 4 | ||
- | ----species number---- | ||
- | 11 | ||
- | ------1 | ||
- | 6 | ||
- | ------2 | ||
- | 27 | ||
- | ------3 | ||
- | 7 | ||
- | ------4 | ||
- | ----combine---- | ||
- | 10 | ||
- | ------5 | ||
- | 12 | ||
- | ------6 | ||
- | 3 | ||
- | ------7 | ||
- | 13 | ||
- | ------8 | ||
- | 9 | ||
- | ------9 | ||
- | 2 | ||
- | ------10 | ||
- | ----count now---- | ||
- | 10 | ||
- | 10 | ||
- | [ | ||
- | 11, 6, 27, 7, 10, | ||
- | 12, 3, 13, 9, 2 | ||
- | ] | ||
- | -------round------- | ||
- | ------0 | ||
- | ----positionsaver---- | ||
- | 8 | ||
- | ----species number---- | ||
- | 11 | ||
- | ------1 | ||
- | 6 | ||
- | ------2 | ||
- | 27 | ||
- | ------3 | ||
- | 7 | ||
- | ------4 | ||
- | 10 | ||
- | ------5 | ||
- | 12 | ||
- | ------6 | ||
- | 3 | ||
- | ------7 | ||
- | 13 | ||
- | ------8 | ||
- | ----combine---- | ||
- | 11 | ||
- | ------9 | ||
- | ----count now---- | ||
- | 9 | ||
- | 9 | ||
- | [ | ||
- | 11, 6, 27, 7, 10, | ||
- | 12, 3, 13, 11 | ||
- | ] | ||
- | -------round------- | ||
- | ------0 | ||
- | ----positionsaver---- | ||
- | 5 | ||
- | ----species number---- | ||
- | 11 | ||
- | ------1 | ||
- | 6 | ||
- | ------2 | ||
- | 27 | ||
- | ------3 | ||
- | 7 | ||
- | ------4 | ||
- | 10 | ||
- | ------5 | ||
- | ----combine---- | ||
- | 15 | ||
- | ------6 | ||
- | 13 | ||
- | ------7 | ||
- | 11 | ||
- | ------8 | ||
- | ----count now---- | ||
- | 8 | ||
- | 8 | ||
- | [ | ||
- | 11, 6, 27, 7, | ||
- | 10, 15, 13, 11 | ||
- | ] | ||
- | ----------RESULT---------- | ||
- | -------counting result------- | ||
- | [ | ||
- | 11, 4, 2, 27, 7, 9, | ||
- | 1, 12, 1, 2, 13, 9, | ||
- | 2 | ||
- | ] | ||
- | -------grouping result------- | ||
- | 11 | ||
- | 6 | ||
- | 27 | ||
- | 7 | ||
- | 10 | ||
- | 15 | ||
- | 13 | ||
- | 11 | ||
- | ``` | ||
- | |||