-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: various ux/ui updates and other minor changes
- Loading branch information
Showing
8 changed files
with
249 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Molecule; | ||
use DB; | ||
use Illuminate\Console\Command; | ||
|
||
class ExtractCAS extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:extract-cas'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
Molecule::whereNull('cas')->whereNotNull('synonyms')->select('id', 'synonyms')->chunk(10000, function ($mols) { | ||
$data = []; | ||
$pattern = "/\b[1-9][0-9]{1,5}-\d{2}-\d\b/"; | ||
foreach ($mols as $mol) { | ||
$casIds = preg_grep($pattern, $mol->synonyms); | ||
array_push($data, [ | ||
'id' => $mol->id, | ||
'cas' => array_values($casIds), | ||
]); | ||
$this->info("Mapped and updated: $mol->id"); | ||
} | ||
$this->insertBatch($data); | ||
}); | ||
} | ||
|
||
/** | ||
* Insert a batch of data into the database. | ||
* | ||
* @return void | ||
*/ | ||
private function insertBatch(array $data) | ||
{ | ||
DB::transaction(function () use ($data) { | ||
foreach ($data as $row) { | ||
Molecule::updateorCreate( | ||
[ | ||
'id' => $row['id'], | ||
], | ||
[ | ||
'cas' => $row['cas'], | ||
] | ||
); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Molecule; | ||
use DB; | ||
use Illuminate\Console\Command; | ||
|
||
class GenerateAnnotationScore extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:generate-score'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
public function handle() | ||
{ | ||
$batchSize = 1000; | ||
$offset = 0; | ||
|
||
while (true) { | ||
$molecules = DB::table('molecules') | ||
->offset($offset) | ||
->limit($batchSize) | ||
->get(); | ||
|
||
if ($molecules->isEmpty()) { | ||
break; | ||
} | ||
|
||
$data = []; | ||
|
||
foreach ($molecules as $molecule) { | ||
$score = $this->calculateAnnotationScore($molecule); | ||
array_push($data, [ | ||
'id' => $molecule->id, | ||
'annotation_level' => $score, | ||
]); | ||
} | ||
|
||
$this->insertBatch($data); | ||
|
||
$offset += $batchSize; | ||
$this->info("Processed batch starting from offset $offset"); | ||
} | ||
|
||
$this->info('Annotation scores generated successfully.'); | ||
} | ||
|
||
/** | ||
* Insert a batch of data into the database. | ||
* | ||
* @return void | ||
*/ | ||
private function insertBatch(array $data) | ||
{ | ||
DB::transaction(function () use ($data) { | ||
foreach ($data as $row) { | ||
Molecule::updateorCreate( | ||
[ | ||
'id' => $row['id'], | ||
], | ||
[ | ||
'annotation_level' => $row['annotation_level'], | ||
] | ||
); | ||
} | ||
}); | ||
} | ||
|
||
protected function calculateAnnotationScore($molecule) | ||
{ | ||
$literatureCount = DB::table('citables') | ||
->where('citable_id', $molecule->id) | ||
->where('citable_type', 'App\Models\Molecule') | ||
->count(); | ||
|
||
$organismCount = DB::table('molecule_organism') | ||
->where('molecule_id', $molecule->id) | ||
->count(); | ||
|
||
$casScore = $molecule->cas ? 1 : 0.5; | ||
$synonymsScore = $molecule->synonyms ? (count(explode(',', $molecule->synonyms)) >= 3 ? 1 : 0.5) : 0; | ||
$nameScore = $molecule->name ? 1 : 0.5; | ||
|
||
$literatureScore = $literatureCount >= 3 ? 1 : ($literatureCount >= 1 ? 0.5 : 0); | ||
$organismScore = $organismCount >= 1 ? 1 : 0; | ||
|
||
$totalScore = ($literatureScore * 0.30) + | ||
($organismScore * 0.25) + | ||
($casScore * 0.20) + | ||
($synonymsScore * 0.15) + | ||
($nameScore * 0.10); | ||
$finalScore = round($totalScore * 5, 2); | ||
|
||
return ceil($finalScore); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters