<commit_before><?php
use pgb_liv\php_ms\Reader\MzIdentMlReaderFactory;
use pgb_liv\php_ms\Reader\MzIdentMlReader1r1;
use pgb_liv\php_ms\Core\Modification;

set_time_limit(600);

define('FORM_FILE', 'mzidentml');
?>
<h2>mzIdentML Viewer</h2>
<?php
if (! empty($_FILES) && $_FILES[FORM_FILE]['error'] != 0) {
    die('<p>An error occured. Ensure you included a file to upload.</p>');
}
?>

<form enctype="multipart/form-data" action="?page=mzidentml_viewer"
    method="POST">
    <fieldset>
        <label for="file">mzIdentML File</label> <input
            name="<?php echo FORM_FILE; ?>" type="file" id="file" />
        (.gz or .mzid supported)
    </fieldset>

    <fieldset>
        <input type="submit" value="Send File" />
    </fieldset>
</form>
<?php

if ((! empty($_FILES) && $_FILES[FORM_FILE]['error'] == 0) || isset($_GET['search'])) {
    if (! empty($_FILES)) {
        $name = $_FILES[FORM_FILE]['name'];
        $mzIdentMlFile = $_FILES[FORM_FILE]['tmp_name'];
        
        if (substr_compare($_FILES[FORM_FILE]['name'], '.gz', strlen($_FILES[FORM_FILE]['name']) - 3) === 0) {
            // This input should be from somewhere else, hard-coded in this example
            $file_name = $_FILES[FORM_FILE]['tmp_name'];
            
            // Raising this value may increase performance
            // read 4kb at a time
            $buffer_size = 4096;
            $out_file_name = $file_name . '_decom';
            
            // Open our files (in binary mode)
            $file = gzopen($file_name, 'rb');
            $out_file = fopen($out_file_name, 'wb');
            
            // Keep repeating until the end of the input file
            while (! gzeof($file)) {
                // Read buffer-size bytes
                // Both fwrite and gzread and binary-safe
                fwrite($out_file, gzread($file, $buffer_size));
            }
            
            // Files are done, close files
            fclose($out_file);
            gzclose($file);
            
            $mzIdentMlFile = $out_file_name;
        }
    } else {
        $mzIdentMlFile = sys_get_temp_dir() . '/' . $_GET['search'] . '.mzid';
        $name = $_GET['name'];
    }
    
    echo '<h3>' . $name . '</h3>';
    
    $reader = MzIdentMlReaderFactory::getReader($mzIdentMlFile);
    ?>
<ul style="float: right;">
    <li><a href="#software">Software</a></li>
    <li><a href="#protocol">Protocol</a></li>
    <li><a href="#peptides">Peptide Spectrum Matches</a></li>
    <li><a href="#proteins">Protein Groups</a></li>
</ul>

<a id="software"></a>
<h4>Software</h4>
<?php
    foreach ($reader->getAnalysisSoftwareList() as $software) {
        echo $software['name'] . ' ';
        if (isset($software['version'])) {
            echo $software['version'];
        }
        
        echo '<br />';
    }
    ?>

<a id="protocol"></a>
<h4>Protocol</h4>

<?php
    $protocolCollection = $reader->getAnalysisProtocolCollection();
    
    if (isset($protocolCollection['spectrum'])) {
        echo '<h5>Spectrum Protocol</h5>';
        
        foreach ($protocolCollection['spectrum'] as $key => $protocol) {
            echo '<h6>Software</h6>';
            
            echo $protocol['software']['name'] . ' ';
            if (isset($protocol['software']['version'])) {
                echo $protocol['software']['version'];
            }
            
            echo '<br />';
            if (isset($protocol['fragmentTolerance']) || isset($protocol['parentTolerance'])) {
                echo '<h6>Tolerances</h6>';
                
                if (isset($protocol['fragmentTolerance'])) {
                    foreach ($protocol['fragmentTolerance'] as $tolerance) {
                        echo 'Fragment: ' . $tolerance->getTolerance() . ' ' . $tolerance->getUnit() . '<br />';
                    }
                }
                
                if (isset($protocol['parentTolerance'])) {
                    foreach ($protocol['parentTolerance'] as $tolerance) {
                        echo 'Precursor: ' . $tolerance->getTolerance() . ' ' . $tolerance->getUnit() . '<br />';
                    }
                }
            }
            
            if (isset($protocol['enzymes'])) {
                echo '<h6>Enzymes</h6>';
                
                foreach ($protocol['enzymes'] as $enzyme) {
                    if (isset($enzyme['EnzymeName']['name'])) {
                        $name = $enzyme['EnzymeName']['name'];
                    } else {
                        $name = $enzyme['id'];
                    }
                    
                    echo $name . ' (' . $enzyme['missedCleavages'] . ' Missed cleavages)<br />';
                }
            }
            
            if (isset($protocol['modifications'])) {
                echo '<h6>Modifications</h6>';
                
                foreach ($protocol['modifications'] as $modification) {
                    echo '[' . ($modification->isFixed() ? 'F' : 'V') . '] ' . $modification->getName() . ' (' .
                         implode(',', $modification->getResidues());
                    
                    if ($modification->getPosition() != Modification::POSITION_ANY) {
                        echo '@' . $modification->getPosition();
                    }
                    
                    echo ') ' . $modification->getMonoisotopicMass() . ' ' . '<br />';
                }
            }
        }
    }
    if (isset($protocolCollection['protein'])) {
        $protocol = $protocolCollection['protein'];
        echo '<h5>Protein Protocol</h5>';
        echo '<h6>Software</h6>';
        
        echo $protocol['software']['name'] . ' ';
        if (isset($protocol['software']['version'])) {
            echo $protocol['software']['version'];
        }
        echo '<h6>Threshold</h6>';
        
        foreach ($protocol['threshold'] as $threshold) {
            echo $threshold[MzIdentMlReader1r1::CV_ACCESSION] . ': ' . $threshold['name'];<commit_msg>Fixed bad constant reference in mzidentml viewer<commit_after><?php
use pgb_liv\php_ms\Reader\MzIdentMlReaderFactory;
use pgb_liv\php_ms\Reader\MzIdentMlReader1r1;
use pgb_liv\php_ms\Core\Modification;
use pgb_liv\php_ms\Reader\HupoPsi\PsiVerb;

set_time_limit(600);

define('FORM_FILE', 'mzidentml');
?>
<h2>mzIdentML Viewer</h2>
<?php
if (! empty($_FILES) && $_FILES[FORM_FILE]['error'] != 0) {
    die('<p>An error occured. Ensure you included a file to upload.</p>');
}
?>

<form enctype="multipart/form-data" action="?page=mzidentml_viewer"
    method="POST">
    <fieldset>
        <label for="file">mzIdentML File</label> <input
            name="<?php echo FORM_FILE; ?>" type="file" id="file" />
        (.gz or .mzid supported)
    </fieldset>

    <fieldset>
        <input type="submit" value="Send File" />
    </fieldset>
</form>
<?php

if ((! empty($_FILES) && $_FILES[FORM_FILE]['error'] == 0) || isset($_GET['search'])) {
    if (! empty($_FILES)) {
        $name = $_FILES[FORM_FILE]['name'];
        $mzIdentMlFile = $_FILES[FORM_FILE]['tmp_name'];
        
        if (substr_compare($_FILES[FORM_FILE]['name'], '.gz', strlen($_FILES[FORM_FILE]['name']) - 3) === 0) {
            // This input should be from somewhere else, hard-coded in this example
            $file_name = $_FILES[FORM_FILE]['tmp_name'];
            
            // Raising this value may increase performance
            // read 4kb at a time
            $buffer_size = 4096;
            $out_file_name = $file_name . '_decom';
            
            // Open our files (in binary mode)
            $file = gzopen($file_name, 'rb');
            $out_file = fopen($out_file_name, 'wb');
            
            // Keep repeating until the end of the input file
            while (! gzeof($file)) {
                // Read buffer-size bytes
                // Both fwrite and gzread and binary-safe
                fwrite($out_file, gzread($file, $buffer_size));
            }
            
            // Files are done, close files
            fclose($out_file);
            gzclose($file);
            
            $mzIdentMlFile = $out_file_name;
        }
    } else {
        $mzIdentMlFile = sys_get_temp_dir() . '/' . $_GET['search'] . '.mzid';
        $name = $_GET['name'];
    }
    
    echo '<h3>' . $name . '</h3>';
    
    $reader = MzIdentMlReaderFactory::getReader($mzIdentMlFile);
    ?>
<ul style="float: right;">
    <li><a href="#software">Software</a></li>
    <li><a href="#protocol">Protocol</a></li>
    <li><a href="#peptides">Peptide Spectrum Matches</a></li>
    <li><a href="#proteins">Protein Groups</a></li>
</ul>

<a id="software"></a>
<h4>Software</h4>
<?php
    foreach ($reader->getAnalysisSoftwareList() as $software) {
        echo $software['name'] . ' ';
        if (isset($software['version'])) {
            echo $software['version'];
        }
        
        echo '<br />';
    }
    ?>

<a id="protocol"></a>
<h4>Protocol</h4>

<?php
    $protocolCollection = $reader->getAnalysisProtocolCollection();
    
    if (isset($protocolCollection['spectrum'])) {
        echo '<h5>Spectrum Protocol</h5>';
        
        foreach ($protocolCollection['spectrum'] as $key => $protocol) {
            echo '<h6>Software</h6>';
            
            echo $protocol['software']['name'] . ' ';
            if (isset($protocol['software']['version'])) {
                echo $protocol['software']['version'];
            }
            
            echo '<br />';
            if (isset($protocol['fragmentTolerance']) || isset($protocol['parentTolerance'])) {
                echo '<h6>Tolerances</h6>';
                
                if (isset($protocol['fragmentTolerance'])) {
                    foreach ($protocol['fragmentTolerance'] as $tolerance) {
                        echo 'Fragment: ' . $tolerance->getTolerance() . ' ' . $tolerance->getUnit() . '<br />';
                    }
                }
                
                if (isset($protocol['parentTolerance'])) {
                    foreach ($protocol['parentTolerance'] as $tolerance) {
                        echo 'Precursor: ' . $tolerance->getTolerance() . ' ' . $tolerance->getUnit() . '<br />';
                    }
                }
            }
            
            if (isset($protocol['enzymes'])) {
                echo '<h6>Enzymes</h6>';
                
                foreach ($protocol['enzymes'] as $enzyme) {
                    if (isset($enzyme['EnzymeName']['name'])) {
                        $name = $enzyme['EnzymeName']['name'];
                    } else {
                        $name = $enzyme['id'];
                    }
                    
                    echo $name . ' (' . $enzyme['missedCleavages'] . ' Missed cleavages)<br />';
                }
            }
            
            if (isset($protocol['modifications'])) {
                echo '<h6>Modifications</h6>';
                
                foreach ($protocol['modifications'] as $modification) {
                    echo '[' . ($modification->isFixed() ? 'F' : 'V') . '] ' . $modification->getName() . ' (' .
                         implode(',', $modification->getResidues());
                    
                    if ($modification->getPosition() != Modification::POSITION_ANY) {
                        echo '@' . $modification->getPosition();
                    }
                    
                    echo ') ' . $modification->getMonoisotopicMass() . ' ' . '<br />';
                }
            }
        }
    }
    if (isset($protocolCollection['protein'])) {
        $protocol = $protocolCollection['protein'];
        echo '<h5>Protein Protocol</h5>';
        echo '<h6>Software</h6>';
        
        echo $protocol['software']['name'] . ' ';
        if (isset($protocol['software']['version'])) {
            echo $protocol['software']['version'];
        }
        echo '<h6>Threshold</h6>';
        
        foreach ($protocol['threshold'] as $threshold) {
            echo $threshold[PsiVerb::CV_ACCESSION] . ': ' . $threshold['name'];
{'fraction_non_alphanumeric': 0.17015468607825296, 'fraction_numerical': 0.006452146579535115, 'mean_word_length': 1.7634285714285713, 'pattern_counts': {'":': 0, '<': 143, '<?xml version=': 0, '>': 167, '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}}
{'dir': 'git-commits-cleaned', 'id': '7433685', 'n_tokens_mistral': 3651, 'n_tokens_neox': 3420, 'n_words': 623}