@@ -2,6 +2,7 @@ package poly
22
33import (
44 "bytes"
5+ "compress/gzip"
56 "encoding/json"
67 "io/ioutil"
78 "log"
@@ -325,13 +326,9 @@ func BuildGff(sequence Sequence) []byte {
325326
326327// ReadGff takes in a filepath for a .gffv3 file and parses it into an Annotated Sequence struct.
327328func ReadGff (path string ) Sequence {
328- file , err := ioutil .ReadFile (path )
329+ file , _ := ioutil .ReadFile (path )
329330 var sequence Sequence
330- if err != nil {
331- // return 0, fmt.Errorf("Failed to open file %s for unpack: %s", gzFilePath, err)
332- } else {
333- sequence = ParseGff (file )
334- }
331+ sequence = ParseGff (file )
335332 return sequence
336333}
337334
@@ -368,10 +365,7 @@ func ParseJSON(file []byte) Sequence {
368365
369366// ReadJSON reads an Sequence JSON file.
370367func ReadJSON (path string ) Sequence {
371- file , err := ioutil .ReadFile (path )
372- if err != nil {
373- // return 0, fmt.Errorf("Failed to open file %s for unpack: %s", gzFilePath, err)
374- }
368+ file , _ := ioutil .ReadFile (path )
375369 sequence := ParseJSON (file )
376370 return sequence
377371}
@@ -499,10 +493,7 @@ func BuildFASTA(sequence Sequence) []byte {
499493
500494// ReadFASTA reads a Sequence struct from a FASTA file.
501495func ReadFASTA (path string ) Sequence {
502- file , err := ioutil .ReadFile (path )
503- if err != nil {
504- // return 0, fmt.Errorf("Failed to open file %s for unpack: %s", gzFilePath, err)
505- }
496+ file , _ := ioutil .ReadFile (path )
506497 sequence := ParseFASTA (file )
507498 return sequence
508499}
@@ -715,14 +706,9 @@ func BuildGbk(sequence Sequence) []byte {
715706
716707// ReadGbk reads a Gbk from path and parses into an Annotated sequence struct.
717708func ReadGbk (path string ) Sequence {
718- file , err := ioutil .ReadFile (path )
709+ file , _ := ioutil .ReadFile (path )
719710 var sequence Sequence
720- if err != nil {
721- // return 0, fmt.Errorf("Failed to open file %s for unpack: %s", gzFilePath, err)
722- } else {
723- sequence = ParseGbk (file )
724-
725- }
711+ sequence = ParseGbk (file )
726712 return sequence
727713}
728714
@@ -1451,24 +1437,28 @@ func ParseGbkFlat(file []byte) []Sequence {
14511437
14521438// ReadGbkMulti reads multiple genbank files from a single file
14531439func ReadGbkMulti (path string ) []Sequence {
1454- file , err := ioutil .ReadFile (path )
1455- if err != nil {
1456- // return 0, fmt.Errorf("Failed to open file %s for unpack: %s", gzFilePath, err)
1457- }
1440+ file , _ := ioutil .ReadFile (path )
14581441 sequences := ParseGbkMulti (file )
14591442 return sequences
14601443}
14611444
1462- // ReadGbkFlat reads flat genbank files, like the ones provided by the NCBI FTP server
1445+ // ReadGbkFlat reads flat genbank files, like the ones provided by the NCBI FTP server (after decompression)
14631446func ReadGbkFlat (path string ) []Sequence {
1464- file , err := ioutil .ReadFile (path )
1465- if err != nil {
1466- // return 0, fmt.Errorf("Failed to open file %s for unpack: %s", gzFilePath, err)
1467- }
1447+ file , _ := ioutil .ReadFile (path )
14681448 sequences := ParseGbkFlat (file )
14691449 return sequences
14701450}
14711451
1452+ // ReadGbkFlatGz reads flat gzip'd genbank files, like the ones provided by the NCBI FTP server
1453+ func ReadGbkFlatGz (path string ) []Sequence {
1454+ file , _ := ioutil .ReadFile (path )
1455+ rdata := bytes .NewReader (file )
1456+ r , _ := gzip .NewReader (rdata )
1457+ s , _ := ioutil .ReadAll (r )
1458+ sequences := ParseGbkFlat (s )
1459+ return sequences
1460+ }
1461+
14721462/******************************************************************************
14731463
14741464Genbank Flat specific IO related things end here.
0 commit comments