Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read raw files indenpendent of the file extension #11

Open
bernt-matthias opened this issue Apr 12, 2024 · 1 comment
Open

Read raw files indenpendent of the file extension #11

bernt-matthias opened this issue Apr 12, 2024 · 1 comment

Comments

@bernt-matthias
Copy link

It seems that raw files can not be processed if they have a different file extension, e.g. compomics/ThermoRawFileParser#180.

Since there are use cases that could benefit from this we are wondering if it is possible to read raw files even if they have a different extension.

@caetera
Copy link

caetera commented Apr 15, 2024

I will add a minimal working example.
small.raw and small.data are the same binary file, however, the latter cannot be opened by RawFileReaderFactory

using System.Security.Cryptography;
using ThermoFisher.CommonCore.Data;
using ThermoFisher.CommonCore.Data.Business;

namespace TestApp
{
    class TestApp
    {
        static void Main()
        {
            TryOpen("small.raw");
            TryOpen("small.data");
        }

        static void TryOpen(string path)
        {
            Console.WriteLine($"Working on {path}");
            using (var md5 = MD5.Create())
            {
                using var stream = File.OpenRead(path);
                var hash = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "");
                Console.WriteLine($"MD5: {hash}");
            }

            using var rawFile = RawFileReaderFactory.ReadFile(path);
            if (rawFile.IsOpen)
            {
                rawFile.SelectMsData();
                Console.WriteLine($"Opened, {rawFile.RunHeaderEx.SpectraCount} spectra in the file");
            }
            else
            {
                Console.WriteLine("Cannot be openned");
            }
        }
    }
}

Output:

Working on small.raw
MD5: 1B12C93735A9EAECD072031B2184D2ED
Opened, 48 spectra in the file
Working on small.data
MD5: 1B12C93735A9EAECD072031B2184D2ED
Cannot be openned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants