Skip to content

Commit

Permalink
Add json argument and note about time.sleep()
Browse files Browse the repository at this point in the history
  • Loading branch information
choang committed Jun 27, 2023
1 parent 94687e3 commit 4c47aec
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions gget/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,7 @@ def main():

# elm parser arguments
parser_elm.add_argument(
"-seq"
"--sequence",
"sequence",
type=str,
default=None,
help="Amino acid sequence or Uniprot ID",
Expand All @@ -1451,6 +1450,26 @@ def main():
help="Search using Uniprot ID",
)

parser_elm.add_argument(
"-csv",
"--csv",
default=True,
action="store_false",
required=False,
help="Returns results in csv format instead of json.",
)

parser_elm.add_argument(
"-o",
"--out",
type=str,
required=False,
help=(
"Path to the csv file the results will be saved in, e.g. path/to/directory/results.csv.\n"
"Default: Standard out."
),
)

### Define return values
args = parent_parser.parse_args()

Expand Down Expand Up @@ -1507,9 +1526,39 @@ def main():

## elm return
if args.command == "elm":
if not args.sequence:
parser_elm.error("the following arguments are required: sequence")
elm(sequence=args.sequence, uniprot=args.uniprot)
elm(sequence=args.sequence, uniprot=args.uniprot, json=args.csv,)

# Run gget elm function
elm_results = elm(
sequence=args.sequence,
json=args.csv,
)

# Check if the function returned something
if not isinstance(blat_results, type(None)):
# Save elm results if args.out specified
if args.out and not args.csv:
# Create saving directory
directory = "/".join(args.out.split("/")[:-1])
if directory != "":
os.makedirs(directory, exist_ok=True)
# Save to csv
elm_results.to_csv(args.out, index=False)

if args.out and args.csv:
# Create saving directory
directory = "/".join(args.out.split("/")[:-1])
if directory != "":
os.makedirs(directory, exist_ok=True)
# Save json
with open(args.out, "w", encoding="utf-8") as f:
json.dump(elm_results, f, ensure_ascii=False, indent=4)

# Print results if no directory specified
if not args.out and not args.csv:
elm_results.to_csv(sys.stdout, index=False)
if not args.out and args.csv:
print(json.dumps(blat_results, ensure_ascii=False, indent=4))

## cellxgene return
if args.command == "cellxgene":
Expand Down

0 comments on commit 4c47aec

Please sign in to comment.