0

I have been trying to set up a unit test which essentially tests whether what I read from a file elsewhere is properly parsed. I don't want to read the file in this unit test so I created an array with the information. But whatever I try the whitespace is transformed to '\t'.

let mgfSection = 
[
    "BEGIN IONS",
    "PEPMASS=491.222686767578",
    "CHARGE=2",
    "TITLE=491.222686767578_1494.17_scan=6268_2014090922Mix2alkylISW10noEclu,seq={ATNYNAGDR},sup={4}",
    "SCANS=0",
    "491.2227\u00092",
    "128.1677\t34.3",
    "143.9659   14.8",
];

The above array when printed to the console directly yields '\t' in all locations where I would expect a tab character (5-7). However, it is literally '\t' and not the tab character so that I cannot split on it (mgfSection[6].split("\t") does not work). On the other hand, it would work when being read from a file so I cannot use ("\t") just to make my test work.

What can I do to have the whitespace show up as real whitespace for downstream functions?

Thank you, Jens

BTW, I am developing on AWS Cloud9.

jallmer
  • 589
  • 3
  • 17

2 Answers2

2

Can't you replace it with actual tab char?

let mgfSection = 
    [
        "BEGIN IONS",
        "PEPMASS=491.222686767578",
        "CHARGE=2",
        "TITLE=491.222686767578_1494.17_scan=6268_2014090922Mix2alkylISW10noEclu,seq={ATNYNAGDR},sup={4}",
        "SCANS=0",
        "491.2227\u00092",
        "128.1677\t34.3",
        "143.9659   14.8",
    ].map((d)=>d.replace("\\t","\t"))
ibrahim tanyalcin
  • 5,643
  • 3
  • 16
  • 22
1

You can use regex to split

let mgfSection = 
[
    "BEGIN IONS",
    "PEPMASS=491.222686767578",
    "CHARGE=2",
    "TITLE=491.222686767578_1494.17_scan=6268_2014090922Mix2alkylISW10noEclu,seq={ATNYNAGDR},sup={4}",
    "SCANS=0",
    "491.2227\u00092",
    "128.1677\t34.3",
    "143.9659   14.8",
];

console.log(mgfSection.map(str => str.split(/\s+/)));
Maheer Ali
  • 35,834
  • 5
  • 42
  • 73
  • No that doesn't work. E.g.:'128.1677\t34.3' cannot be split using the regex. Note that \t is two literals and not one white space. – jallmer Feb 18 '19 at 13:33
  • @jallmer but in snippet `'128.1677\t34.3' ` is splitted into `[ "128.1677", "34.3" ]` – Maheer Ali Feb 18 '19 at 13:40