Skip to content

Commit

Permalink
remove pandas dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Debabrata Acharya authored and Debabrata Acharya committed Jul 17, 2020
1 parent 2345700 commit 7eb4ea8
Show file tree
Hide file tree
Showing 7 changed files with 5,942 additions and 26 deletions.
7 changes: 4 additions & 3 deletions csv_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import copy
import os
from typing import List, Union

import file
import model as m
import util as u
from typing import List, Union
import copy
import os


def readcsv(filename: str, separator: str = ',', rstrip: bool = True) -> List[List[str]]:
Expand Down
11 changes: 5 additions & 6 deletions data.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import csv_handler as csv
import model as m
from typing import List, Union, Tuple
import copy
import os
from typing import List
import anndata as ad
import scanpy as sc
import pandas as pd
import csv_handler as csv
import model as m
import util as u
import os


def build_model_from_csv(filename: str, separator: str = ',', rstrip: bool = True) -> m.DataMatrix:
Expand Down Expand Up @@ -48,7 +47,7 @@ def read_as_anndata(list_of_list: List[List[float]], roundoff_decimal: int = 5,
list_of_list = [[u.roundoff(value, roundoff_decimal) for value in row] for row in list_of_list]

u.create_path_if_not_exists(temp_folder)
pd.DataFrame(list_of_list).to_csv(complete_file_path, index=False, index_label=False, header=False)
csv.writecsv(filename, list_of_list, directory=temp_folder)

return sc.read_csv(complete_file_path)

Expand Down
3 changes: 2 additions & 1 deletion datamatrix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
from typing import List, Union, Tuple

from sample import Sample
import copy


class DataMatrix:
Expand Down
19 changes: 9 additions & 10 deletions preprocess.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import copy
import statistics as st
from typing import List, Tuple, Union
import model
import scanpy as sc
import csv_handler as csv
import data
import model
import normalization as nz
import util as u
import statistics as st
import copy
import pandas as pd
import scanpy as sc
import anndata as ad
import csv_handler as csv
import os


def filter_csv_by_sd(filename: str, attr_count: int, separator: str = ',', rstrip: bool = True) -> model.DataMatrix:
Expand Down Expand Up @@ -205,8 +202,10 @@ def filter_singlecells(datamatrix: model.DataMatrix, min_cells: int, min_genes:

datamatrix = filter_genes(datamatrix, min_genes=min_genes, roundoff_decimal=roundoff_decimal, filehash=filehash)

u.clear_temp()

return datamatrix


def fsc(datamatrix: model.DataMatrix, min_cells: int, min_genes: int, rd: int = 5) -> model.DataMatrix:
return filter_singlecells(datamatrix, min_cells, min_genes=min_genes, roundoff_decimal=rd)
def fsc(datamatrix: model.DataMatrix, mc: int, mg: int, rd: int = 5) -> model.DataMatrix:
return filter_singlecells(datamatrix, mc, mg, roundoff_decimal=rd)
3 changes: 2 additions & 1 deletion sample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
from typing import List, Union

from datapoint import DataPoint
import copy


class Sample:
Expand Down
5,899 changes: 5,899 additions & 0 deletions sample_datasets/bmmcaml-5898-1000.csv

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import List, Union
import copy
import model as m
import string
import random
import os
import math
import os
import random
import string
import glob
from typing import List, Union

import model as m


def hash(length=10) -> str:
Expand Down Expand Up @@ -103,3 +105,17 @@ def get_classlabeled_list_of_list_from_datamatrix(datamatrix: m.DataMatrix) -> L

def gclld(datamatrix: m.DataMatrix) -> List[List[Union[float, str]]]:
return get_classlabeled_list_of_list_from_datamatrix(datamatrix)


def clear_temp():

temp_folder: str = '__temp__'

if not is_valid_path(temp_folder):
return

filelist = glob.glob(os.path.join(temp_folder, '*'))

for f in filelist:
if is_valid_path(os.path.join(f)):
os.remove(f)

0 comments on commit 7eb4ea8

Please sign in to comment.