Beispiel #1
0
        public static async Task <List <GffFeature> > FromFile(string path)
        {
            using (var reader = new StreamReader(path))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    csv.Configuration.Delimiter = "\t";
                    var records = new List <GffFeature>();
                    while (await csv.ReadAsync())
                    {
                        var sequence = csv.GetField(0);
                        if (sequence.StartsWith("#"))
                        {
                            continue;
                        }
                        var hasAttributes = csv.TryGetField(8, out string attributesFied);
                        var attributes    = new Dictionary <string, string>();
                        if (hasAttributes)
                        {
                            attributes = AttributesParser.Parse(attributesFied, AttributesParser.GffAttributeRegex);
                        }

                        var additionnalFieldValues = new List <string>();
                        var additionnalFieldIndex  = 9;
                        while (csv.TryGetField(additionnalFieldIndex, out string value))
                        {
                            additionnalFieldValues.Add(value);
                        }

                        records.Add(new GffFeature()
                        {
                            Sequence = sequence,
                            Source   = csv.GetField(1),
                            Feature  = csv.GetField(2),
                            Start    = Int32.Parse(csv.GetField(3)),
                            End      = Int32.Parse(csv.GetField(4)),
                            Score    = csv.GetField(5) switch
                            {
                                "." => null,
                                { } s => Int32.Parse(s)
                            },
Beispiel #2
0
        public static async Task <List <Snp> > FromCsv(string path)
        {
            using (var reader = new StreamReader(path))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    csv.Configuration.Delimiter = "\t";
                    var records = new List <Snp>();
                    while (await csv.ReadAsync())
                    {
                        var record        = SpdiParser.Parse(csv.GetField(0));
                        var hasAttributes = csv.TryGetField(1, out string attributesFied);
                        if (hasAttributes)
                        {
                            var attributes = AttributesParser.Parse(attributesFied);
                            record.Attributes = attributes;
                        }
                        records.Add(record);
                    }

                    return(records);
                }
        }