1

I have text file consisting repeating strings elements like this

@SRR1582908.1 ILLUMINA_0154:8:1101:3556:1998/1        //1 line
CCTCGCTGGTCGATTTGTTTAACCGTTTTCTGTTCAGCGCCAAAATTATTTT  //2 line
+                                                     //3 line
BCCFFFFFHHHHHIIIIIHIHGHHGGIIIIIGHHDBGHHHIIGHIIGIHIII  //4 line

and 29 millions of such elements in the file. What I need is to extract second line from each element into new array of strings

I have a function which is doing following:

do
{
    let textToOpen = try String(contentsOf: chosenFile!, encoding: .utf8)
    var arrayOfTextLines = textToOpen.components(separatedBy: "\n")

    arrayOfReads = stride(from: 1, to: arrayOfTextLines.endIndex, by: 4).map{(arrayOfTextLines[$0])}
}
catch
{}

The code is working correctly but for the file with 29 millions elements is relatively slow.

The main drawback is

var arrayOfTextLines = textToOpen.components(separatedBy: "\n")

Is there a way to speed-up the function ?

VYT
  • 1,071
  • 19
  • 35

0 Answers0