Skip to content

Commit d2551b2

Browse files
committed
Symlink support for "xic" and "query"
1 parent 5c468bf commit d2551b2

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

Query/ProxiSpectrumReader.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4+
using System.IO;
45
using System.Reflection;
6+
using System.Runtime.InteropServices;
57
using log4net;
68
using ThermoFisher.CommonCore.Data.Business;
79
using ThermoFisher.CommonCore.Data.FilterEnums;
810
using ThermoFisher.CommonCore.Data.Interfaces;
911
using ThermoRawFileParser.Writer;
12+
using ThermoRawFileParser.Util;
1013

1114
namespace ThermoRawFileParser.Query
1215
{
@@ -26,9 +29,28 @@ public List<ProxiSpectrum> Retrieve()
2629
{
2730
var resultList = new List<ProxiSpectrum>();
2831
IRawDataPlus rawFile;
32+
33+
//checking for symlinks
34+
var fileInfo = new FileInfo(queryParameters.rawFilePath);
35+
if (fileInfo.Attributes.HasFlag(FileAttributes.ReparsePoint)) //detected path is a symlink
36+
{
37+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
38+
{
39+
var realPath = NativeMethods.GetFinalPathName(queryParameters.rawFilePath);
40+
Log.DebugFormat("Detected reparse point, real path: {0}", realPath);
41+
queryParameters.UpdateRealPath(realPath);
42+
}
43+
else //Mono should handle all non-windows platforms
44+
{
45+
var realPath = Path.Combine(Path.GetDirectoryName(queryParameters.rawFilePath), Mono.Unix.UnixPath.ReadLink(queryParameters.rawFilePath));
46+
Log.DebugFormat("Detected reparse point, real path: {0}", realPath);
47+
queryParameters.UpdateRealPath(realPath);
48+
}
49+
}
50+
2951
using (rawFile = RawFileReaderFactory.ReadFile(queryParameters.rawFilePath))
3052
{
31-
Log.Info($"Started parsing {queryParameters.rawFilePath}");
53+
Log.Info($"Started parsing {queryParameters.userFilePath}");
3254

3355
if (!rawFile.IsOpen)
3456
{
@@ -240,7 +262,7 @@ public List<ProxiSpectrum> Retrieve()
240262
}
241263
}
242264

243-
Log.Info($"Finished processing {queryParameters.rawFilePath}");
265+
Log.Info($"Finished processing {queryParameters.userFilePath}");
244266

245267
return resultList;
246268
}

Query/QueryExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void Run(QueryParameters parameters)
3434
// otherwise put output files into the same directory as the raw file input
3535
else
3636
{
37-
outputFileName = Path.GetFullPath(parameters.rawFilePath);
37+
outputFileName = Path.GetFullPath(parameters.userFilePath);
3838
}
3939

4040
var directory = Path.GetDirectoryName(outputFileName);

Query/QueryParameters.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections;
21
using System.Collections.Generic;
3-
using System.Configuration;
42

53
namespace ThermoRawFileParser.Query
64
{
@@ -10,8 +8,23 @@ public class QueryParameters
108

119
private int _warnings;
1210

11+
private string _rawFilePath;
12+
13+
private string _userFilePath;
14+
1315
public bool help { get; set; }
14-
public string rawFilePath { get; set; }
16+
public string rawFilePath
17+
{
18+
get => _rawFilePath;
19+
set
20+
{
21+
_rawFilePath = value;
22+
_userFilePath = value;
23+
}
24+
}
25+
26+
public string userFilePath { get => _userFilePath; }
27+
1528
public string scans { get; set; }
1629
public string outputFile { get; set; }
1730
public bool noPeakPicking { get; set; }
@@ -62,5 +75,10 @@ public void NewWarn()
6275
{
6376
_warnings++;
6477
}
78+
79+
public void UpdateRealPath(string realPath)
80+
{
81+
_rawFilePath = realPath;
82+
}
6583
}
6684
}

XIC/XicReader.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Reflection;
5+
using System.Runtime.InteropServices;
56
using log4net;
67
using ThermoFisher.CommonCore.Data;
78
using ThermoFisher.CommonCore.Data.Business;
89
using ThermoFisher.CommonCore.Data.Interfaces;
10+
using ThermoRawFileParser.Util;
911

1012
namespace ThermoRawFileParser.XIC
1113
{
@@ -20,10 +22,29 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData, ref
2022
{
2123
IRawDataPlus rawFile;
2224
int _xicCount = 0;
25+
string _userProvidedPath = rawFilePath;
26+
27+
//checking for symlinks
28+
var fileInfo = new FileInfo(rawFilePath);
29+
if (fileInfo.Attributes.HasFlag(FileAttributes.ReparsePoint)) //detected path is a symlink
30+
{
31+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
32+
{
33+
var realPath = NativeMethods.GetFinalPathName(rawFilePath);
34+
Log.DebugFormat("Detected reparse point, real path: {0}", realPath);
35+
rawFilePath = realPath;
36+
}
37+
else //Mono should handle all non-windows platforms
38+
{
39+
var realPath = Path.Combine(Path.GetDirectoryName(rawFilePath), Mono.Unix.UnixPath.ReadLink(rawFilePath));
40+
Log.DebugFormat("Detected reparse point, real path: {0}", realPath);
41+
rawFilePath = realPath;
42+
}
43+
}
2344

2445
using (rawFile = RawFileReaderFactory.ReadFile(rawFilePath))
2546
{
26-
Log.Info($"Started parsing {rawFilePath}");
47+
Log.Info($"Started parsing {_userProvidedPath}");
2748

2849
if (!rawFile.IsOpen)
2950
{
@@ -136,14 +157,16 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData, ref
136157
Math.Abs(data.PositionsArray[0][0] - endTime) < 0.001))
137158
{
138159
Log.Warn(
139-
$"Only the minimum or maximum retention time was returned. Does the provided retention time range [{xicUnit.Meta.RtStart}-{xicUnit.Meta.RtEnd}] lies outside the max. window [{startTime}-{endTime}]?");
160+
$"Only the minimum or maximum retention time was returned. " +
161+
$"Does the provided retention time range [{xicUnit.Meta.RtStart}-{xicUnit.Meta.RtEnd}] lies outside the max. window [{startTime}-{endTime}]?");
140162
parameters.NewWarn();
141163
}
142164
}
143165
else
144166
{
145167
Log.Warn(
146-
$"No scans found in retention time range [{xicUnit.Meta.RtStart}-{xicUnit.Meta.RtEnd}]. Does the provided retention time window lies outside the max. window [{startTime}-{endTime}]");
168+
$"No scans found in retention time range [{xicUnit.Meta.RtStart}-{xicUnit.Meta.RtEnd}]. " +
169+
$"Does the provided retention time window lies outside the max. window [{startTime}-{endTime}]");
147170
parameters.NewWarn();
148171
}
149172
}
@@ -193,7 +216,7 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData, ref
193216
Console.Out.Write("\r");
194217
}
195218

196-
Log.Info($"Finished parsing {rawFilePath}");
219+
Log.Info($"Finished parsing {_userProvidedPath}");
197220
}
198221
}
199222

0 commit comments

Comments
 (0)