File tree Expand file tree Collapse file tree 3 files changed +43
-11
lines changed
Expand file tree Collapse file tree 3 files changed +43
-11
lines changed Original file line number Diff line number Diff line change 11import flatgfa
22
3- graph = flatgfa .parse ("your-gfa -file" )
4- gaf = "your-gaf-gile "
5- gaf_parser = graph .load_gaf (gaf )
6- for read in gaf_parser :
7- print (read .name )
8- print (read .sequence ())
9- print (read .segment_ranges ())
10- for element in read . chunks :
3+ graph = flatgfa .parse ("name-of-GFA -file" )
4+ gaf = "name-of-GAF-file "
5+ gaf_parser = graph .all_reads (gaf )
6+ for lines in gaf_parser :
7+ print (lines .name )
8+ print (lines .sequence ())
9+ print (lines .segment_ranges ())
10+ for element in lines :
1111 print (element .handle )
1212 print (element .range )
13+
14+
Original file line number Diff line number Diff line change @@ -65,13 +65,14 @@ class LinkList:
6565class ChunkEvent :
6666 handle : Handle
6767 range : tuple [int , int ]
68- def __sequence__ (self ) -> None : ...
68+ def sequence (self ) -> str : ...
6969
7070class GAFLine :
7171 name : str
7272 chunks : list [ChunkEvent ]
7373 def segment_ranges (self ) -> str : ...
7474 def sequence (self ) -> str : ...
75+ def __iter__ (self ) -> Iterator [ChunkEvent ]: ...
7576
7677class GAFParser :
7778 def __iter__ (self ) -> Iterator [GAFLine ]: ...
@@ -84,7 +85,7 @@ class FlatGFA:
8485 def write_flatgfa (self , filename : str ) -> None : ...
8586 def write_gfa (self , filename : str ) -> None : ...
8687 def depth (self ) -> None : ...
87- def load_gaf (self , gaf : str ) -> GAFParser : ...
88+ def all_reads (self , gaf : str ) -> GAFParser : ...
8889
8990def parse (filename : str ) -> FlatGFA : ...
9091def load (filename : str ) -> FlatGFA : ...
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ impl PyFlatGFA {
131131 mmap. flush ( ) ?;
132132 Ok ( ( ) )
133133 }
134- fn load_gaf ( & self , gaf : & str ) -> PyGAFParser {
134+ fn all_reads ( & self , gaf : & str ) -> PyGAFParser {
135135 let gfa = self . 0 . view ( ) ;
136136 let name_map = flatgfa:: namemap:: NameMap :: build ( & gfa) ;
137137 let gaf_buf = Arc :: new ( flatgfa:: memfile:: map_file ( gaf) ) ;
@@ -497,6 +497,29 @@ impl PyChunkEvent {
497497 }
498498}
499499
500+ #[ pyclass]
501+ struct PyGAFLineIter {
502+ chunks : Vec < PyChunkEvent > ,
503+ index : usize ,
504+ }
505+
506+ #[ pymethods]
507+ impl PyGAFLineIter {
508+ fn __iter__ ( slf : PyRef < Self > ) -> PyRef < Self > {
509+ slf
510+ }
511+
512+ fn __next__ ( mut slf : PyRefMut < Self > ) -> Option < PyChunkEvent > {
513+ if slf. index < slf. chunks . len ( ) {
514+ let item = slf. chunks [ slf. index ] . clone ( ) ;
515+ slf. index += 1 ;
516+ Some ( item)
517+ } else {
518+ None
519+ }
520+ }
521+ }
522+
500523#[ pyclass]
501524#[ pyo3( name = "GAFLine" , module = "flatgfa" ) ]
502525
@@ -532,6 +555,12 @@ impl PyGAFLine {
532555 }
533556 res
534557 }
558+ fn __iter__ ( slf : PyRef < Self > ) -> PyGAFLineIter {
559+ PyGAFLineIter {
560+ chunks : slf. chunks . clone ( ) ,
561+ index : 0 ,
562+ }
563+ }
535564}
536565struct OwnedGAFParser {
537566 mmap : Arc < Mmap > ,
You can’t perform that action at this time.
0 commit comments